diff options
| author | bwarsaw | 2001-04-03 02:51:30 +0000 |
|---|---|---|
| committer | bwarsaw | 2001-04-03 02:51:30 +0000 |
| commit | 8fcfb3d6bac017ea93c7940d3c2ef65898b92e01 (patch) | |
| tree | f2c2b04bb26c898686746f02a1b548d2cd6e3af0 | |
| parent | a70c5efc9f0cce452d45b36de737bc89ee963b6a (diff) | |
| download | mailman-8fcfb3d6bac017ea93c7940d3c2ef65898b92e01.tar.gz mailman-8fcfb3d6bac017ea93c7940d3c2ef65898b92e01.tar.zst mailman-8fcfb3d6bac017ea93c7940d3c2ef65898b92e01.zip | |
process(): Do no harm to MIME documents when adding the header and
footer. The rules now are:
- if the message is not a MIME, or is only a text/plain, then add the
header and footer the old way (concatenation).
- if the message is multipart/mixed, add the header and footer as
text/plain subparts (prepended and appended to the original
subparts).
- anything else goes through without headers and footers added. We
may elaborate on this last bit in the future.
| -rw-r--r-- | Mailman/Handlers/Decorate.py | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/Mailman/Handlers/Decorate.py b/Mailman/Handlers/Decorate.py index 29e12384d..8a2a30f9e 100644 --- a/Mailman/Handlers/Decorate.py +++ b/Mailman/Handlers/Decorate.py @@ -17,7 +17,9 @@ """Decorate a message by sticking the header and footer around it. """ -import mimelib.Text +from types import ListType + +from mimelib.Text import Text from Mailman import mm_cfg from Mailman.i18n import _ @@ -32,18 +34,34 @@ def process(mlist, msg, msgdata): return header = decorate(mlist, mlist.msg_header, _('non-digest header')) footer = decorate(mlist, mlist.msg_footer, _('non-digest footer')) - # Be MIME smart here. If the message is non-multipart, then we can just - # tack the header and footers onto the message body. But if the message - # is multipart, we want to add them as MIME subobjects. - if msg.ismultipart(): - mimehdr = mimelib.Text(header) - mimeftr = mimelib.Text(footer) + # Be MIME smart here. We only attach the header and footer by + # concatenation when the message is a non-multipart of type text/plain. + # Otherwise, if it is not a multipart, we make it a multipart, and then we + # add the header and footer as text/plain parts. + if not msg.ismultipart() and msg.gettype() in (None, 'text/plain'): + payload = header + msg.get_payload() + footer + msg.set_payload(payload) + elif msg.gettype() == 'multipart/mixed': + # The next easiest thing to do is just prepend the header and append + # the footer as additional subparts + mimehdr = Text(header) + mimeftr = Text(footer) payload = msg.get_payload() - payload.insert(0, mimehdr) + if not isinstance(payload, ListType): + payload = [payload] payload.append(mimeftr) - else: - payload = header + msg.get_payload() + footer + payload.insert(0, mimehdr) msg.set_payload(payload) + elif msg.getmaintype() <> 'multipart': + # Okay, we've got some 'image/*' or 'audio/*' -like type. For now, we + # simply refuse to add headers and footers to this message. BAW: + # still trying to decide what the Right Thing To Do is. + pass + else: + # Now we've got some multipart/* that's not a multipart/mixed. I'm + # even less sure about what to do here, so once again, let's not add + # headers or footers for now. + pass |
