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 <Sebastian@SSpaeth.de>
This commit is contained in:
parent
6fe808338c
commit
09ce56c594
@ -221,6 +221,17 @@ class MaildirFolder(BaseFolder):
|
|||||||
filepath = os.path.join(self.getfullname(), filename)
|
filepath = os.path.join(self.getfullname(), filename)
|
||||||
return os.path.getmtime(filepath)
|
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):
|
def savemessage(self, uid, content, flags, rtime):
|
||||||
# This function only ever saves to tmp/,
|
# This function only ever saves to tmp/,
|
||||||
# but it calls savemessageflags() to actually save to cur/ or new/.
|
# 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()
|
# Otherwise, save the message in tmp/ and then call savemessageflags()
|
||||||
# to give it a permanent home.
|
# to give it a permanent home.
|
||||||
tmpdir = os.path.join(self.getfullname(), 'tmp')
|
tmpdir = os.path.join(self.getfullname(), 'tmp')
|
||||||
timeval, timeseq = gettimeseq()
|
messagename = self.new_message_filename(uid, flags)
|
||||||
messagename = '%d_%d.%d.%s,U=%d,FMD5=%s' % \
|
|
||||||
(timeval,
|
|
||||||
timeseq,
|
|
||||||
os.getpid(),
|
|
||||||
socket.gethostname(),
|
|
||||||
uid,
|
|
||||||
md5(self.getvisiblename()).hexdigest())
|
|
||||||
# open file and write it out
|
# open file and write it out
|
||||||
try:
|
try:
|
||||||
fd = os.open(os.path.join(tmpdir, messagename),
|
fd = os.open(os.path.join(tmpdir, messagename),
|
||||||
|
Loading…
Reference in New Issue
Block a user