Update of /cvsroot/mailman/mailman/Mailman/Handlers
In directory usw-pr-cvs1:/tmp/cvs-serv24489/Mailman/Handlers
Modified Files:
CookHeaders.py
Log Message:
process(), prefix_subject(): Ben Gertzfield's patch (refactored by
Barry) which correctly checks for the prefix in encoded Subject:
headers.
Index: CookHeaders.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Handlers/CookHeaders.py,v
retrieving revision 2.12
retrieving revision 2.13
diff -C2 -d -r2.12 -r2.13
*** CookHeaders.py 8 Apr 2002 04:28:41 -0000 2.12
--- CookHeaders.py 8 Apr 2002 05:14:52 -0000 2.13
***************
*** 20,23 ****
--- 20,25 ----
import re
+ from email.Charset import Charset
+ from email.Header import Header, decode_header
import email.Utils
***************
*** 29,32 ****
--- 31,35 ----
CONTINUATION = ',\n\t'
COMMASPACE = ', '
+ MAXLINELEN = 78
***************
*** 42,61 ****
# but we need it for the Acknowledge module later.
msgdata['original_sender'] = msg.get_sender()
- subject = msg['subject']
# VirginRunner sets _fasttrack for internally crafted messages.
fasttrack = msgdata.get('_fasttrack')
if not msgdata.get('isdigest') and not fasttrack:
! # Add the subject prefix unless the message is a digest or is being
! # fast tracked (e.g. internally crafted, delivered to a single user
! # such as the list admin). We assume all digests have an appropriate
! # subject header added by the ToDigest module.
! prefix = mlist.subject_prefix
! # We purposefully leave no space b/w prefix and subject!
! if not subject:
! del msg['subject']
! msg['Subject'] = prefix + _('(no subject)')
! elif prefix and not re.search(re.escape(prefix), subject, re.I):
! del msg['subject']
! msg['Subject'] = prefix + subject
# Mark message so we know we've been here, but leave any existing
# X-BeenThere's intact.
--- 45,52 ----
# but we need it for the Acknowledge module later.
msgdata['original_sender'] = msg.get_sender()
# VirginRunner sets _fasttrack for internally crafted messages.
fasttrack = msgdata.get('_fasttrack')
if not msgdata.get('isdigest') and not fasttrack:
! prefix_subject(mlist, msg, msgdata)
# Mark message so we know we've been here, but leave any existing
# X-BeenThere's intact.
***************
*** 162,163 ****
--- 153,194 ----
v = CONTINUATION.join(v.split(', '))
msg[h] = v
+
+
+
+ def prefix_subject(mlist, msg, msgdata):
+ # Add the subject prefix unless the message is a digest or is being fast
+ # tracked (e.g. internally crafted, delivered to a single user such as the
+ # list admin).
+ prefix = mlist.subject_prefix
+ subject = msg['subject']
+ # The header may be multilingual; decode it from base64/quopri and search
+ # each chunk for the prefix.
+ has_prefix = 0
+ if prefix and subject:
+ pattern = re.escape(prefix.strip())
+ for decodedsubj, charset in decode_header(subject):
+ if re.search(pattern, decodedsubj, re.IGNORECASE):
+ has_prefix = 1
+ charset = Charset(Utils.GetCharSet(mlist.preferred_language))
+ # We purposefully leave no space b/w prefix and subject!
+ if not subject:
+ del msg['subject']
+ msg['Subject'] = Header(prefix + _('(no subject)'),
+ charset,
+ header_name='Subject')
+ elif prefix and not has_prefix:
+ del msg['subject']
+ # We'll encode the new prefix (just in case) but leave the old subject
+ # alone, in case it was already encoded.
+ new_subject = Header(prefix, charset, header_name='Subject').encode()
+ # If we go over 76 characters with the prefix, just put the old
+ # subject on its own line.
+ first = subject.split('\n')[0]
+ if len(new_subject) + len(first) + 1 >= MAXLINELEN - len('Subject: '):
+ new_subject += '\n '
+ # We might have to add a space because the prefix and old subject may
+ # both be MIME-encoded, losing the space at the end of the prefix.
+ elif new_subject[-1] <> ' ':
+ new_subject += ' '
+ new_subject += subject
+ msg['Subject'] = new_subject
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/mailman-checkins