Skip to content

Commit

Permalink
Maildir.newMessage returns a MaildirMessageWriter with a file handl…
Browse files Browse the repository at this point in the history
…e opened

in text mode, see
https://github.com/zopefoundation/zope.sendmail/blob/2ee8b0a454ff484335e6b65b9d46a695309a2b2f/src/zope/sendmail/maildir.py#L110
(mode is 'w' not 'wb')

But `MaildirMessageWriter.write` writes bytes to this file handle, see
https://github.com/zopefoundation/zope.sendmail/blob/2ee8b0a454ff484335e6b65b9d46a695309a2b2f/src/zope/sendmail/maildir.py#L131-L132

This commit changes the implementation to use bytes for Python 3.

The change is necessary to get the tests in zopefoundation/Products.MailHost#15 green.

Closes #23. (Which had a different implementation.)
  • Loading branch information
Michael Howitz committed Mar 29, 2019
1 parent 2ee8b0a commit b841d80
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
4.2.2 (unreleased)
==================

- Nothing changed yet.
- Fix text/bytes issue in MailDir for Python 3.


4.2.1 (2019-02-07)
Expand Down
2 changes: 1 addition & 1 deletion src/zope/sendmail/maildir.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def newMessage(self):
time.sleep(0.1)
else:
break
return MaildirMessageWriter(os.fdopen(fd, 'w'), filename,
return MaildirMessageWriter(os.fdopen(fd, 'wb'), filename,
join(subdir_new, unique))


Expand Down
2 changes: 1 addition & 1 deletion src/zope/sendmail/tests/test_maildir.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def fdopen(self, fd, mode='r'):
except KeyError: # pragma: no cover
raise AssertionError('os.fdopen() called with an unknown'
' file descriptor')
assert mode == 'w'
assert mode == 'wb'
assert flags & os.O_WRONLY
assert not flags & os.O_RDWR
return FakeFile(filename, mode)
Expand Down

0 comments on commit b841d80

Please sign in to comment.