I've been making some modifications to Mailman to support dynamic sublists (http://javamlm.mills.edu).  I'm still rather new with Python and have a question about modifying fields (dictionary elements) of the msg data structure.  Specifically, I added the following code to change the message's "To" field at the end of CookHeaders.py:

1    if msgdata.get('dlist'):
2        threadID = msgdata['thread_id']
3        syslog('info', "threadID = %d", threadID)
4        to_line =  '%s-%d@%s' % (mlist.real_name.lower(),
                                  threadID,
                                  mlist.host_name)
5        syslog('info', "to_line = %s", to_line)
6        del msg['To']
7        msg['To'] = to_line
8        syslog('info', "Set msg['To'] to '%s'", msg['To'])

This correctly changes the "To" field of the message from etest-new@hostname to etest-<threadID>@hostname, as shown by the log:
Mar 18 13:29:55 2002 (4600) threadID = 19
Mar 18 13:29:55 2002 (4600) to_line = [EMAIL PROTECTED]
Mar 18 13:29:55 2002 (4600) Set msg['To'] to '[EMAIL PROTECTED]'

Similarly, the resulting email message that is sent has the new 'To' field.

The problem is I don't see why line 6 above is necessary.  When I comment it out, however, I get the incongruous logfile entry:
Mar 18 13:36:04 2002 (4640) threadID = 20
Mar 18 13:36:04 2002 (4640) to_line = [EMAIL PROTECTED]
Mar 18 13:36:04 2002 (4640) Set msg['To'] to '[EMAIL PROTECTED]'

as though line 7 had never been executed.  The final email message contains two "To" headers, one with "etest-new" and one with "etest-<threadID>".  It's not clear to me why the original value is preserved instead of overwritten.   Could someone let me know what I'm missing about dictionaries or the email class?

Thank you.

Ellen Spertus

Reply via email to