Skip to content

Commit

Permalink
MailMover: preserve maildir subdir
Browse files Browse the repository at this point in the history
Currently, MailMover moves all mail to `/cur`. But everyone moving mail
from `/new` to `/cur` is required to set up the maildir flags field in
the name.

Rather than setting up that field, preserve the maildir subdir part and
let other clients change subdirs as necessary. After all, "moving" does
not constitute "reading".
  • Loading branch information
mjg committed Jun 14, 2018
1 parent 01bee4f commit 46dce1f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions afew/MailMover.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, max_age=0, rename = False, dry_run=False):

def get_new_name(self, fname, destination):
basename = os.path.basename(fname)
submaildir = os.path.split(os.path.split(fname)[0])[1]
if self.rename:
parts = basename.split(':')
if len(parts) > 1:
Expand All @@ -43,7 +44,7 @@ def get_new_name(self, fname, destination):
# construct a new filename, composed of a made-up ID and the flags part
# of the original filename.
basename = str(uuid.uuid1()) + flagpart
return os.path.join(destination, basename)
return os.path.join(destination, submaildir, basename)

def move(self, maildir, rules):
'''
Expand All @@ -54,7 +55,7 @@ def move(self, maildir, rules):
to_delete_fnames = []
moved = False
for query in rules.keys():
destination = '{}/{}/cur/'.format(self.db_path, rules[query])
destination = '{}/{}/'.format(self.db_path, rules[query])
main_query = self.query.format(folder=maildir, subquery=query)
logging.debug("query: {}".format(main_query))
messages = notmuch.Query(self.db, main_query).search_messages()
Expand Down

0 comments on commit 46dce1f

Please sign in to comment.