From 2f37e6f8e1401c7976f1f5f48bea404fe0e46af0 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 30 Nov 2020 17:59:23 -0500 Subject: Fix headers generated by "b4 ty" Make sure we always create a Date: header, and that we're not crashing when we try to parse a message without a Date: header. Signed-off-by: Konstantin Ryabitsev --- .gitignore | 2 ++ b4/__init__.py | 7 ++++++- b4/ty.py | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5d6f10a..209539a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ __pycache__ *.patch *.mbx *.cover +*.thanks +.venv diff --git a/b4/__init__.py b/b4/__init__.py index e7b27cd..c77ca9a 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -833,7 +833,12 @@ class LoreMessage: except IndexError: pass - self.date = email.utils.parsedate_to_datetime(str(self.msg['Date'])) + msgdate = self.msg.get('Date') + if msgdate: + self.date = email.utils.parsedate_to_datetime(str(msgdate)) + else: + # An email without a Date: field? + self.date = datetime.datetime.now() diffre = re.compile(r'^(---.*\n\+\+\+|GIT binary patch|diff --git \w/\S+ \w/\S+)', re.M | re.I) diffstatre = re.compile(r'^\s*\d+ file.*\d+ (insertion|deletion)', re.M | re.I) diff --git a/b4/ty.py b/b4/ty.py index 96ce3af..842ec11 100644 --- a/b4/ty.py +++ b/b4/ty.py @@ -92,7 +92,8 @@ def make_reply(reply_template, jsondata): allto.append((jsondata['fromname'], jsondata['fromemail'])) msg['To'] = b4.format_addrs(allto) - msg['Cc'] = b4.format_addrs(allcc) + if allcc: + msg['Cc'] = b4.format_addrs(allcc) msg['In-Reply-To'] = '<%s>' % jsondata['msgid'] if len(jsondata['references']): msg['References'] = '%s <%s>' % (jsondata['references'], jsondata['msgid']) @@ -107,6 +108,7 @@ def make_reply(reply_template, jsondata): mydomain = jsondata['myemail'].split('@')[1] msg['Message-Id'] = email.utils.make_msgid(idstring='b4-ty', domain=mydomain) + msg['Date'] = email.utils.formatdate(localtime=True) return msg -- cgit v1.2.3