From e05fe15470dd26d0f01c694c7232e37f3838254a Mon Sep 17 00:00:00 2001 From: spametki Date: Sun, 6 Oct 2013 12:09:44 -0300 Subject: [PATCH 1/2] IMAP .insert support for custom date (Google Code issue 1707) --- applications/admin/languages/es.py | 3 +++ gluon/dal.py | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/applications/admin/languages/es.py b/applications/admin/languages/es.py index 1c939933..85356785 100644 --- a/applications/admin/languages/es.py +++ b/applications/admin/languages/es.py @@ -10,6 +10,7 @@ '(requires internet access, experimental)': '(requires internet access, experimental)', '(something like "it-it")': '(algo como "it-it")', '@markmin\x01(file **gluon/contrib/plural_rules/%s.py** is not found)': '(file **gluon/contrib/plural_rules/%s.py** is not found)', +'@markmin\x01An error occured, please [[reload %s]] the page': 'An error occured, please [[reload %s]] the page', '@markmin\x01Searching: **%s** %%{file}': 'Searching: **%s** files', 'A new version of web2py is available': 'Hay una nueva versión de web2py disponible', 'A new version of web2py is available: %s': 'Hay una nueva versión de web2py disponible: %s', @@ -31,6 +32,7 @@ 'appadmin': 'appadmin', 'appadmin is disabled because insecure channel': 'admin deshabilitado, el canal no es seguro', 'application "%s" uninstalled': 'aplicación "%s" desinstalada', +'application %(appname)s installed with md5sum: %(digest)s': 'application %(appname)s installed with md5sum: %(digest)s', 'application compiled': 'aplicación compilada', 'application is compiled and cannot be designed': 'la aplicación está compilada y no puede ser modificada', 'Application name:': 'Application name:', @@ -92,6 +94,7 @@ 'Create new application using the Wizard': 'Create new application using the Wizard', 'create new application:': 'nombre de la nueva aplicación:', 'Create new simple application': 'Cree una nueva aplicación', +'Create/Upload': 'Create/Upload', 'created by': 'creado por', 'crontab': 'crontab', 'Current request': 'Solicitud en curso', diff --git a/gluon/dal.py b/gluon/dal.py index 4e9245ee..ea1107de 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -6150,8 +6150,8 @@ class IMAPAdapter(NoSQLAdapter): LOGGER.error("Could not parse date text: %s. %s" % (date, e)) return None - elif isinstance(date, (datetime.datetime, datetime.date)): - return (date + add).strftime("%d-%b-%Y") + elif isinstance(date, (datetime.date, datetime.datetime)): + return (date + add).strftime("%a, %d %b %Y %H:%M:%S %z") else: return None @@ -6532,7 +6532,8 @@ class IMAPAdapter(NoSQLAdapter): mailbox = table.mailbox d = dict(((k.name, v) for k, v in fields)) - date_time = (d.get("created", datetime.datetime.now())).timetuple() + date_time = d.get("created", datetime.datetime.now()) + struct_time = date_time.timetuple() if len(d) > 0: message = d.get("email", None) attachments = d.get("attachments", []) @@ -6547,6 +6548,8 @@ class IMAPAdapter(NoSQLAdapter): message = Message() message["from"] = d.get("sender", "") message["subject"] = d.get("subject", "") + message["date"] = self.convert_date(date_time) + if mime: message.set_type(mime) if charset: @@ -6569,7 +6572,7 @@ class IMAPAdapter(NoSQLAdapter): [add_payload(message, c) for c in content] [add_payload(message, a) for a in attachments] message = message.as_string() - return (mailbox, flags, date_time, message) + return (mailbox, flags, struct_time, message) else: raise NotImplementedError("IMAP empty insert is not implemented") From e7fbd0095f8d80e67fdd4b8e6ee0b3696150e16c Mon Sep 17 00:00:00 2001 From: spametki Date: Sun, 6 Oct 2013 14:39:23 -0300 Subject: [PATCH 2/2] IMAP google code issue 1707: fixed patch --- gluon/dal.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gluon/dal.py b/gluon/dal.py index ea1107de..3180ecce 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -6124,7 +6124,7 @@ class IMAPAdapter(NoSQLAdapter): else: return (uid_list[0], uid_list[-1]) - def convert_date(self, date, add=None): + def convert_date(self, date, add=None, imf=False): if add is None: add = datetime.timedelta() """ Convert a date object to a string @@ -6138,7 +6138,10 @@ class IMAPAdapter(NoSQLAdapter): if isinstance(date, basestring): # Prevent unexpected date response format try: - dayname, datestring = date.split(",") + if "," in date: + dayname, datestring = date.split(",") + else: + dayname, datestring = None, date date_list = datestring.strip().split() year = int(date_list[2]) month = months.index(date_list[1].upper()) @@ -6151,7 +6154,9 @@ class IMAPAdapter(NoSQLAdapter): (date, e)) return None elif isinstance(date, (datetime.date, datetime.datetime)): - return (date + add).strftime("%a, %d %b %Y %H:%M:%S %z") + if imf: date_format = "%a, %d %b %Y %H:%M:%S %z" + else: date_format = "%d-%b-%Y" + return (date + add).strftime(date_format) else: return None @@ -6548,7 +6553,7 @@ class IMAPAdapter(NoSQLAdapter): message = Message() message["from"] = d.get("sender", "") message["subject"] = d.get("subject", "") - message["date"] = self.convert_date(date_time) + message["date"] = self.convert_date(date_time, imf=True) if mime: message.set_type(mime)