Skip to content

Commit

Permalink
MailMover: escape mail folder name with double quotes
Browse files Browse the repository at this point in the history
shlex.quote quoted with single quotes, which is not supported by
notmuch, so we have to quote and escape on our own

followup of afewmail#218 (comment)
  • Loading branch information
flokli committed Jan 28, 2019
1 parent 7100674 commit d088210
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions afew/MailMover.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import notmuch
import logging
import os, shutil
import shlex
from subprocess import check_call, CalledProcessError

from .Database import Database
Expand All @@ -23,7 +22,7 @@ class MailMover(Database):
def __init__(self, max_age=0, rename = False, dry_run=False):
super(MailMover, self).__init__()
self.db = notmuch.Database(self.db_path)
self.query = 'folder:{folder} AND {subquery}'
self.query = 'folder:"{folder}" AND {subquery}'
if max_age:
days = timedelta(int(max_age))
start = date.today() - days
Expand Down Expand Up @@ -55,7 +54,7 @@ def move(self, maildir, rules):
for query in rules.keys():
destination = '{}/{}/cur/'.format(self.db_path, rules[query])
main_query = self.query.format(
folder=shlex.quote(maildir), subquery=query)
folder=maildir.replace("\"", "\\\""), subquery=query)
logging.debug("query: {}".format(main_query))
messages = notmuch.Query(self.db, main_query).search_messages()
for message in messages:
Expand Down

0 comments on commit d088210

Please sign in to comment.