summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2016-08-30 11:19:16 -0400
committerMatthew Treinish <mtreinish@kortar.org>2016-08-30 14:44:41 -0400
commit01050415dc8cb0e253823ad5fff5e4439a0205b4 (patch)
treea20571966501ebeb0c4e4fb127b790bfbc3239bf
parent33db094142f67c293416af9a29eb112a17473580 (diff)
Fix bug email subject processing0.0.1
This commit fixes some issues that would come up if the email had a subject encoded in a different charset like utf8. Now lpmqtt will attempt to decode the subject and failing that exclude the bug number from the response, instead of blowing up like it did before.
-rw-r--r--lpmqtt/daemon.py3
-rw-r--r--lpmqtt/lp.py13
2 files changed, 13 insertions, 3 deletions
diff --git a/lpmqtt/daemon.py b/lpmqtt/daemon.py
index ba2c5e3..1043fa7 100644
--- a/lpmqtt/daemon.py
+++ b/lpmqtt/daemon.py
@@ -51,7 +51,8 @@ def process_event(event, base_topic):
51 pieces.append(event['project']) 51 pieces.append(event['project'])
52 if 'event_type' in event: 52 if 'event_type' in event:
53 pieces.append(event['event-type']) 53 pieces.append(event['event-type'])
54 pieces.append(event['bug-number']) 54 if 'bug-number' in event:
55 pieces.append(event['bug-number'])
55 topic = "/".join(pieces) 56 topic = "/".join(pieces)
56 msg = json.dumps(event) 57 msg = json.dumps(event)
57 return msg, topic 58 return msg, topic
diff --git a/lpmqtt/lp.py b/lpmqtt/lp.py
index 6e9baeb..507970a 100644
--- a/lpmqtt/lp.py
+++ b/lpmqtt/lp.py
@@ -13,6 +13,7 @@
13# under the License. 13# under the License.
14 14
15import email 15import email
16from email.header import decode_header
16import re 17import re
17 18
18import imaplib2 as imaplib 19import imaplib2 as imaplib
@@ -46,8 +47,16 @@ class LPImapWatcher(object):
46 if bug_tags: 47 if bug_tags:
47 event['tags'] = bug_tags.split(' ') 48 event['tags'] = bug_tags.split(' ')
48 subject = message['Subject'] 49 subject = message['Subject']
49 bug_num_str = re.match('^\[(.*?)\]', subject).group(0) 50 header_decode_out = decode_header(subject)
50 event['bug-number'] = bug_num_str.split(' ')[1].rstrip(']') 51 subject = header_decode_out[0][0]
52 bug_num_re_match = re.match('^\[(.*?)\]', subject)
53 if not bug_num_re_match:
54 print("Subject %s does not contain a parseable bug number"
55 % subject)
56 else:
57 bug_num_str = bug_num_re_match.group(0)
58 event['bug-number'] = bug_num_str.split(' ')[1].rstrip(']')
59
51 bug_info = message['X-Launchpad-Bug'].split(';') 60 bug_info = message['X-Launchpad-Bug'].split(';')
52 for info in bug_info: 61 for info in bug_info:
53 clean_info = info.lstrip() 62 clean_info = info.lstrip()