homepage

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 <1294263603.86.0.308955870327.issue10839@psf.upfronthosting.co.za>
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 = ["one@example.com", "two@example.com", "three@example.com", "four@example.com"]
 
for d in dest:
 msg["From"] = "myself@example.com"
 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: myself@example.com
To: one@example.com
subject: just a test
From: myself@example.com
To: two@example.com
subject: just a test
From: myself@example.com
To: three@example.com
subject: just a test
From: myself@example.com
To: four@example.com
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: <1294263603.86.0.308955870327.issue10839@psf.upfronthosting.co.za>
2011年01月05日 21:40:02adrien-saladinlinkissue10839 messages
2011年01月05日 21:40:02adrien-saladincreate

AltStyle によって変換されたページ (->オリジナル) /