[Python-bugs-list] [ python-Bugs-602029 ] smtplib mishandles empty sender
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 04 Sep 2002 18:20:46 -0700
Bugs item #602029, was opened at 2002-08-29 13:53
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=602029&group_id=5470
Category: Python Library
Group: Python 2.2
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Greg Ward (gward)
Assigned to: Raymond Hettinger (rhettinger)
Summary: smtplib mishandles empty sender
Initial Comment:
If you pass a non-empty string to SMTP.mail(), it gets it
right, ie.
smtp.mail("gward@python.net")
becomes
MAIL FROM:<gward@python.net>
But if you pass the empty string, things go badly:
smtp.mail("")
becomes
MAIL FROM:
which most SMTP servers should reject. (I only tried
one.)
The culprit appears to be the "if not m" branch in
quoteaddr(). One possible fix:
--- smtplib.py 8 Aug 2002 20:19:18 -0000 1.61
+++ smtplib.py 29 Aug 2002 18:52:42 -0000
@@ -173,11 +173,7 @@
m=rfc822.parseaddr(addr)[1]
except AttributeError:
pass
- if not m:
- #something weird here.. punt -ddm
- return addr
- else:
- return "<%s>" % m
+ return "<%s>" % m
def quotedata(data):
"""Quote data for email.
Another possible fix:
--- smtplib.py 8 Aug 2002 20:19:18 -0000 1.61
+++ smtplib.py 29 Aug 2002 18:53:28 -0000
@@ -168,6 +168,8 @@
Should be able to handle anything rfc822.parseaddr
can handle.
"""
+ if addr == "":
+ return "<>"
m=None
try:
m=rfc822.parseaddr(addr)[1]
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-09-04 20:20
Message:
Logged In: YES
user_id=80475
rfc822.parseaddr() is already finding a problem with an
empty address. The real problem in this code block is
that the return value upon failure was expected to be
None, instead of (None, None) as documented.
Fixed for Python 2.3. See smtplib.py revision 1.62.
I am reluctant to backport the error correction because it
involves a behavioral change to a possibly common case
of a blank address. Since this hasn't been a problem until
now, I'll forgo the backport.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=602029&group_id=5470