From 65e9b15414f019def6d7aa6d4a2b4d937cac003c Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 17 Nov 2016 10:49:44 -0500 Subject: [PATCH] Better handling for multipart message replies Signed-off-by: Anna Schumaker --- slackpost.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/slackpost.py b/slackpost.py index b2d294c..f7cde12 100755 --- a/slackpost.py +++ b/slackpost.py @@ -20,11 +20,22 @@ if addr.replace(".", "") != slack.user().email().replace(".", ""): sys.exit(1) +# +# Find the message payload (this is tricky for multipart messages) +# +if headers.is_multipart(): + for part in headers.get_payload(): + if part.get_content_type() == "text/plain": + payload = part.get_payload() +else: + payload = headers.get_payload() + + # # Find the thread id in the message payload # reply = "--- Reply above this line ---(\s*?)thread=(.*?)\n" -match = re.search(reply, headers.get_payload()) +match = re.search(reply, payload) if match == None: print("Reply line missing!") sys.exit(1) @@ -39,8 +50,7 @@ thread_id = match.group(0).rsplit("=")[-1].rstrip() # - Quoted text will always begin with ">" # - The email reply will always have "Reply sent on " text # -message = headers.get_payload() -message = re.sub(">(.*?)\n", "", message).rstrip() +message = re.sub(">(.*?)\n", "", payload).rstrip() split = message.split("\n") message = "\n".join(split[:-1]).rstrip()