Better handling for multipart message replies
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
867b1edb24
commit
65e9b15414
16
slackpost.py
16
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 <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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue