From 09ce56c5942db78193f1e44343759afb2d2d8396 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 30 Aug 2011 10:51:33 +0200 Subject: [PATCH] Factor out creating a Maildir message filename Various functions (such as change_message_uid) will want to construct maildir filenames, so factor out the code into a helper. Signed-off-by: Sebastian Spaeth --- offlineimap/folder/Maildir.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index dc2e368..5b2de91 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -221,6 +221,17 @@ class MaildirFolder(BaseFolder): filepath = os.path.join(self.getfullname(), filename) return os.path.getmtime(filepath) + def new_message_filename(self, uid, flags=set()): + """Creates a new unique Maildir filename + + :param uid: The UID`None`, or a set of maildir flags + :param flags: A set of maildir flags + :returns: String containing unique message filename""" + timeval, timeseq = gettimeseq() + return '%d_%d.%d.%s,U=%d,FMD5=%s%s2,%s' % \ + (timeval, timeseq, os.getpid(), socket.gethostname(), + uid, self._foldermd5, self.infosep, ''.join(sorted(flags))) + def savemessage(self, uid, content, flags, rtime): # This function only ever saves to tmp/, # but it calls savemessageflags() to actually save to cur/ or new/. @@ -237,14 +248,7 @@ class MaildirFolder(BaseFolder): # Otherwise, save the message in tmp/ and then call savemessageflags() # to give it a permanent home. tmpdir = os.path.join(self.getfullname(), 'tmp') - timeval, timeseq = gettimeseq() - messagename = '%d_%d.%d.%s,U=%d,FMD5=%s' % \ - (timeval, - timeseq, - os.getpid(), - socket.gethostname(), - uid, - md5(self.getvisiblename()).hexdigest()) + messagename = self.new_message_filename(uid, flags) # open file and write it out try: fd = os.open(os.path.join(tmpdir, messagename),