Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core

Commits:
b8d9fec1 by Mark Sapiro at 2018-01-19T16:02:27-08:00
Caught and handled a LookupError in subject prefixing.

Added a test for the above.

Fixed the test for blank subject_prefix which erroneously set _fasttrack.

- - - - -
8509f565 by Mark Sapiro at 2018-01-19T16:25:55-08:00
Require SQLAlchemy < 1.2 because of a test failure.

- - - - -
8a87a59c by Mark Sapiro at 2018-01-22T20:19:40+00:00
Merge branch 'prefix' into 'master'

Caught and handled a LookupError in subject prefixing.

Closes #445

See merge request mailman/mailman!354
- - - - -


4 changed files:

- setup.py
- src/mailman/docs/NEWS.rst
- src/mailman/handlers/subject_prefix.py
- src/mailman/handlers/tests/test_subject_prefix.py


Changes:

=====================================
setup.py
=====================================
--- a/setup.py
+++ b/setup.py
@@ -116,7 +116,7 @@ case second `m'.  Any other spelling is incorrect.""",
         'lazr.config',
         'passlib',
         'requests',
-        'sqlalchemy',
+        'sqlalchemy<1.2',
         'zope.component',
         'zope.configuration',
         'zope.event',


=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -52,6 +52,8 @@ Bugs
 * A new SQLAlchemy column type ``SAUnicodeXL`` has been implemented to support
   large columns in MySQL and is used for the ``value`` column of the
   ``pendedkeyvalue`` table.  (Closes #385)
+* Messages with ``Subject`` headers encoded in an unknown character set no
+  longer throw ``LookupError`` in subject prefixing.  (Closes #445)
 
 Command line
 ------------


=====================================
src/mailman/handlers/subject_prefix.py
=====================================
--- a/src/mailman/handlers/subject_prefix.py
+++ b/src/mailman/handlers/subject_prefix.py
@@ -72,7 +72,11 @@ def all_same_charset(mlist, msgdata, subject, prefix, 
prefix_pattern, ws):
         if isinstance(chunk, str):
             chunks.append(chunk)
         else:
-            chunks.append(chunk.decode(charset))
+            try:
+                chunks.append(chunk.decode(charset))
+            except LookupError as e:
+                # The charset value is unknown.
+                return None
         if charset != list_charset:
             return None
     subject_text = EMPTYSTRING.join(chunks)
@@ -117,7 +121,12 @@ def mixed_charsets(mlist, msgdata, subject, prefix, 
prefix_pattern, ws):
     if isinstance(chunk_text, str):
         first_text = chunk_text
     else:
-        first_text = chunk_text.decode(chunk_charset)
+        try:
+            first_text = chunk_text.decode(chunk_charset)
+        except LookupError as e:
+            # The chunk_charset is unknown. Add a dummy first_text.
+            chunks.insert(0, ('', 'us-ascii'))
+            first_text = ''
     first_text = re.sub(prefix_pattern, '', first_text).lstrip()
     rematch = re.match(RE_PATTERN, first_text, re.I)
     if rematch:


=====================================
src/mailman/handlers/tests/test_subject_prefix.py
=====================================
--- a/src/mailman/handlers/tests/test_subject_prefix.py
+++ b/src/mailman/handlers/tests/test_subject_prefix.py
@@ -55,7 +55,7 @@ class TestSubjectPrefix(unittest.TestCase):
         self._mlist.subject_prefix = '    '
         msg = Message()
         msg['Subject'] = 'A test message'
-        self._process(self._mlist, msg, dict(_fasttrack=True))
+        self._process(self._mlist, msg, {})
         self.assertEqual(str(msg['subject']), 'A test message')
 
     def test_save_original_subject(self):
@@ -136,3 +136,11 @@ class TestSubjectPrefix(unittest.TestCase):
         subject = msg['subject']
         self.assertEqual(subject.encode(),
                          '=?iso-8859-1?q?=5BTest=5D_?= Plain text')
+
+    def test_unknown_encoded_subject(self):
+        msg = Message()
+        msg['Subject'] = '=?unknown-8bit?q?Non-ascii_subject_-_français?='
+        self._process(self._mlist, msg, {})
+        subject = msg['subject']
+        self.assertEqual(str(subject),
+                         '[Test]  Non-ascii subject - fran�ais')



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/5477a201469cdd2259225d07ab4052e348e0e1b3...8a87a59cf5e60ead2b5a4d6faee39443f459e272

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/5477a201469cdd2259225d07ab4052e348e0e1b3...8a87a59cf5e60ead2b5a4d6faee39443f459e272
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to