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.

classification
Title: smtplib mishandles empty sender
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: gward, rhettinger
Priority: normal Keywords:

Created on 2002-08-29 18:53 by gward, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (2)
msg12193 - (view) Author: Greg Ward (gward) (Python committer) Date: 2002-08-29 18:53
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]
msg12194 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-09-05 01:20
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.
History
Date User Action Args
2022-04-10 16:05:37adminsetgithub: 37106
2002-08-29 18:53:50gwardcreate