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
|
===============
The news runner
===============
The news runner is the queue runner that gateways mailing list messages to an
NNTP newsgroup. One of the most important things this runner does is prepare
the message for Usenet (yes, I know that NNTP is not Usenet, but this runner
was originally written to gate to Usenet, which has its own rules).
>>> mlist = create_list('_xtest@example.com')
>>> mlist.linked_newsgroup = 'comp.lang.python'
Some NNTP servers such as INN reject messages containing a set of prohibited
headers, so one of the things that the news runner does is remove these
prohibited headers.
::
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: _xtest@example.com
... NNTP-Posting-Host: news.example.com
... NNTP-Posting-Date: today
... X-Trace: blah blah
... X-Complaints-To: abuse@dom.ain
... Xref: blah blah
... Xref: blah blah
... Date-Received: yesterday
... Posted: tomorrow
... Posting-Version: 99.99
... Relay-Version: 88.88
... Received: blah blah
...
... A message
... """)
>>> msgdata = {}
>>> from mailman.queue.news import prepare_message
>>> prepare_message(mlist, msg, msgdata)
>>> msgdata['prepped']
True
>>> print msg.as_string()
From: aperson@example.com
To: _xtest@example.com
Newsgroups: comp.lang.python
Message-ID: ...
Lines: 1
<BLANKLINE>
A message
<BLANKLINE>
Some NNTP servers will reject messages where certain headers are duplicated,
so the news runner must collapse or move these duplicate headers to an
``X-Original-*`` header that the news server doesn't care about.
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: _xtest@example.com
... To: two@example.com
... Cc: three@example.com
... Cc: four@example.com
... Cc: five@example.com
... Content-Transfer-Encoding: yes
... Content-Transfer-Encoding: no
... Content-Transfer-Encoding: maybe
...
... A message
... """)
>>> msgdata = {}
>>> prepare_message(mlist, msg, msgdata)
>>> msgdata['prepped']
True
>>> print msg.as_string()
From: aperson@example.com
Newsgroups: comp.lang.python
Message-ID: ...
Lines: 1
To: _xtest@example.com
X-Original-To: two@example.com
CC: three@example.com
X-Original-CC: four@example.com
X-Original-CC: five@example.com
Content-Transfer-Encoding: yes
X-Original-Content-Transfer-Encoding: no
X-Original-Content-Transfer-Encoding: maybe
<BLANKLINE>
A message
<BLANKLINE>
But if no headers are duplicated, then the news runner doesn't need to modify
the message.
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: _xtest@example.com
... Cc: someother@example.com
... Content-Transfer-Encoding: yes
...
... A message
... """)
>>> msgdata = {}
>>> prepare_message(mlist, msg, msgdata)
>>> msgdata['prepped']
True
>>> print msg.as_string()
From: aperson@example.com
To: _xtest@example.com
Cc: someother@example.com
Content-Transfer-Encoding: yes
Newsgroups: comp.lang.python
Message-ID: ...
Lines: 1
<BLANKLINE>
A message
<BLANKLINE>
Newsgroup moderation
====================
When the newsgroup is moderated, an ``Approved:`` header with the list's
posting address is added for the benefit of the Usenet system.
::
>>> from mailman.interfaces.nntp import NewsModeration
>>> mlist.news_moderation = NewsModeration.open_moderated
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: _xtest@example.com
... Approved: this gets deleted
...
... """)
>>> prepare_message(mlist, msg, {})
>>> print msg['approved']
_xtest@example.com
>>> mlist.news_moderation = NewsModeration.moderated
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: _xtest@example.com
... Approved: this gets deleted
...
... """)
>>> prepare_message(mlist, msg, {})
>>> print msg['approved']
_xtest@example.com
But if the newsgroup is not moderated, the ``Approved:`` header is not changed.
>>> mlist.news_moderation = NewsModeration.none
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: _xtest@example.com
... Approved: this doesn't get deleted
...
... """)
>>> prepare_message(mlist, msg, {})
>>> msg['approved']
u"this doesn't get deleted"
XXX More of the NewsRunner should be tested.
|