Commit a7046dca authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

Add workaround for MUAs that don't handle UTF-8

Some MUAs seem to send UTF-8 in headers (e.g.: Subject) as is instead of
escaping it using RFC2047.

Those usually get mangled somewhere on the way by the MTA/MDA and we end
up with something escaped with 'unknown-8bit' encoding.

Python raises an exception if we ever try to parse that, so it's better
to at least try to decode it as UTF-8.

Fixes: #43Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent 16a53dad
Pipeline #167442 passed with stage
in 1 minute and 47 seconds
......@@ -79,6 +79,10 @@ def normalise_space(str):
def clean_header(header):
""" Decode (possibly non-ascii) headers """
if header.startswith('=?unknown-8bit?'):
LOGGER.debug("unknown-8bit in header, trying to assume utf-8")
header = header.replace('=?unknown-8bit?', '=?utf-8?')
def decode(fragment):
(frag_str, frag_encoding) = fragment
if frag_encoding:
......
......@@ -26,7 +26,8 @@ from django.test import TestCase, TransactionTestCase
from patchwork.bin.parsemail import (find_content, find_author, find_project,
mail_headers, parse_mail, split_prefixes,
clean_subject, parse_series_marker)
clean_subject, clean_header,
parse_series_marker)
from patchwork.models import (Project, Person, Patch, Comment, State, EventLog,
Event, SeriesRevision, Series, RevisionState,
get_default_initial_patch_state)
......@@ -1160,3 +1161,13 @@ class SubjectTest(TestCase):
('[bar] meep', ['bar']))
self.assertEqual(clean_subject('[FOO] [bar] meep', ['foo']),
('[bar] meep', ['bar']))
def testHandlesUTF8(self):
h = '=?utf-8?b?4pyXIEZpLkNJLkNIRUNLUEFUQ0g6IHdhcm5pbmcg?='
h = clean_header(h)
self.assertEqual('✗ Fi.CI.CHECKPATCH: warning', h)
def testCleanHeaderUnknown8bit(self):
h = '=?unknown-8bit?q?=E2=9C=97_Fi=2ECI=2EIGT=3A_failure?='
h = clean_header(h)
self.assertEqual('✗ Fi.CI.IGT: failure', h)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment