aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-02-13 17:52:43 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-02-13 17:52:43 -0500
commite8fd5a0e03371fb11af50bdd81f933ceeda4bc3a (patch)
treee7a1ac8ae080b92ffc1bc5fa4a6cf6fbbc17495c
parent2e62cad9eaddddd87ad67b298ab12ba0f1944231 (diff)
downloadkorg-helpers-e8fd5a0e03371fb11af50bdd81f933ceeda4bc3a.tar.gz
Make sure follow-up trailers match email in From
This is mostly to avoid bogus matches, but adds a small layer of sanity checking. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-xget-lore-mbox.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/get-lore-mbox.py b/get-lore-mbox.py
index 61fb0dd..eb309b7 100755
--- a/get-lore-mbox.py
+++ b/get-lore-mbox.py
@@ -28,7 +28,7 @@ from email import charset
charset.add_charset('utf-8', None)
logger = logging.getLogger('get-lore-mbox')
-VERSION = '0.2'
+VERSION = '0.2.1'
# You can use bash-style globbing here
WANTHDRS = [
@@ -314,6 +314,8 @@ class LoreMessage:
# Header-based info
self.in_reply_to = None
+ self.fromname = None
+ self.fromemail = None
# Body and body-based info
self.body = None
@@ -340,6 +342,13 @@ class LoreMessage:
self.in_reply_to = LoreMessage.get_clean_msgid(self.msg, header='In-Reply-To')
+ try:
+ fromdata = email.utils.getaddresses(self.msg.get_all('from', []))[0]
+ self.fromname = fromdata[0]
+ self.fromemail = fromdata[1]
+ except IndexError:
+ pass
+
# walk until we find the first text/plain part
mcharset = self.msg.get_content_charset()
if not mcharset:
@@ -363,16 +372,24 @@ class LoreMessage:
if re.search(r'^---.*\n\+\+\+', self.body, re.MULTILINE):
self.has_diff = True
- # Do we have something that looks like a person-trailer?
- matches = re.findall(r'^\s*([\w-]+):\s+(.*<\S+>)\s*$', self.body, re.MULTILINE)
- if matches:
- self.trailers = matches
+ # We only pay attention to trailers that are sent in reply
+ if self.reply:
+ # Do we have something that looks like a person-trailer?
+ matches = re.findall(r'^\s*([\w-]+):\s+(.*<\S+>)\s*$', self.body, re.MULTILINE)
+ if matches:
+ # Does the email in the trailer match what's in the From?
+ for tname, tvalue in matches:
+ namedata = email.utils.getaddresses([tvalue])[0]
+ if namedata[1].lower() == self.fromemail.lower():
+ self.trailers.append((tname, tvalue))
def __repr__(self):
out = list()
out.append('msgid: %s' % self.msgid)
out.append(str(self.lsubject))
+ out.append(' fromname: %s' % self.fromname)
+ out.append(' fromemail: %s' % self.fromemail)
out.append(' in_reply_to: %s' % self.in_reply_to)
# Header-based info