Skip to content

Commit

Permalink
Merge pull request #201 from mjg/MailMover-fix-renames
Browse files Browse the repository at this point in the history
Mail mover fix renames
  • Loading branch information
GuillaumeSeren committed Sep 18, 2019
2 parents 316033f + d96c0ac commit ea6221d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions afew/MailMover.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ def __init__(self, max_age=0, rename = False, dry_run=False):
self.rename = rename

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:
return os.path.join(
destination,
parts = basename.split(':')
if len(parts) > 1:
flagpart = ':' + parts[-1]
else:
flagpart = ''
# construct a new filename, composed of a made-up ID and the flags part
# of the original filename.
str(uuid.uuid1()) + ':' + os.path.basename(fname).split(':')[-1]
)
else:
return destination
basename = str(uuid.uuid1()) + flagpart
return os.path.join(destination, submaildir, basename)

def move(self, maildir, rules):
'''
Expand All @@ -52,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.replace("\"", "\\\""), subquery=query)
logging.debug("query: {}".format(main_query))
Expand Down

0 comments on commit ea6221d

Please sign in to comment.