Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f663d0

Browse files
committed
#12283: Fixed regression in smtplib quoting of leading dots in DATA.
I unfortunately introduced the regression when I refactored the code, and there were no tests of quoting so it wasn't caught. Now there is one.
1 parent 8168d10 commit 0f663d0

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/smtplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def quotedata(data):
162162
re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data))
163163

164164
def _quote_periods(bindata):
165-
return re.sub(br'(?m)^\.', '..', bindata)
165+
return re.sub(br'(?m)^\.', b'..', bindata)
166166

167167
def _fix_eols(data):
168168
return re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data)

Lib/test/test_smtplib.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@ def testSendBinary(self):
278278
mexpect = '%s%s\n%s' % (MSG_BEGIN, m.decode('ascii'), MSG_END)
279279
self.assertEqual(self.output.getvalue(), mexpect)
280280

281+
def testSendNeedingDotQuote(self):
282+
# Issue 12283
283+
m = '.A test\n.mes.sage.'
284+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
285+
smtp.sendmail('John', 'Sally', m)
286+
# XXX (see comment in testSend)
287+
time.sleep(0.01)
288+
smtp.quit()
289+
290+
self.client_evt.set()
291+
self.serv_evt.wait()
292+
self.output.flush()
293+
mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END)
294+
self.assertEqual(self.output.getvalue(), mexpect)
295+
281296
def testSendMessage(self):
282297
m = email.mime.text.MIMEText('A test message')
283298
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Core and Builtins
2222
Library
2323
-------
2424

25+
- Issue #12283: Fixed regression in smtplib quoting of leading dots in DATA.
26+
2527
- Issue #12168: SysLogHandler now allows NUL termination to be controlled using
2628
a new 'append_nul' attribute on the handler.
2729

0 commit comments

Comments
 (0)