[PATCH 1/3] Simplify constructing the SEARCH date

Sebastian Spaeth Sebastian at SSpaeth.de
Wed Sep 7 16:21:44 UTC 2011


We can use Imaplib's monthnames and shorten the construction of the date
by using them rather than hardcoding them again.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/IMAP.py |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 5a14776..cee9aa0 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -24,6 +24,7 @@ import time
 from sys import exc_info
 from Base import BaseFolder
 from offlineimap import imaputil, imaplibutil, OfflineImapError
+from offlineimap.imaplib2 import MonthNames
 try: # python 2.6 has set() built in
     set
 except NameError:
@@ -130,16 +131,10 @@ class IMAPFolder(BaseFolder):
                 if(maxage != -1):
                     #find out what the oldest message is that we should look at
                     oldest_struct = time.gmtime(time.time() - (60*60*24*maxage))
-
-                    #format months manually - otherwise locales cause problems
-                    monthnames = ["Jan", "Feb", "Mar", "Apr", "May", \
-                        "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
-
-                    month = monthnames[oldest_struct[1]-1]
-                    daystr = "%(day)02d" % {'day' : oldest_struct[2]}
-
-                    search_cond += "SINCE %s-%s-%s" % (daystr, month,
-                                                       oldest_struct[0])
+                    search_cond += "SINCE %02d-%s-%d" % (
+                        oldest_struct[2],
+                        MonthNames[oldest_struct[1]],
+                        oldest_struct[0])
 
                 if(maxsize != -1):
                     if(maxage != -1): # There are two conditions, add space
-- 
1.7.4.1




More information about the OfflineIMAP-project mailing list