From fa7659656039a7a1037e984febf374c66e2c3025 Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Mon, 15 May 2017 16:24:48 -0400 Subject: [PATCH 1/2] initial commit for #231 --- tools/archiver.py | 11 +++++++---- tools/import-mbox.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/archiver.py b/tools/archiver.py index 141a4318..2085ba7c 100755 --- a/tools/archiver.py +++ b/tools/archiver.py @@ -240,7 +240,7 @@ def msgbody(self, msg): return body - def compute_updates(self, lid, private, msg): + def compute_updates(self, lid, private, msg, default_invalid_date_to_now=True): """Determine what needs to be sent to the archiver. :param lid: The list id @@ -288,9 +288,12 @@ def compute_updates(self, lid, private, msg): if not mdate and msg_metadata.get('archived-at'): mdate = email.utils.parsedate_tz(msg_metadata.get('archived-at')) elif not mdate: - print("Date (%s) seems totally wrong, setting to _now_ instead." % mdate) - mdate = time.gmtime() # Get a standard 9-tuple - mdate = mdate + (0, ) # Fake a TZ (10th element) + if default_invalid_date_to_now: + print("Date (%s) seems totally wrong, setting to _now_ instead." % mdate) + mdate = time.gmtime() # Get a standard 9-tuple + mdate = mdate + (0, ) # Fake a TZ (10th element) + else: + print("Date (%s) seems totally wrong, TODO: figure out what to do now" % mdate) mdatestring = time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(email.utils.mktime_tz(mdate))) body = self.msgbody(msg) try: diff --git a/tools/import-mbox.py b/tools/import-mbox.py index 7901a091..65d42805 100755 --- a/tools/import-mbox.py +++ b/tools/import-mbox.py @@ -267,7 +267,7 @@ def mailgen(list): bad += 1 continue - json, contents = archie.compute_updates(list_override, private, message) + json, contents = archie.compute_updates(list_override, private, message, default_invalid_date_to_now=False) # Not sure this can ever happen if json and not (json['list'] and json['list_raw']): From 7645b090dd215c7b0262551d3feca9c9579e4a53 Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Mon, 15 May 2017 18:11:34 -0400 Subject: [PATCH 2/2] defer mdatestring calculation --- tools/archiver.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/archiver.py b/tools/archiver.py index 2085ba7c..46509568 100755 --- a/tools/archiver.py +++ b/tools/archiver.py @@ -287,14 +287,10 @@ def compute_updates(self, lid, private, msg, default_invalid_date_to_now=True): pass if not mdate and msg_metadata.get('archived-at'): mdate = email.utils.parsedate_tz(msg_metadata.get('archived-at')) - elif not mdate: - if default_invalid_date_to_now: - print("Date (%s) seems totally wrong, setting to _now_ instead." % mdate) - mdate = time.gmtime() # Get a standard 9-tuple - mdate = mdate + (0, ) # Fake a TZ (10th element) - else: - print("Date (%s) seems totally wrong, TODO: figure out what to do now" % mdate) - mdatestring = time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(email.utils.mktime_tz(mdate))) + elif not mdate and default_invalid_date_to_now: + print("Date (%s) seems totally wrong, setting to _now_ instead." % mdate) + mdate = time.gmtime() # Get a standard 9-tuple + mdate = mdate + (0, ) # Fake a TZ (10th element) body = self.msgbody(msg) try: if 'content-type' in msg_metadata and msg_metadata['content-type'].find("flowed") != -1: @@ -316,7 +312,8 @@ def compute_updates(self, lid, private, msg, default_invalid_date_to_now=True): attachments, contents = self.msgfiles(msg) irt = "" - if body is not None or attachments: + if (mdate is not None) and (body is not None or attachments): + mdatestring = time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(email.utils.mktime_tz(mdate))) pmid = mid try: # Use full message as bytes for mid?