summaryrefslogtreecommitdiff
path: root/Mailman/Handlers/CookHeaders.py
diff options
context:
space:
mode:
authorbwarsaw2002-11-19 00:40:32 +0000
committerbwarsaw2002-11-19 00:40:32 +0000
commitbbd823bd3623071a574b7fec36e4ea5757fd5d11 (patch)
tree33762ef7b129252005b6c54a64651e04687700d9 /Mailman/Handlers/CookHeaders.py
parent3520ab50fb6b3c05d8e1b110274e58d289fe3c7c (diff)
downloadmailman-bbd823bd3623071a574b7fec36e4ea5757fd5d11.tar.gz
mailman-bbd823bd3623071a574b7fec36e4ea5757fd5d11.tar.zst
mailman-bbd823bd3623071a574b7fec36e4ea5757fd5d11.zip
Diffstat (limited to 'Mailman/Handlers/CookHeaders.py')
-rw-r--r--Mailman/Handlers/CookHeaders.py56
1 files changed, 33 insertions, 23 deletions
diff --git a/Mailman/Handlers/CookHeaders.py b/Mailman/Handlers/CookHeaders.py
index 400230dc2..55dbd1d12 100644
--- a/Mailman/Handlers/CookHeaders.py
+++ b/Mailman/Handlers/CookHeaders.py
@@ -39,6 +39,23 @@ MAXLINELEN = 78
def _isunicode(s):
return isinstance(s, UnicodeType)
+def uheader(mlist, s, header_name=None):
+ # Get the charset to encode the string in. If this is us-ascii, we'll use
+ # iso-8859-1 instead, just to get a little extra coverage, and because the
+ # Header class tries us-ascii first anyway.
+ charset = Utils.GetCharSet(mlist.preferred_language)
+ if charset == 'us-ascii':
+ charset = 'iso-8859-1'
+ charset = Charset(charset)
+ # Convert the string to unicode so Header will do the 3-charset encoding.
+ # If s is a byte string and there are funky characters in it that don't
+ # match the charset, we might as well replace them now.
+ if not _isunicode(s):
+ codec = charset.input_codec or 'ascii'
+ s = unicode(s, codec, 'replace')
+ # We purposefully leave no space b/w prefix and subject!
+ return Header(s, charset, header_name=header_name)
+
def process(mlist, msg, msgdata):
@@ -147,17 +164,23 @@ def process(mlist, msg, msgdata):
# Pre-calculate
listid = '<%s.%s>' % (mlist.internal_name(), mlist.host_name)
if mlist.description:
- listid = mlist.description + ' ' + listid
- requestaddr = mlist.GetRequestEmail()
- subfieldfmt = '<%s>, <mailto:%s?subject=%ssubscribe>'
- listinfo = mlist.GetScriptURL('listinfo', absolute=1)
- # We always add a List-ID: header. For internally crafted messages, we
+ # Make sure description is properly i18n'd
+ listid_h = uheader(mlist, mlist.description, 'List-Id')
+ listid_h.append(' ' + listid, 'us-ascii')
+ else:
+ # For wrapping
+ listid_h = Header(listid, 'us-ascii', header_name='List-Id')
+ # We always add a List-ID: header.
+ del msg['list-id']
+ msg['List-Id'] = listid_h
+ # For internally crafted messages, we
# also add a (nonstandard), "X-List-Administrivia: yes" header. For all
# others (i.e. those coming from list posts), we adda a bunch of other RFC
# 2369 headers.
- headers = {
- 'List-Id' : listid,
- }
+ requestaddr = mlist.GetRequestEmail()
+ subfieldfmt = '<%s>, <mailto:%s?subject=%ssubscribe>'
+ listinfo = mlist.GetScriptURL('listinfo', absolute=1)
+ headers = {}
if msgdata.get('reduced_list_headers'):
headers['X-List-Administrivia'] = 'yes'
else:
@@ -209,21 +232,8 @@ def prefix_subject(mlist, msg, msgdata):
del msg['subject']
if not subject:
subject = _('(no subject)')
- # Get the charset to encode the prefix in. If this is us-ascii, we'll use
- # iso-8859-1 instead, just to get a little extra coverage, and because the
- # Header class tries us-ascii first anyway.
- charset = Utils.GetCharSet(mlist.preferred_language)
- if charset == 'us-ascii':
- charset = 'iso-8859-1'
- charset = Charset(charset)
- # Convert the prefix to unicode so Header will do the 3-charset encoding.
- # If prefix is a byte string and there are funky characters in it that
- # don't match the charset, we might as well replace them now.
- if not _isunicode(prefix):
- codec = charset.input_codec or 'ascii'
- prefix = unicode(prefix, codec, 'replace')
- # We purposefully leave no space b/w prefix and subject!
- h = Header(prefix, charset, header_name='Subject')
+ # Get the header as a Header instance, with proper unicode conversion
+ h = uheader(mlist, prefix, 'Subject')
for s, c in headerbits:
# Once again, convert the string to unicode.
if c is None: