diff -r 0b78a8c35357 Lib/smtplib.py --- a/Lib/smtplib.py Thu Dec 15 18:58:35 2016 -0500 +++ b/Lib/smtplib.py Fri Dec 16 15:04:13 2016 -0500 @@ -913,20 +913,21 @@ # Section 3.6.6). In such a case, we use the 'Resent-*' fields. However, # if there is more than one 'Resent-' block there's no way to # unambiguously determine which one is the most recent in all cases, - # so rather than guess we raise a ValueError in that case. + # so rather than guess we raise a ValueError in that case. See RFC 5322 + # section 3.6.6, first paragraph for more details about the "should" that + # the code should respect. # # TODO implement heuristics to guess the correct Resent-* block with an # option allowing the user to enable the heuristics. (It should be # possible to guess correctly almost all of the time.) - self.ehlo_or_helo_if_needed() - resent = msg.get_all('Resent-Date') - if resent is None: - header_prefix = '' - elif len(resent) == 1: - header_prefix = 'Resent-' - else: - raise ValueError("message has more than one 'Resent-' header block") + #Resent or original? + header_prefix = 'Resent-' if len(msg.get('Resent-Date','')) >= 1 else '' + + # RFC 5322 section 3.6, 4th Paragraph + if msg.get('Date',None) is None: + msg['Date'] = email.utils.formatdate() + if from_addr is None: # Prefer the sender field per RFC 2822:3.6.2. from_addr = (msg[header_prefix + 'Sender'] @@ -1110,5 +1111,6 @@ server = SMTP('localhost') server.set_debuglevel(1) - server.sendmail(fromaddr, toaddrs, msg) + #server.sendmail(fromaddr, toaddrs, msg) + server.send_message(from_addr=fromaddr, to_addrs=toaddrs, msg=email.message_from_string(msg)) server.quit() diff -r 0b78a8c35357 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Thu Dec 15 18:58:35 2016 -0500 +++ b/Lib/test/test_smtplib.py Fri Dec 16 15:04:13 2016 -0500 @@ -531,13 +531,14 @@ re.MULTILINE) self.assertRegex(debugout, to_addr) - def testSendMessageMultipleResentRaises(self): + def testSendMessageMultipleResent(self): + first_date = 'Thu, 1 Jan 1970 17:42:00 +0000' m = email.mime.text.MIMEText('A test message') m['From'] = 'foo@bar.com' m['To'] = 'John' m['CC'] = 'Sally, Fred' m['Bcc'] = 'John Root , "Dinsdale" ' - m['Resent-Date'] = 'Thu, 1 Jan 1970 17:42:00 +0000' + m['Resent-Date'] = first_date m['Resent-From'] = 'holy@grail.net' m['Resent-To'] = 'Martha , Jeff' m['Resent-Bcc'] = 'doe@losthope.net' @@ -545,8 +546,13 @@ m['Resent-To'] = 'holy@grail.net' m['Resent-From'] = 'Martha , Jeff' smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) - with self.assertRaises(ValueError): - smtp.send_message(m) + smtp.send_message(m) #validate that no errors are raised + self.assertEqual(first=m.get('Resent-Date'), + second=first_date, + msg=""" + The Resent-Date order is not read correctly or + something wrong happened. + """) smtp.close() class NonConnectingTests(unittest.TestCase):