This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author adrien-saladin
Recipients adrien-saladin
Date 2011-01-05.21:40:02
SpamBayes Score 0.0016034181
Marked as misclassified No
Message-id <[email protected]>
In-reply-to
Content
Hi,

The following script shows two problems with email.mime.text.MIMEText:

- first the use of msg['To'] seems confusing because its dictionnary-like syntax made me think it acts as a "set or replace", but in fact is working as a stream operation
- second this behavior allows for the same field to be repeated several times in a header which is discouraged in rfc-822 and forbidden for many fields in rfc-2822. 



#########################################"
from email.mime.text import MIMEText

msg = MIMEText("""Hello World""")

dest = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
 
for d in dest:
    msg["From"] = "[email protected]"
    msg["To"] = d
    msg["subject"] = "just a test"
    print (msg)
    # + send the buggy mail...
###################################

the last sent mail will looks like this: 

---------------------
Hello World
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
From: [email protected]
To: [email protected]
subject: just a test
From: [email protected]
To: [email protected]
subject: just a test
From: [email protected]
To: [email protected]
subject: just a test
From: [email protected]
To: [email protected]
subject: just a test

Hello World
----------------------


I see some possible modifications:

* make the [] operator work as a dictionnary-like syntax. So calling msg['To'] multiple times would simply replace the previous 'To:' field. The additional constraint is that some fields like 'comments' or 'keywords' can be repeated

* (or) throw an error when some fields are repeated in this list: 
  from,  sender, reply-to, to, cc, bcc, message-id, in-reply-to, references, subject
History
Date User Action Args
2011-01-05 21:40:03adrien-saladinsetrecipients: + adrien-saladin
2011-01-05 21:40:03adrien-saladinsetmessageid: <[email protected]>
2011-01-05 21:40:02adrien-saladinlinkissue10839 messages
2011-01-05 21:40:02adrien-saladincreate