~barry/mailman/lp1423756

« back to all changes in this revision

Viewing changes to src/mailman/handlers/docs/subject-munging.rst

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
===============
2
 
Subject munging
3
 
===============
 
1
================
 
2
Subject prefixes
 
3
================
4
4
 
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.
10
8
 
11
9
    >>> mlist = create_list('test@example.com')
12
10
 
 
11
The default list style gives the mailing list a default prefix.
 
12
 
 
13
    >>> print(mlist.subject_prefix)
 
14
    [Test]
 
15
 
 
16
This can be changed to anything, but typically ends with a trailing space.
 
17
 
 
18
    >>> mlist.subject_prefix = '[XTest] '
 
19
    >>> process = config.handlers['subject-prefix'].process
 
20
 
 
21
 
 
22
No Subject
 
23
==========
 
24
 
 
25
If the original message has no ``Subject``, then a canned one is used.
 
26
 
 
27
    >>> msg = message_from_string("""\
 
28
    ... From: aperson@example.com
 
29
    ...
 
30
    ... A message of great import.
 
31
    ... """)
 
32
    >>> process(mlist, msg, {})
 
33
    >>> print(msg['subject'])
 
34
    [XTest] (no subject)
 
35
 
13
36
 
14
37
Inserting a prefix
15
38
==================
16
39
 
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.
21
 
::
22
 
 
23
 
    >>> mlist.subject_prefix = '[XTest] '
24
 
    >>> mlist.preferred_language = 'en'
25
 
    >>> msg = message_from_string("""\
26
 
    ... From: aperson@example.com
27
 
    ...
28
 
    ... A message of great import.
29
 
    ... """)
30
 
    >>> msgdata = {}
31
 
 
32
 
    >>> from mailman.handlers.cook_headers import process
33
 
    >>> process(mlist, msg, msgdata)
34
 
 
35
 
The original subject header is stored in the message metadata.
36
 
 
37
 
    >>> msgdata['original_subject']
38
 
    u''
39
 
    >>> print(msg['subject'])
40
 
    [XTest] (no subject)
41
 
 
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.
44
42
 
50
48
    ... """)
51
49
    >>> msgdata = {}
52
50
    >>> process(mlist, msg, msgdata)
 
51
    >>> print(msg['subject'])
 
52
    [XTest] Something important
 
53
 
 
54
The original ``Subject`` is available in the metadata.
 
55
 
53
56
    >>> print(msgdata['original_subject'])
54
57
    Something important
55
 
    >>> print(msg['subject'])
56
 
    [XTest] Something important
57
 
 
58
 
``Subject`` headers are not munged for digest messages.
59
 
    
60
 
    >>> msg = message_from_string("""\
61
 
    ... From: aperson@example.com
62
 
    ... Subject: Something important
63
 
    ...
64
 
    ... A message of great import.
65
 
    ... """)
66
 
    >>> process(mlist, msg, dict(isdigest=True))
67
 
    >>> print(msg['subject'])
68
 
    Something important
69
 
 
70
 
Nor are they munged for *fast tracked* messages, which are generally defined
71
 
as messages that Mailman crafts internally.
72
 
 
73
 
    >>> msg = message_from_string("""\
74
 
    ... From: aperson@example.com
75
 
    ... Subject: Something important
76
 
    ...
77
 
    ... A message of great import.
78
 
    ... """)
79
 
    >>> process(mlist, msg, dict(_fasttrack=True))
80
 
    >>> print(msg['subject'])
81
 
    Something important
82
58
 
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
96
72
 
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.
 
74
where it will stay.
100
75
 
101
76
    >>> msg = message_from_string("""\
102
77
    ... From: aperson@example.com
122
97
    ...
123
98
    ... """)
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']))
 
103
    [XTest] メールマン
129
104
 
130
105
 
131
106
Prefix numbers
178
153
    ...
179
154
    ... """)
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'])
 
159
    [XTest 456] メールマン
185
160
 
186
161
Even more fun is when the internationalized ``Subject`` header already has a
187
162
prefix, possibly with a different posting number.
191
166
    ...
192
167
    ... """)
193
168
    >>> process(mlist, msg, {})
194
 
    >>> print(msg['subject'])
 
169
    >>> print(msg['subject'].encode())
195
170
    [XTest 456] Re: =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
196
 
 
197
 
..
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: メールマン
201
173
 
202
174
As before, old style subject prefixes are re-ordered.
203
175
 
206
178
    ...
207
179
    ... """)
208
180
    >>> process(mlist, msg, {})
209
 
    >>> print(msg['subject'])
 
181
    >>> print(msg['subject'].encode())
210
182
    [XTest 456] Re:
211
183
      =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=
212
 
 
213
 
..
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: メールマン
217
186
 
218
187
 
219
188
In this test case, we get an extra space between the prefix and the original