Skip to content

Commit

Permalink
Ensure lines end with \r\n
Browse files Browse the repository at this point in the history
  • Loading branch information
srittau committed Apr 6, 2018
1 parent 3cc79a3 commit 9a73e67
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes in FakeSMTPd 0.2.1
==========================

Improvements
------------

* Ensure that lines end with \r\n.

Bug fixes
---------

Expand Down
4 changes: 2 additions & 2 deletions fakesmtpd/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def _handle_connection(self) -> None:
self._write_reply(SMTPStatus.SERVICE_READY,
"{} FakeSMTPd Service ready".format(getfqdn()))
while not self.reader.at_eof():
line = await self.reader.readline()
line = await self.reader.readuntil(b"\r\n")
try:
decoded = line.decode("ascii").rstrip()
except UnicodeDecodeError:
Expand Down Expand Up @@ -99,7 +99,7 @@ async def _handle_mail_text(self) -> None:

async def _read_mail_text(self) -> None:
while not self.reader.at_eof():
line = await self.reader.readline()
line = await self.reader.readuntil(b"\r\n")
if len(line) > SMTP_TEXT_LINE_LIMIT:
raise ValueError()
if line == b".\r\n":
Expand Down
3 changes: 2 additions & 1 deletion fakesmtpd_test/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def __init__(self) -> None:

# SUT Interface

async def readline(self) -> bytes:
async def readuntil(self, separator: bytes = b"\n") -> bytes:
assert_equal(b"\r\n", separator)
if not self.lines:
return b""
line = self.lines[0].encode("latin1") + b"\r\n"
Expand Down

0 comments on commit 9a73e67

Please sign in to comment.