~launchpad-pqm/mailman/2.1

« back to all changes in this revision

Viewing changes to Mailman/Handlers/Decorate.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2009-10-21 01:06:17 UTC
  • mfrom: (975.1.1 mailman.2112)
  • Revision ID: launchpad@pqm.canonical.com-20091021010617-prbs2ay6nhxx515v
[rs=flacoste] Upgrade Mailman to upstream 2.1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 1998-2007 by the Free Software Foundation, Inc.
 
1
# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
2
2
#
3
3
# This program is free software; you can redistribute it and/or
4
4
# modify it under the terms of the GNU General Public License
98
98
        # TK: Try to keep the message plain by converting the header/
99
99
        # footer/oldpayload into unicode and encode with mcset/lcset.
100
100
        # Try to decode qp/base64 also.
101
 
        uheader = unicode(header, lcset, 'ignore')
102
 
        ufooter = unicode(footer, lcset, 'ignore')
 
101
        # It is possible header/footer is already unicode if it was
 
102
        # interpolated with a unicode.
 
103
        if isinstance(header, unicode):
 
104
            uheader = header
 
105
        else:
 
106
            uheader = unicode(header, lcset, 'ignore')
 
107
        if isinstance(footer, unicode):
 
108
            ufooter = footer
 
109
        else:
 
110
            ufooter = unicode(footer, lcset, 'ignore')
103
111
        try:
104
112
            oldpayload = unicode(msg.get_payload(decode=True), mcset)
105
113
            frontsep = endsep = u''
130
138
            wrap = False
131
139
        except (LookupError, UnicodeError):
132
140
            pass
133
 
    elif msg.get_type() == 'multipart/mixed':
 
141
    elif msg.get_content_type() == 'multipart/mixed':
134
142
        # The next easiest thing to do is just prepend the header and append
135
143
        # the footer as additional subparts
136
144
        payload = msg.get_payload()
159
167
    # basis of the interior, wrapped Message.
160
168
    inner = Message()
161
169
    # Which headers to copy?  Let's just do the Content-* headers
 
170
    copied = False
162
171
    for h, v in msg.items():
163
172
        if h.lower().startswith('content-'):
164
173
            inner[h] = v
 
174
            copied = True
165
175
    inner.set_payload(msg.get_payload())
166
176
    # For completeness
167
177
    inner.set_unixfrom(msg.get_unixfrom())
171
181
    # get_content_charset isn't.  However, do make sure there is a default
172
182
    # content-type, even if the original message was not MIME.
173
183
    inner.set_default_type(msg.get_default_type())
 
184
    if not copied:
 
185
        inner['Content-Type'] = inner.get_content_type()
 
186
    if msg['mime-version'] == None:
 
187
        msg['MIME-Version'] = '1.0'
174
188
    # BAW: HACK ALERT.
175
189
    if hasattr(msg, '__version__'):
176
190
        inner.__version__ = msg.__version__
221
235
        template = Utils.to_percent(template)
222
236
    # Interpolate into the template
223
237
    try:
224
 
        text = re.sub(r' *\r?\n', r'\n', template % d)
 
238
        text = re.sub(r'(?m)(?<!^--) +(?=\n)', '',
 
239
                      re.sub(r'\r\n', r'\n', template % d))
225
240
    except (ValueError, TypeError), e:
226
241
        syslog('error', 'Exception while calculating %s:\n%s', what, e)
227
242
        what = what.upper()