Repository: aio-libs/aiosmtpd
Pull request #139 (2018-01-28 23:57:52)

don't strip last CR-LF prior to terminating dot
Stripping the last \r\n off the DATA command results in the messages
actual size being 2 bytes shorter than the SIZE set in MAIL FROM.

RFC 1870[1]:
>   The message size is defined as the number of octets, including CR-LF
>   pairs, but not the SMTP DATA command's terminating dot or doubled
>   quoting dots, to be transmitted by the SMTP client after receiving
>   reply code 354 to the DATA command.

[1] https://tools.ietf.org/html/rfc1870#section-5

waynew: This is probably failing on Travis due to the IPv6 bug - a couple of the other PRs have added a fix that looks to fix that - you could either add that to this PR as well or wait for those to get merged.
waynew: I went ahead and rebased this against master :+1: 
codecov[bot]: # [Codecov](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=h1) Report
> Merging [#139](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=desc) into [master](https://codecov.io/gh/aio-libs/aiosmtpd/commit/03f1cd0a6f8f5c8366696f4faa4bce8e3f811fd5?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139/graphs/tree.svg?width=650&token=k9dc7NVG69&height=150&src=pr)](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #139   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           5      5           
  Lines         796    794    -2     
  Branches      133    132    -1     
=====================================
- Hits          796    794    -2
```


| [Impacted Files](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [aiosmtpd/smtp.py](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139/diff?src=pr&el=tree#diff-YWlvc210cGQvc210cC5weQ==) | `100% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=footer). Last update [03f1cd0...9996583](https://codecov.io/gh/aio-libs/aiosmtpd/pull/139?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/aiosmtpd/smtp.py b/aiosmtpd/smtp.py
index 657eb1e..b119dee 100644
--- a/aiosmtpd/smtp.py
+++ b/aiosmtpd/smtp.py
@@ -649,8 +649,6 @@ class SMTP(asyncio.StreamReaderProtocol):
                 self._writer.close()
                 raise
             if line == b'.\r\n':
-                if data:
-                    data[-1] = data[-1].rstrip(b'\r\n')
                 break
             num_bytes += len(line)
             if (not size_exceeded and


Test patch:
diff --git a/aiosmtpd/tests/test_handlers.py b/aiosmtpd/tests/test_handlers.py
index 67d888e..dc5de7c 100644
--- a/aiosmtpd/tests/test_handlers.py
+++ b/aiosmtpd/tests/test_handlers.py
@@ -425,7 +425,7 @@ Testing
             'Subject: A test',
             'X-Peer: ::1',
             '',
-            'Testing']).encode('ascii')
+            'Testing\r\n']).encode('ascii')
 
     def test_deliver_bytes(self):
         with ExitStack() as resources:
diff --git a/aiosmtpd/tests/test_smtp.py b/aiosmtpd/tests/test_smtp.py
index d875b8f..280889b 100644
--- a/aiosmtpd/tests/test_smtp.py
+++ b/aiosmtpd/tests/test_smtp.py
@@ -159,14 +159,14 @@ class TestProtocol(unittest.TestCase):
 
     def test_honors_mail_delimeters(self):
         handler = ReceivingHandler()
-        data = b'test\r\nmail\rdelimeters\nsaved'
+        data = b'test\r\nmail\rdelimeters\nsaved\r\n'
         protocol = self._get_protocol(handler)
         protocol.data_received(BCRLF.join([
             b'HELO example.org',
             b'MAIL FROM: <anne@example.com>',
             b'RCPT TO: <anne@example.com>',
             b'DATA',
-            data + b'\r\n.',
+            data + b'.',
             b'QUIT\r\n'
             ]))
         try:
@@ -902,7 +902,7 @@ Testing
             mail = CRLF.join(['Test', '.', 'mail'])
             client.sendmail('anne@example.com', ['bart@example.com'], mail)
             self.assertEqual(len(handler.box), 1)
-            self.assertEqual(handler.box[0].content, 'Test\r\n.\r\nmail')
+            self.assertEqual(handler.box[0].content, 'Test\r\n.\r\nmail\r\n')
 
     def test_unexpected_errors(self):
         handler = ErroringHandler()