[Python-bugs-list] [ python-Bugs-602029 ] smtplib mishandles empty sender

noreply@sourceforge.net noreply@sourceforge.net
Thu, 29 Aug 2002 11:53:50 -0700


Bugs item #602029, was opened at 2002-08-29 14:53
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=602029&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Ward (gward)
Assigned to: Nobody/Anonymous (nobody)
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]


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=602029&group_id=5470