[Mailman-Developers] Modifications to msg

Ellen Spertus spertus@mills.edu
Mon, 18 Mar 2002 13:43:57 -0800


--=====================_169733023==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

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 = etest-19@javamlm.mills.edu
Mar 18 13:29:55 2002 (4600) Set msg['To'] to 'etest-19@javamlm.mills.edu'

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 = etest-20@javamlm.mills.edu
Mar 18 13:36:04 2002 (4640) Set msg['To'] to 'etest-new@javamlm.mills.edu'

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

--=====================_169733023==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
I've been making some modifications to Mailman to support dynamic
sublists
(<a href="http://javamlm.mills.edu/" eudora="autourl">http://javamlm.mills.edu</a>).&nbsp;
I'm still rather new with Python and have a question about modifying
fields (dictionary elements) of the msg data structure.&nbsp;
Specifically, I added the following code to change the message's
&quot;To&quot; field at the end of CookHeaders.py:<br><br>
1&nbsp;&nbsp;&nbsp; if msgdata.get('dlist'):<br>
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; threadID =
msgdata['thread_id']<br>
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; syslog('info', &quot;threadID
= %d&quot;, threadID)<br>
4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to_line =&nbsp; '%s-%d@%s' %
(mlist.real_name.lower(),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
threadID,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mlist.host_name)<br>
5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; syslog('info', &quot;to_line
= %s&quot;, to_line)<br>
6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; del msg['To']<br>
7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg['To'] = to_line<br>
8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; syslog('info', &quot;Set
msg['To'] to '%s'&quot;, msg['To'])<br><br>
This correctly changes the &quot;To&quot; field of the message from
etest-new@hostname to etest-&lt;threadID&gt;@hostname, as shown by the
log:<br>

<dl>
<dd>Mar 18 13:29:55 2002 (4600) threadID = 19
<dd>Mar 18 13:29:55 2002 (4600) to_line = etest-19@javamlm.mills.edu
<dd>Mar 18 13:29:55 2002 (4600) Set msg['To'] to
'etest-19@javamlm.mills.edu'<br><br>

</dl>Similarly, the resulting email message that is sent has the new 'To'
field.<br><br>
The problem is I don't see why line 6 above is necessary.&nbsp; When I
comment it out, however, I get the incongruous logfile entry:<br>

<dl>
<dd>Mar 18 13:36:04 2002 (4640) threadID = 20
<dd>Mar 18 13:36:04 2002 (4640) to_line = etest-20@javamlm.mills.edu
<dd>Mar 18 13:36:04 2002 (4640) Set msg['To'] to
'etest-new@javamlm.mills.edu'<br><br>

</dl>as though line 7 had never been executed.&nbsp; The final email
message contains two &quot;To&quot; headers, one with
&quot;etest-new&quot; and one with
&quot;etest-&lt;threadID&gt;&quot;.&nbsp; It's not clear to me why the
original value is preserved instead of overwritten.&nbsp;&nbsp; Could
someone let me know what I'm missing about dictionaries or the email
class?<br><br>
Thank you.<br><br>
Ellen Spertus<br>
</html>

--=====================_169733023==_.ALT--