diff options
author | Frank Vanderham <twelve.eighty@gmail.com> | 2018-04-25 14:19:33 -0600 |
---|---|---|
committer | Jelle van der Waa <jelle@vdwaa.nl> | 2019-01-21 21:19:58 +0100 |
commit | bee446fc982ac59ef0ad7066aa2fb3588da19dcd (patch) | |
tree | 40cb1e83395bba25ea6a6a4252331f048c11be0e /main | |
parent | f972220bbc14e019942267642c7d3a093e9e1746 (diff) | |
download | archweb-bee446fc982ac59ef0ad7066aa2fb3588da19dcd.tar.gz archweb-bee446fc982ac59ef0ad7066aa2fb3588da19dcd.zip |
Fix Python 2 to 3 Unicode issues for string join
Revisited earlier commit where email subject lines with potentially
mixed encoding are joined into a single string. This fix brings in
the 'codecs' import to decode bytes to string using either the passed
encoding (if provided) or otherwise utf-8.
Changed the test_donor_import to no longer convert the Header to a
string and instead leave it as a byte array.
Diffstat (limited to 'main')
-rw-r--r-- | main/management/commands/donor_import.py | 3 | ||||
-rw-r--r-- | main/tests/test_donor_import.py | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/main/management/commands/donor_import.py b/main/management/commands/donor_import.py index b8bdbf54..cc0e59f2 100644 --- a/main/management/commands/donor_import.py +++ b/main/management/commands/donor_import.py @@ -14,6 +14,7 @@ Subject: Receipt [$25.00] By: John Doe [john.doe@archlinux.org] Usage: ./manage.py donor_import path/to/maildir/ """ +import codecs import logging import mailbox import sys @@ -46,7 +47,7 @@ class Command(BaseCommand): default_charset = 'utf-8' # Convert the list of tuples containing the decoded string and encoding to # UTF-8 - return u''.join([s[0].encode(default_charset, 'replace').decode(default_charset, 'replace') for s in subject]) + return ''.join([codecs.decode(s[0], s[1] or default_charset) for s in subject]) def parse_subject(self, subject): diff --git a/main/tests/test_donor_import.py b/main/tests/test_donor_import.py index f31ae099..0f27eee7 100644 --- a/main/tests/test_donor_import.py +++ b/main/tests/test_donor_import.py @@ -38,7 +38,7 @@ class DonorImportTest(TransactionTestCase): def test_decode_subject(self): text = u'メイル' - subject = str(Header(text, 'utf-8')) + subject = Header(text, 'utf-8') self.assertEqual(self.command.decode_subject(subject), text) def test_invalid_args(self): |