5
Messages that flow through the global pipeline get their headers *cooked*,
6
which basically means that their headers go through several mostly unrelated
7
transformations. Some headers get added, others get changed. Some of these
8
changes depend on mailing list settings and others depend on how the message
9
is getting sent through the system. We'll take things one-by-one.
5
Mailing lists can define a *subject prefix* which gets added to the front of
6
any ``Subject`` text. This can be used to quickly identify which mailing list
7
the message was posted to.
11
9
>>> mlist = create_list('test@example.com')
11
The default list style gives the mailing list a default prefix.
13
>>> print(mlist.subject_prefix)
16
This can be changed to anything, but typically ends with a trailing space.
18
>>> mlist.subject_prefix = '[XTest] '
19
>>> process = config.handlers['subject-prefix'].process
25
If the original message has no ``Subject``, then a canned one is used.
27
>>> msg = message_from_string("""\
28
... From: aperson@example.com
30
... A message of great import.
32
>>> process(mlist, msg, {})
33
>>> print(msg['subject'])
17
Another thing header cooking does is *munge* the ``Subject`` header by
18
inserting the subject prefix for the list at the front. If there's no subject
19
header in the original message, Mailman uses a canned default. In order to do
20
subject munging, a mailing list must have a preferred language.
23
>>> mlist.subject_prefix = '[XTest] '
24
>>> mlist.preferred_language = 'en'
25
>>> msg = message_from_string("""\
26
... From: aperson@example.com
28
... A message of great import.
32
>>> from mailman.handlers.cook_headers import process
33
>>> process(mlist, msg, msgdata)
35
The original subject header is stored in the message metadata.
37
>>> msgdata['original_subject']
39
>>> print(msg['subject'])
42
40
If the original message had a ``Subject`` header, then the prefix is inserted
43
41
at the beginning of the header's value.
52
50
>>> process(mlist, msg, msgdata)
51
>>> print(msg['subject'])
52
[XTest] Something important
54
The original ``Subject`` is available in the metadata.
53
56
>>> print(msgdata['original_subject'])
54
57
Something important
55
>>> print(msg['subject'])
56
[XTest] Something important
58
``Subject`` headers are not munged for digest messages.
60
>>> msg = message_from_string("""\
61
... From: aperson@example.com
62
... Subject: Something important
64
... A message of great import.
66
>>> process(mlist, msg, dict(isdigest=True))
67
>>> print(msg['subject'])
70
Nor are they munged for *fast tracked* messages, which are generally defined
71
as messages that Mailman crafts internally.
73
>>> msg = message_from_string("""\
74
... From: aperson@example.com
75
... Subject: Something important
77
... A message of great import.
79
>>> process(mlist, msg, dict(_fasttrack=True))
80
>>> print(msg['subject'])
83
59
If a ``Subject`` header already has a prefix, usually following a ``Re:``
84
60
marker, another one will not be added but the prefix will be moved to the
95
71
[XTest] Re: Something important
97
73
If the ``Subject`` header has a prefix at the front of the header text, that's
98
where it will stay. This is called *new style* prefixing and is the only
99
option available in Mailman 3.
101
76
>>> msg = message_from_string("""\
102
77
... From: aperson@example.com
124
99
>>> process(mlist, msg, {})
125
>>> print(msg['subject'])
100
>>> print(msg['subject'].encode())
126
101
[XTest] =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
127
>>> unicode(msg['subject'])
128
u'[XTest] \u30e1\u30fc\u30eb\u30de\u30f3'
102
>>> print(str(msg['subject']))
180
155
>>> process(mlist, msg, {})
181
>>> print(msg['subject'])
156
>>> print(msg['subject'].encode())
182
157
[XTest 456] =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
183
>>> unicode(msg['subject'])
184
u'[XTest 456] \u30e1\u30fc\u30eb\u30de\u30f3'
158
>>> print(msg['subject'])
186
161
Even more fun is when the internationalized ``Subject`` header already has a
187
162
prefix, possibly with a different posting number.
193
168
>>> process(mlist, msg, {})
194
>>> print(msg['subject'])
169
>>> print(msg['subject'].encode())
195
170
[XTest 456] Re: =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
198
# XXX This requires Python email patch #1681333 to succeed.
199
# >>> unicode(msg['subject'])
200
# u'[XTest 456] Re: \u30e1\u30fc\u30eb\u30de\u30f3'
171
>>> print(msg['subject'])
172
[XTest 456] Re: メールマン
202
174
As before, old style subject prefixes are re-ordered.
208
180
>>> process(mlist, msg, {})
209
>>> print(msg['subject'])
181
>>> print(msg['subject'].encode())
211
183
=?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
214
# XXX This requires Python email patch #1681333 to succeed.
215
# >>> unicode(msg['subject'])
216
# u'[XTest 456] Re: \u30e1\u30fc\u30eb\u30de\u30f3'
184
>>> print(msg['subject'])
185
[XTest 456] Re: メールマン
219
188
In this test case, we get an extra space between the prefix and the original