Commit 6cbf136e authored by Frank Vanderham's avatar Frank Vanderham Committed by Jelle van der Waa
Browse files

Fix Python 2 vs. Python 3 Unicode string issues

* Fixed issue with string concatenation that fails under Python 3
* Fixed issue with concatenating strings with potentially mixed
encoding. All strings are now first converted to UTF-8 and then
concatenated.
parent 7bc24570
......@@ -43,10 +43,10 @@ def add_arguments(self, parser):
def decode_subject(self, subject):
subject = decode_header(subject)
default_charset = 'ASCII'
default_charset = 'utf-8'
# Convert the list of tuples containing the decoded string and encoding to
# the same encoding.
return u''.join([unicode(s[0], s[1] or default_charset) for s in subject])
# UTF-8
return u''.join([s[0].encode(default_charset, 'replace').decode(default_charset, 'replace') for s in subject])
def parse_subject(self, subject):
......@@ -67,7 +67,7 @@ def sanitize_name(self, name):
return u''
# Strip any numbers, they could be a bank account number
name = filter(lambda x: not x.isdigit(), name)
name = u''.join([l for l in name if not l.isdigit()])
# Normalize all capitalized names. (JOHN DOE)
name = u' '.join(l.capitalize() for l in name.split(u' '))
......
Supports Markdown
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