Skip to content

gh-65495: Use lowercase mail from and rcpt to in smtplib.SMTP #107019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/smtplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ def mail(self, sender, options=()):
raise SMTPNotSupportedError(
'SMTPUTF8 not supported by server')
optionlist = ' ' + ' '.join(options)
self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender), optionlist))
self.putcmd("mail", "from:%s%s" % (quoteaddr(sender), optionlist))
return self.getreply()

def rcpt(self, recip, options=()):
"""SMTP 'rcpt' command -- indicates 1 recipient for this mail."""
optionlist = ''
if options and self.does_esmtp:
optionlist = ' ' + ' '.join(options)
self.putcmd("rcpt", "TO:%s%s" % (quoteaddr(recip), optionlist))
self.putcmd("rcpt", "to:%s%s" % (quoteaddr(recip), optionlist))
return self.getreply()

def data(self, msg):
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_smtplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ class SimSMTPChannel(smtpd.SMTPChannel):
def __init__(self, extra_features, *args, **kw):
self._extrafeatures = ''.join(
[ "250-{0}\r\n".format(x) for x in extra_features ])
self.all_received_lines = []
super(SimSMTPChannel, self).__init__(*args, **kw)

# AUTH related stuff. It would be nice if support for this were in smtpd.
Expand All @@ -845,6 +846,7 @@ def found_terminator(self):
self.smtp_state = self.COMMAND
self.push('%s %s' % (e.smtp_code, e.smtp_error))
return
self.all_received_lines.append(self.received_lines)
super().found_terminator()


Expand Down Expand Up @@ -1349,6 +1351,18 @@ def test_name_field_not_included_in_envelop_addresses(self):
self.assertEqual(self.serv._addresses['from'], 'michael@example.com')
self.assertEqual(self.serv._addresses['tos'], ['rene@example.com'])

def test_lowercase_mail_from_rcpt_to(self):
m = 'A test message'
smtp = smtplib.SMTP(
HOST, self.port, local_hostname='localhost',
timeout=support.LOOPBACK_TIMEOUT)
self.addCleanup(smtp.close)

smtp.sendmail('John', 'Sally', m)

self.assertIn(['mail from:<John> size=14'], self.serv._SMTPchannel.all_received_lines)
self.assertIn(['rcpt to:<Sally>'], self.serv._SMTPchannel.all_received_lines)


class SimSMTPUTF8Server(SimSMTPServer):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use lowercase ``mail from`` and ``rcpt to`` in :class:`smptlib.SMTP`.