Fix bug email subject processing
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.
This commit is contained in:
parent
33db094142
commit
01050415dc
|
@ -51,7 +51,8 @@ def process_event(event, base_topic):
|
|||
pieces.append(event['project'])
|
||||
if 'event_type' in event:
|
||||
pieces.append(event['event-type'])
|
||||
pieces.append(event['bug-number'])
|
||||
if 'bug-number' in event:
|
||||
pieces.append(event['bug-number'])
|
||||
topic = "/".join(pieces)
|
||||
msg = json.dumps(event)
|
||||
return msg, topic
|
||||
|
|
13
lpmqtt/lp.py
13
lpmqtt/lp.py
|
@ -13,6 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
import email
|
||||
from email.header import decode_header
|
||||
import re
|
||||
|
||||
import imaplib2 as imaplib
|
||||
|
@ -46,8 +47,16 @@ class LPImapWatcher(object):
|
|||
if bug_tags:
|
||||
event['tags'] = bug_tags.split(' ')
|
||||
subject = message['Subject']
|
||||
bug_num_str = re.match('^\[(.*?)\]', subject).group(0)
|
||||
event['bug-number'] = bug_num_str.split(' ')[1].rstrip(']')
|
||||
header_decode_out = decode_header(subject)
|
||||
subject = header_decode_out[0][0]
|
||||
bug_num_re_match = re.match('^\[(.*?)\]', subject)
|
||||
if not bug_num_re_match:
|
||||
print("Subject %s does not contain a parseable bug number"
|
||||
% subject)
|
||||
else:
|
||||
bug_num_str = bug_num_re_match.group(0)
|
||||
event['bug-number'] = bug_num_str.split(' ')[1].rstrip(']')
|
||||
|
||||
bug_info = message['X-Launchpad-Bug'].split(';')
|
||||
for info in bug_info:
|
||||
clean_info = info.lstrip()
|
||||
|
|
Loading…
Reference in New Issue