<DKIM> maxage causes loss of local email
Nicolas Sebrecht
nicolas.s-dev at laposte.net
Fri Mar 6 09:52:19 GMT 2015
On Fri, Mar 06, 2015 at 02:52:28AM -0500, Janna Martl wrote:
> Oops, corrected:
>
> On Thu, Mar 05, 2015 at 10:30:23PM -0500, Janna Martl wrote:
> >--- /usr/lib/python2.7/site-packages/offlineimap/folder/Maildir.py 2015-03-05 22:13:10.390450915 -0500
> >+++ Maildir.py 2015-03-05 22:13:53.882540931 -0500
> >@@ -22,6 +22,7 @@
> > import tempfile
> > from .Base import BaseFolder
> > from threading import Lock
> >+from offlineimap import emailutil
> >
> > try:
> > from hashlib import md5
> >@@ -235,16 +236,25 @@
> > filepath = os.path.join(self.getfullname(), filename)
> > return os.path.getmtime(filepath)
> >
> >- def new_message_filename(self, uid, flags=set()):
> >+ def new_message_filename(self, uid, flags=set(), rtime=None):
> > """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)))
> >+ if rtime is None:
> >+ timeval, timeseq = _gettimeseq()
> >+ else:
> >+ timeval, timeseq = rtime, 0
I think it should explain why rtime is a better choice than
_gettimeseq().
> >+ filename = '%d_%d.%d.%s,U=%d,FMD5=%s%s2,%s' % \
> >+ (timeval, timeseq, os.getpid(), socket.gethostname(),
> >+ uid, self._foldermd5, self.infosep, ''.join(sorted(flags)))
> >+ while os.path.exists(os.path.join(self.getfullname(), "cur", filename)) or os.path.exists(os.path.join(self.getfullname(), "new", filename)):
> >+ timeseq += 1
> >+ filename = '%d_%d.%d.%s,U=%d,FMD5=%s%s2,%s' % \
> >+ (timeval, timeseq, os.getpid(), socket.gethostname(),
> >+ uid, self._foldermd5, self.infosep, ''.join(sorted(flags)))
> >+ return filename
Recursive approach avoid some code duplication and avoid multiple calls.
Function should be local within the new_message_filename() method, on
top of its statements.
def build_filename(..., timeseq, ...):
"""Compute a new filename with 'time sequence' uniquiness in mind."""
filename = ...
for imap_dir in ['cur', 'new', 'tmp']:
if os.path.exists(...):
# Increase timeseq.
return newfilename(..., timeseq + 1, ...)
return filename
return build_filename(..., timeseq, ...)
> >
> >
> > def save_to_tmp_file(self, filename, content):
> >@@ -314,7 +324,9 @@
> > # Otherwise, save the message in tmp/ and then call savemessageflags()
> > # to give it a permanent home.
> > tmpdir = os.path.join(self.getfullname(), 'tmp')
> >- messagename = self.new_message_filename(uid, flags)
> >+ if rtime is None:
> >+ rtime = emailutil.get_message_date(content)
Should explain why relying on get_message_date() is better.
> >+ messagename = self.new_message_filename(uid, flags, rtime=rtime)
> > tmpname = self.save_to_tmp_file(messagename, content)
> > if rtime != None:
> > os.utime(os.path.join(self.getfullname(), tmpname), (rtime, rtime))
> >@@ -382,8 +394,10 @@
> > oldfilename = self.messagelist[uid]['filename']
> > dir_prefix, filename = os.path.split(oldfilename)
> > flags = self.getmessageflags(uid)
> >+ content = self.getmessage(uid)
> >+ rtime = emailutil.get_message_date(content)
> > newfilename = os.path.join(dir_prefix,
> >- self.new_message_filename(new_uid, flags))
> >+ self.new_message_filename(new_uid, flags, rtime=rtime))
> > os.rename(os.path.join(self.getfullname(), oldfilename),
> > os.path.join(self.getfullname(), newfilename))
> > self.messagelist[new_uid] = self.messagelist[uid]
>
--
Nicolas Sebrecht
More information about the OfflineIMAP-project
mailing list