[New-bugs-announce] [issue10839] email module should not allow some header field repetitions

Adrien Saladin report at bugs.python.org
Wed Jan 5 22:40:03 CET 2011


New submission from Adrien Saladin <adrien.saladin at gmail.com>:

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 at example.com", "two at example.com", "three at example.com", "four at example.com"]
 
for d in dest:
    msg["From"] = "myself at 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 at example.com
To: one at example.com
subject: just a test
From: myself at example.com
To: two at example.com
subject: just a test
From: myself at example.com
To: three at example.com
subject: just a test
From: myself at example.com
To: four at 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

----------
components: Library (Lib)
messages: 125473
nosy: adrien-saladin
priority: normal
severity: normal
status: open
title: email module should not allow some header field repetitions
versions: Python 2.6, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10839>
_______________________________________


More information about the New-bugs-announce mailing list