From b9f8773d42671900fed03949154432b23a15612c Mon Sep 17 00:00:00 2001 From: James Boswell Date: Fri, 7 Jul 2017 15:18:26 -0400 Subject: [PATCH] Handle THOLD alerts with no image/jpg or otherwise missing attachment * Handle multipart message with no image/jpg subpart * Remove DEBUG print statements from get_image --- thold-slack.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/thold-slack.py b/thold-slack.py index 0807e50..0885617 100644 --- a/thold-slack.py +++ b/thold-slack.py @@ -213,11 +213,12 @@ def get_image(message): # get the FIRST image JPEG version only image_parts = [part for part in typed_subpart_iterator(message, 'image', 'jpg')] - image_part = image_parts[0] + image_part = "" if len(image_parts) is 0 else image_parts[0] return return_image(image_part) else: - attachment = message.get_payload()[1] + payload = message.get_payload() + attachment = "" if len(payload) is 0 else payload[1] return return_image(attachment)