From 41a9b83a0d0a1253aeb5d7aa108852128de504ee Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Thu, 10 Mar 2016 17:53:32 -0800 Subject: Fixed _set_date() in pipermail.py do do a better job. --- Mailman/Archiver/pipermail.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'Mailman/Archiver') diff --git a/Mailman/Archiver/pipermail.py b/Mailman/Archiver/pipermail.py index 9c54bbd9..15decd40 100644 --- a/Mailman/Archiver/pipermail.py +++ b/Mailman/Archiver/pipermail.py @@ -16,6 +16,7 @@ __version__ = '0.09 (Mailman edition)' VERSION = __version__ CACHESIZE = 100 # Number of slots in the cache +from Mailman import mm_cfg from Mailman import Errors from Mailman.Mailbox import ArchiverMailbox from Mailman.Logging.Syslog import syslog @@ -230,21 +231,30 @@ class Article: self.body = s.readlines() def _set_date(self, message): - def floatdate(header): - missing = [] - datestr = message.get(header, missing) - if datestr is missing: + def floatdate(datestr): + if not datestr: return None date = parsedate_tz(datestr) try: - return mktime_tz(date) + date = mktime_tz(date) + if (date < 0 or + date - time.time() > + mm_cfg.ARCHIVER_ALLOWABLE_SANE_DATE_SKEW + ): + return None + return date except (TypeError, ValueError, OverflowError): return None - date = floatdate('date') + date = floatdate(message.get('date')) + if date is None: + date = floatdate(message.get('x-list-received-date')) + if date is None: + date = floatdate(re.sub(r'^.*;\s*', '', + message.get('received'), flags=re.S)) if date is None: - date = floatdate('x-list-received-date') + date = floatdate(re.sub(r'From \s*\S+\s+', '', + message.get_unixfrom())) if date is None: - # What's left to try? date = self._last_article_time + 1 self._last_article_time = date self.date = '%011i' % date -- cgit v1.2.3 From c34680adb21d669521ca80c086b4913ba370fb79 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Fri, 11 Mar 2016 09:32:21 -0800 Subject: Fixed bug in last commit if no Received: header. --- Mailman/Archiver/pipermail.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Mailman/Archiver') diff --git a/Mailman/Archiver/pipermail.py b/Mailman/Archiver/pipermail.py index 15decd40..c03d43b3 100644 --- a/Mailman/Archiver/pipermail.py +++ b/Mailman/Archiver/pipermail.py @@ -250,10 +250,10 @@ class Article: date = floatdate(message.get('x-list-received-date')) if date is None: date = floatdate(re.sub(r'^.*;\s*', '', - message.get('received'), flags=re.S)) + message.get('received', ''), flags=re.S)) if date is None: date = floatdate(re.sub(r'From \s*\S+\s+', '', - message.get_unixfrom())) + message.get_unixfrom() or '' )) if date is None: date = self._last_article_time + 1 self._last_article_time = date -- cgit v1.2.3