Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail mover fix renames #201

Merged
merged 3 commits into from
Sep 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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