]> khamidou — GitHub mirrors - flanker.git/commitdiff
Add support for Chinese character sets GB2312 and GB18030. fix_chinese_subjects
authorKarim Hamidou <khamidou@gmail.com>
Mon, 2 May 2016 22:28:47 +0000 (15:28 -0700)
committerKarim Hamidou <khamidou@gmail.com>
Mon, 2 May 2016 22:28:47 +0000 (15:28 -0700)
These character sets are mostly used in mainland China.

flanker/mime/message/charsets.py
tests/mime/message/headers/encodedword_test.py

index 9cd1333fb9afdb97362ee459ad3bf55e048d94fb..296e999d18eaa5d1eace8c6be8111f213423c570 100644 (file)
@@ -19,16 +19,22 @@ def _translate_charset(charset):
     Otherwise returns unmodified.
     """
     # ev: (ticket #2819)
-    if "sjis" in charset.lower():
+    if 'sjis' in charset.lower():
         return 'shift_jis'
 
     # cp874 looks to be an alias for windows-874
-    if "windows-874" == charset.lower():
-        return "cp874"
+    if 'windows-874' == charset.lower():
+        return 'cp874'
 
     if 'koi8-r' in charset.lower():
         return 'koi8_r'
 
+    if 'gb2312' in charset.lower():
+        return 'gb2312'
+
+    if 'gb18030' in charset.lower():
+        return 'gb18030'
+
     if 'utf-8' in charset.lower() or charset.lower() == 'x-unknown':
         return 'utf-8'
 
index 73b248d4955c4a9bd53a8419d8b0bafdd370dca4..50fc5b30189c6c69e84f4c9533f697ebffc0a9ea 100644 (file)
@@ -131,6 +131,12 @@ def various_encodings_test():
     v = u'=?utf-8?Q?Evaneos-Concepci=C3=B3n.pdf?='
     eq_(u'Evaneos-Concepción.pdf', encodedword.mime_to_unicode(v))
 
+    v = u'=?gb2312?Q?Hey_There=D7=B2=D8=B0?='
+    eq_(u'Hey There撞匕', encodedword.mime_to_unicode(v))
+
+    v = u'=?gb18030?Q?Hey_There=D7=B2=D8=B0?='
+    eq_(u'Hey There撞匕', encodedword.mime_to_unicode(v))
+
 
 @patch.object(utils, '_guess_and_convert', Mock(side_effect=errors.EncodingError()))
 def test_convert_to_utf8_unknown_encoding():