1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
===============
Cooking headers
===============
Messages that flow through the global pipeline get their headers 'cooked',
which basically means that their headers go through several mostly unrelated
transformations. Some headers get added, others get changed. Some of these
changes depend on mailing list settings and others depend on how the message
is getting sent through the system. We'll take things one-by-one.
>>> mlist = create_list('_xtest@example.com')
>>> mlist.subject_prefix = ''
>>> mlist.include_list_post_header = False
>>> mlist.archive = True
Saving the original sender
==========================
Because the original sender headers may get deleted or changed, this handler
will place the sender in the message metadata for safe keeping.
::
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... A message of great import.
... """)
>>> msgdata = {}
>>> from mailman.pipeline.cook_headers import process
>>> process(mlist, msg, msgdata)
>>> print msgdata['original_sender']
aperson@example.com
But if there was no original sender, then the empty string will be saved.
>>> msg = message_from_string("""\
... Subject: No original sender
...
... A message of great import.
... """)
>>> msgdata = {}
>>> process(mlist, msg, msgdata)
>>> print msgdata['original_sender']
<BLANKLINE>
Mailman version header
======================
Mailman will also insert an ``X-Mailman-Version`` header...
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... A message of great import.
... """)
>>> process(mlist, msg, {})
>>> from mailman.version import VERSION
>>> msg['x-mailman-version'] == VERSION
True
...but only if one doesn't already exist.
>>> msg = message_from_string("""\
... From: aperson@example.com
... X-Mailman-Version: 3000
...
... A message of great import.
... """)
>>> process(mlist, msg, {})
>>> print msg['x-mailman-version']
3000
Precedence header
=================
Mailman will insert a ``Precedence`` header, which is a de-facto standard for
telling automatic reply software (e.g. ``vacation(1)``) not to respond to this
message.
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... A message of great import.
... """)
>>> process(mlist, msg, {})
>>> print msg['precedence']
list
But Mailman will only add that header if the original message doesn't already
have one of them.
>>> msg = message_from_string("""\
... From: aperson@example.com
... Precedence: junk
...
... A message of great import.
... """)
>>> process(mlist, msg, {})
>>> print msg['precedence']
junk
RFC 2919 and 2369 headers
=========================
This is a helper function for the following section.
>>> def list_headers(msg):
... print '---start---'
... # Sort the List-* headers found in the message. We need to do
... # this because CookHeaders puts them in a dictionary which does
... # not have a guaranteed sort order.
... for header in sorted(msg.keys()):
... parts = header.lower().split('-')
... if 'list' not in parts:
... continue
... for value in msg.get_all(header):
... print '%s: %s' % (header, value)
... print '---end---'
These RFCs define headers for mailing list actions. A mailing list should
generally add these headers, but not for messages that aren't crafted for a
specific list (e.g. password reminders in Mailman 2.x).
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, dict(_nolist=True))
>>> list_headers(msg)
---start---
---end---
Some people don't like these headers because their mail readers aren't good
about hiding them. A list owner can turn these headers off.
>>> mlist.include_rfc2369_headers = False
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, {})
>>> list_headers(msg)
---start---
---end---
But normally, a list will include these headers.
>>> mlist.include_rfc2369_headers = True
>>> mlist.include_list_post_header = True
>>> mlist.preferred_language = 'en'
>>> msg = message_from_string("""\
... From: aperson@example.com
... Message-ID: <12345>
...
... """)
>>> process(mlist, msg, {})
>>> list_headers(msg)
---start---
List-Archive: <http://lists.example.com/archives/_xtest@example.com>
List-Help: <mailto:_xtest-request@example.com?subject=help>
List-Id: <_xtest.example.com>
List-Post: <mailto:_xtest@example.com>
List-Subscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-join@example.com>
List-Unsubscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-leave@example.com>
---end---
If the mailing list has a description, then it is included in the ``List-Id``
header.
>>> mlist.description = 'My test mailing list'
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, {})
>>> list_headers(msg)
---start---
List-Archive: <http://lists.example.com/archives/_xtest@example.com>
List-Help: <mailto:_xtest-request@example.com?subject=help>
List-Id: My test mailing list <_xtest.example.com>
List-Post: <mailto:_xtest@example.com>
List-Subscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-join@example.com>
List-Unsubscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-leave@example.com>
---end---
There are some circumstances when the list administrator wants to explicitly
set the ``List-ID`` header. Start by creating a new domain.
::
>>> from mailman.interfaces.domain import IDomainManager
>>> from zope.component import getUtility
>>> domain = getUtility(IDomainManager).add('mail.example.net')
>>> mlist.host_name = 'mail.example.net'
>>> process(mlist, msg, {})
>>> print msg['list-id']
My test mailing list <_xtest.example.com>
>>> mlist.list_id = '_xtest.mail.example.net'
>>> process(mlist, msg, {})
>>> print msg['list-id']
My test mailing list <_xtest.mail.example.net>
>>> mlist.host_name = 'example.com'
>>> mlist.list_id = '_xtest.example.com'
Any existing ``List-ID`` headers are removed from the original message.
>>> msg = message_from_string("""\
... From: aperson@example.com
... List-ID: <123.456.789>
...
... """)
>>> process(mlist, msg, {})
>>> sorted(msg.get_all('list-id'))
[u'My test mailing list <_xtest.example.com>']
Administrative messages crafted by Mailman will have a reduced set of headers.
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, dict(reduced_list_headers=True))
>>> list_headers(msg)
---start---
List-Help: <mailto:_xtest-request@example.com?subject=help>
List-Id: My test mailing list <_xtest.example.com>
List-Subscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-join@example.com>
List-Unsubscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-leave@example.com>
X-List-Administrivia: yes
---end---
With the normal set of ``List-*`` headers, it's still possible to suppress the
``List-Post`` header, which is reasonable for an announce only mailing list.
>>> mlist.include_list_post_header = False
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, {})
>>> list_headers(msg)
---start---
List-Archive: <http://lists.example.com/archives/_xtest@example.com>
List-Help: <mailto:_xtest-request@example.com?subject=help>
List-Id: My test mailing list <_xtest.example.com>
List-Subscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-join@example.com>
List-Unsubscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-leave@example.com>
---end---
And if the list isn't being archived, it makes no sense to add the
``List-Archive`` header either.
>>> mlist.include_list_post_header = True
>>> mlist.archive = False
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, {})
>>> list_headers(msg)
---start---
List-Help: <mailto:_xtest-request@example.com?subject=help>
List-Id: My test mailing list <_xtest.example.com>
List-Post: <mailto:_xtest@example.com>
List-Subscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-join@example.com>
List-Unsubscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-leave@example.com>
---end---
Archived-At
===========
RFC 5064 (draft) defines a new ``Archived-At`` header which contains the url to
the individual message in the archives. The stock Pipermail archiver doesn't
support this because the url can't be calculated until after the message is
archived. Because this is done by the archive runner, this information isn't
available to us now.
>>> print msg['archived-at']
None
Personalization
===============
The ``To`` field normally contains the list posting address. However when
messages are fully personalized, that header will get overwritten with the
address of the recipient. The list's posting address will be added to one of
the recipient headers so that users will be able to reply back to the list.
>>> from mailman.interfaces.mailinglist import (
... Personalization, ReplyToMunging)
>>> mlist.personalize = Personalization.full
>>> mlist.reply_goes_to_list = ReplyToMunging.no_munging
>>> msg = message_from_string("""\
... From: aperson@example.com
...
... """)
>>> process(mlist, msg, {})
>>> print msg.as_string()
From: aperson@example.com
X-BeenThere: _xtest@example.com
X-Mailman-Version: ...
Precedence: list
Cc: My test mailing list <_xtest@example.com>
List-Id: My test mailing list <_xtest.example.com>
List-Unsubscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-leave@example.com>
List-Post: <mailto:_xtest@example.com>
List-Help: <mailto:_xtest-request@example.com?subject=help>
List-Subscribe: <http://lists.example.com/listinfo/_xtest@example.com>,
<mailto:_xtest-join@example.com>
<BLANKLINE>
<BLANKLINE>
|