Barry Warsaw pushed to branch release-3.0 at mailman / Mailman

Commits:
e745bf03 by Mark Sapiro at 2015-10-29T22:49:50Z
Fixes for issue #147 Multiple "Re:" in subject.

- - - - -
45d5f1f7 by Barry Warsaw at 2015-10-29T22:51:28Z
Collapse multiple ``Re:`` in Subject headers.  Given by Mark Sapiro.
(Closes: #147)

- - - - -
68a1f2b8 by Barry Warsaw at 2015-10-29T23:03:32Z
Collapse multiple ``Re:`` in Subject headers.  Given by Mark Sapiro.
(Closes: #147)

- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/handlers/docs/subject-munging.rst
- src/mailman/handlers/subject_prefix.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -47,6 +47,8 @@ Bugs
  * Fix the logging of moderation reasons.  Given by Aurélien Bompard.  Also,
    update the postauth.txt and postheld.txt templates to not include the bogus
    URLs, and to include the translated moderation reasons.
+ * Collapse multiple ``Re:`` in Subject headers.  Given by Mark Sapiro.
+   (Closes: #147)
 
 
 3.0.0 -- "Show Don't Tell"


=====================================
src/mailman/handlers/docs/subject-munging.rst
=====================================
--- a/src/mailman/handlers/docs/subject-munging.rst
+++ b/src/mailman/handlers/docs/subject-munging.rst
@@ -83,6 +83,20 @@ where it will stay.
     >>> print(msg['subject'])
     [XTest] Re: Something important
 
+Sometimes the incoming ``Subject`` header has a pathological sequence of
+``Re:`` like markers. These should all be collapsed up to the first non-``Re:``
+marker.
+
+    >>> msg = message_from_string("""\
+    ... From: aper...@example.com
+    ... Subject: [XTest] Re: RE : Re: Re: Re: Re: Re: Something important
+    ...
+    ... A message of great import.
+    ... """)
+    >>> process(mlist, msg, {})
+    >>> print(msg['subject'])
+    [XTest] Re: Something important
+
 
 Internationalized headers
 =========================
@@ -207,10 +221,7 @@ And again, with an RFC 2047 encoded header.
     ...
     ... """)
     >>> process(mlist, msg, {})
-
-..
- # XXX This one does not appear to work the same way as
- # test_subject_munging_prefix_crooked() in the old Python-based tests.  I need
- # to get Tokio to look at this.
- #    >>> print(msg['subject'])
- #    [XTest] =?iso-2022-jp?b?IBskQiVhITwlayVeJXMbKEI=?=
+    >>> print(msg['subject'].encode())
+    [XTest] =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
+    >>> print(msg['subject'])
+    [XTest]  メールマン


=====================================
src/mailman/handlers/subject_prefix.py
=====================================
--- a/src/mailman/handlers/subject_prefix.py
+++ b/src/mailman/handlers/subject_prefix.py
@@ -30,7 +30,7 @@ from mailman.interfaces.handler import IHandler
 from zope.interface import implementer
 
 
-RE_PATTERN = '((RE|AW|SV|VS)(\[\d+\])?:\s*)+'
+RE_PATTERN = '\s*((RE|AW|SV|VS)(\[\d+\])?\s*:\s*)+'
 ASCII_CHARSETS = (None, 'ascii', 'us-ascii')
 EMPTYSTRING = ''
 
@@ -43,12 +43,6 @@ 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())
-    rematch = re.match(RE_PATTERN, subject_text, re.I)
-    if rematch:
-        subject_text = subject_text[rematch.end():]
-        recolon = 'Re: '
-    else:
-        recolon = ''
     # At this point, the subject may become null if someone posted mail
     # with "Subject: [subject prefix]".
     if subject_text.strip() == '':
@@ -57,6 +51,12 @@ def ascii_header(mlist, msgdata, subject, prefix, 
prefix_pattern, ws):
     else:
         subject_text = re.sub(prefix_pattern, '', subject_text)
     msgdata['stripped_subject'] = subject_text
+    rematch = re.match(RE_PATTERN, subject_text, re.I)
+    if rematch:
+        subject_text = subject_text[rematch.end():]
+        recolon = 'Re: '
+    else:
+        recolon = ''
     lines = subject_text.splitlines()
     first_line = [lines[0]]
     if recolon:
@@ -77,12 +77,6 @@ def all_same_charset(mlist, msgdata, subject, prefix, 
prefix_pattern, ws):
         if charset != list_charset:
             return None
     subject_text = EMPTYSTRING.join(chunks)
-    rematch = re.match(RE_PATTERN, subject_text, re.I)
-    if rematch:
-        subject_text = subject_text[rematch.end():]
-        recolon = 'Re: '
-    else:
-        recolon = ''
     # At this point, the subject may become null if someone posted mail
     # with "Subject: [subject prefix]".
     if subject_text.strip() == '':
@@ -91,6 +85,12 @@ def all_same_charset(mlist, msgdata, subject, prefix, 
prefix_pattern, ws):
     else:
         subject_text = re.sub(prefix_pattern, '', subject_text)
     msgdata['stripped_subject'] = subject_text
+    rematch = re.match(RE_PATTERN, subject_text, re.I)
+    if rematch:
+        subject_text = subject_text[rematch.end():]
+        recolon = 'Re: '
+    else:
+        recolon = ''
     lines = subject_text.splitlines()
     first_line = [lines[0]]
     if recolon:



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/7adc92c7892b3565212c3beb683478e5c7f06b06...68a1f2b869225b67216424ed91d412a2c33c9872
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to