Better handling for multipart message replies

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-11-17 10:49:44 -05:00
parent 867b1edb24
commit 65e9b15414
1 changed files with 13 additions and 3 deletions

View File

@ -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 <whenever>" 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()