Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits:
f5d6b2e9 by Mark Sapiro at 2021-07-27T21:23:56-07:00
Code cleanup and additional tests.
- - - - -
49b7cd66 by Mark Sapiro at 2021-07-28T04:54:34+00:00
Merge branch 'pref' into 'master'
Code cleanup and additional tests.
See merge request mailman/mailman!897
- - - - -
2 changed files:
- src/mailman/handlers/subject_prefix.py
- src/mailman/handlers/tests/test_subject_prefix.py
Changes:
=====================================
src/mailman/handlers/subject_prefix.py
=====================================
@@ -39,8 +39,7 @@ def ascii_header(mlist, msgdata, subject, prefix,
prefix_pattern, ws):
if charset not in ASCII_CHARSETS:
return None
subject_text = EMPTYSTRING.join(str(subject).splitlines())
- # At this point, the subject may become null if someone posted mail
- # with "Subject: [subject prefix]".
+ # Replace empty subject.
if subject_text.strip() == '':
with _.using(mlist.preferred_language.code):
subject_text = _('(no subject)')
@@ -86,10 +85,9 @@ def all_same_charset(mlist, msgdata, subject, prefix,
prefix_pattern, ws):
except UnicodeEncodeError:
return None
subject_text = EMPTYSTRING.join(chunks)
- # At this point, the subject may become null if someone posted mail
- # with "Subject: [subject prefix]".
+ # Replace empty subject.
if subject_text.strip() == '':
- with _.push(mlist.preferred_language.code):
+ with _.using(mlist.preferred_language.code):
subject_text = _('(no subject)')
else:
subject_text = re.sub(prefix_pattern, '', subject_text)
@@ -116,13 +114,17 @@ def all_same_charset(mlist, msgdata, subject, prefix,
prefix_pattern, ws):
def mixed_charsets(mlist, msgdata, subject, prefix, prefix_pattern, ws):
list_charset = mlist.preferred_language.charset
chunks = decode_header(subject.encode())
- if len(chunks) == 0:
- with _.push(mlist.preferred_language.code):
- subject_text = _('(no subject)')
- chunks = [(prefix, list_charset),
- (subject_text, list_charset),
- ]
- return make_header(chunks, continuation_ws=ws)
+ # This code was:
+ # if len(chunks) == 0:
+ # with _.using(mlist.preferred_language.code):
+ # subject_text = _('(no subject)')
+ # chunks = [(prefix, list_charset),
+ # (subject_text, list_charset),
+ # ]
+ # return make_header(chunks, continuation_ws=ws)
+ # but len(chunks) == 0 is always False and an empty Subject: will always
+ # be processed in all_same_charset() anyway.
+
# Only search the first chunk for Re and existing prefix.
chunk_text, chunk_charset = chunks[0]
if chunk_charset is None:
=====================================
src/mailman/handlers/tests/test_subject_prefix.py
=====================================
@@ -179,6 +179,33 @@ class TestSubjectPrefix(unittest.TestCase):
subject = msg['subject']
self.assertEqual(str(subject), '[Test] Re: ')
+ def test_empty(self):
+ # Incoming subject is empty.
+ msg = Message()
+ msg['Subject'] = ''
+ self._process(self._mlist, msg, {})
+ subject = msg['subject']
+ self.assertEqual(str(subject), '[Test] (no subject)')
+
+ def test_empty_all_same(self):
+ # Incoming subject is empty.
+ msg = Message()
+ msg['Subject'] = '=?utf-8?Q?_?='
+ old_charset = self._mlist.preferred_language.charset
+ self._mlist.preferred_language.charset = 'utf-8'
+ self._process(self._mlist, msg, {})
+ self._mlist.preferred_language.charset = old_charset
+ subject = msg['subject']
+ self.assertEqual(str(subject), '[Test] (no subject)')
+
+ def test_empty_mixed(self):
+ # Incoming subject is empty.
+ msg = Message()
+ msg['Subject'] = '=?utf-8?Q?_?='
+ self._process(self._mlist, msg, {})
+ subject = msg['subject']
+ self.assertEqual(str(subject), '[Test] (no subject)')
+
def test_i18n_subject_with_sequential_prefix_and_re(self):
# The mailing list defines a sequential prefix, and the original
# Subject has a prefix with a different sequence number, *and* it also
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/10b6007b26c2083595e47a5e53c5415e89ee6c29...49b7cd6672ea41b8cc6b6335f50665338385dd9d
--
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/10b6007b26c2083595e47a5e53c5415e89ee6c29...49b7cd6672ea41b8cc6b6335f50665338385dd9d
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: [email protected]