Commit 257b5809 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

Fix workarounds for MUAs that don't handle UTF-8

Turns out that clean_header() takes Header, so we were getting:
  AttributeError
  'Header' object has no attribute 'startswith'

Let's use Header in the test and fix the issue properly.

Fix: a7046dca ("Add workaround for MUAs that don't handle UTF-8")
Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent 462c95c3
Pipeline #172141 passed with stage
in 1 minute and 41 seconds
......@@ -79,13 +79,12 @@ 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:
if frag_encoding == 'unknown-8bit':
frag_encoding = 'utf-8'
LOGGER.debug("unknown-8bit in header, trying to assume utf-8")
return frag_str.decode(frag_encoding)
elif isinstance(frag_str, bytes):
return frag_str.decode()
......
......@@ -21,6 +21,7 @@ from email import message_from_string
from email.mime.text import MIMEText
from email.utils import make_msgid
from email.parser import HeaderParser
from email.header import make_header
from django.test import TestCase, TransactionTestCase
......@@ -1163,11 +1164,13 @@ class SubjectTest(TestCase):
('[bar] meep', ['bar']))
def testHandlesUTF8(self):
h = '=?utf-8?b?4pyXIEZpLkNJLkNIRUNLUEFUQ0g6IHdhcm5pbmcg?='
raw_utf8 = '✗ Fi.CI.CHECKPATCH: warning'
h = make_header([(raw_utf8.encode(), 'utf-8')])
h = clean_header(h)
self.assertEqual('✗ Fi.CI.CHECKPATCH: warning', h)
self.assertEqual(raw_utf8, h)
def testCleanHeaderUnknown8bit(self):
h = '=?unknown-8bit?q?=E2=9C=97_Fi=2ECI=2EIGT=3A_failure?='
raw_utf8 = '✗ Fi.CI.CHECKPATCH: warning'
h = make_header([(raw_utf8.encode(), 'unknown-8bit')])
h = clean_header(h)
self.assertEqual('✗ Fi.CI.IGT: failure', h)
self.assertEqual(raw_utf8, 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