From: W. Trevor King Date: Sat, 1 Sep 2012 00:46:54 +0000 (-0400) Subject: mailpipe: add support for multi-part subjects in _get_message_subject. X-Git-Tag: v0.3~49 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c622b03090b45a9c9755c1724a8b0eedc24af36d;p=pygrader.git mailpipe: add support for multi-part subjects in _get_message_subject. --- diff --git a/pygrader/mailpipe.py b/pygrader/mailpipe.py index 1ad75ca..5b18de8 100644 --- a/pygrader/mailpipe.py +++ b/pygrader/mailpipe.py @@ -675,13 +675,11 @@ def _get_message_subject(course, message, original, person, ValueError: no subject in msg-id >>> del message['Subject'] >>> subject = Header('unicode part', 'utf-8') - >>> subject.append('ascii part', 'ascii') + >>> subject.append('-ascii part', 'ascii') >>> message['Subject'] = subject.encode() >>> _get_message_subject( ... course=None, message=message, original=message, person=None) - Traceback (most recent call last): - ... - ValueError: multi-part header [(b'unicode part', 'utf-8'), (b'ascii part', None)] + 'unicode part-ascii part' >>> del message['Subject'] >>> message['Subject'] = 'clean subject' >>> _get_message_subject( @@ -701,13 +699,14 @@ def _get_message_subject(course, message, original, person, raise ValueError(response_subject) parts = _decode_header(message['Subject']) - if len(parts) != 1: - raise ValueError('multi-part header {}'.format(parts)) - subject,encoding = parts[0] - if encoding is None: - encoding = 'ascii' - if not isinstance(subject, str): - subject = str(subject, encoding) + part_strings = [] + for string,encoding in parts: + if encoding is None: + encoding = 'ascii' + if not isinstance(string, str): + string = str(string, encoding) + part_strings.append(string) + subject = ''.join(part_strings) _LOG.debug('decoded header {} -> {}'.format(parts[0], subject)) return subject.lower().replace('#', '')