Message125473
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 |
|
| Date |
User |
Action |
Args |
| 2011-01-05 21:40:03 | adrien-saladin | set | recipients:
+ adrien-saladin |
| 2011-01-05 21:40:03 | adrien-saladin | set | messageid: <[email protected]> |
| 2011-01-05 21:40:02 | adrien-saladin | link | issue10839 messages |
| 2011-01-05 21:40:02 | adrien-saladin | create | |
|