diff options
| -rw-r--r-- | Mailman/Handlers/Decorate.py | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/Mailman/Handlers/Decorate.py b/Mailman/Handlers/Decorate.py index b2e957161..e8ec3488c 100644 --- a/Mailman/Handlers/Decorate.py +++ b/Mailman/Handlers/Decorate.py @@ -1,4 +1,4 @@ -# Copyright (C) 1998,1999,2000 by the Free Software Foundation, Inc. +# Copyright (C) 1998,1999,2000,2001 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,30 +17,47 @@ """Decorate a message by sticking the header and footer around it. """ +import mimelib.Text + from Mailman import mm_cfg -from Mailman import Utils +from Mailman.SafeDict import SafeDict from Mailman.Logging.Syslog import syslog def process(mlist, msg, msgdata): if msgdata.get('isdigest'): - # Digests already have their own header and footers attached. + # Digests already have their own header and footer return - d = Utils.SafeDict(mlist.__dict__) + 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) + payload = msg.get_payload() + payload.insert(0, mimehdr) + payload.append(mimeftr) + else: + payload = header + msg.get_payload() + footer + msg.set_payload(payload) + + + +def decorate(mlist, template, what): + # `what' is just a descriptive phrase + d = SafeDict(mlist.__dict__) + # Certain attributes are sensitive + del d['password'] + del d['passwords'] d['cgiext'] = mm_cfg.CGIEXT - # interpolate into the header - try: - header = (mlist.msg_header % d).replace('\r\n', '\n') - except ValueError, e: - syslog('error', 'Exception while calculating message header:\n%s' % e) - header = '[INVALID HEADER]' + # Interpolate into the template try: - footer = (mlist.msg_footer % d).replace('\r\n', '\n') + text = (template % d).replace('\r\n', '\n') except ValueError, e: - syslog('error', 'Exception while calculating message footer:\n%s' % e) - footer = '[INVALID FOOTER]' - msg.body = header + msg.body + footer - # Mark the message as dirty so that its text will be forced to disk next - # time it's queued. - msgdata['_dirty'] = 1 + syslog('error', 'Exception while calculating %s:\n%s' % + (what, e)) + text = '[INVALID %s]' % what.upper() + return text |
