diff options
author | Petri Lehtinen <petri@digip.org> | 2012-08-16 07:27:47 +0300 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2012-08-16 07:27:53 +0300 |
commit | 69a06dd59defa8de0586eb751b6acbed50fddc3e (patch) | |
tree | e963d42c66793e9fa101310c0acb940529a0c683 /Lib/mailbox.py | |
parent | 0e41628d3583c03a6078d88c91a4ac80482f060b (diff) | |
parent | 88614948c08aa583c41176d05eec5cf099c9d04d (diff) | |
download | cpython-git-69a06dd59defa8de0586eb751b6acbed50fddc3e.tar.gz |
#11062: Fix universal newline support in Babyl._install_message()
Diffstat (limited to 'Lib/mailbox.py')
-rw-r--r-- | Lib/mailbox.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 30877f1a6a..1841b0fb0e 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1447,10 +1447,17 @@ class Babyl(_singlefileMailbox): else: break while True: - buffer = message.read(4096) # Buffer size is arbitrary. - if not buffer: + line = message.readline() + if not line: break - self._file.write(buffer.replace(b'\n', linesep)) + # Universal newline support. + if line.endswith(b'\r\n'): + line = line[:-2] + linesep + elif line.endswith(b'\r'): + line = line[:-1] + linesep + elif line.endswith(b'\n'): + line = line[:-1] + linesep + self._file.write(line) else: raise TypeError('Invalid message type: %s' % type(message)) stop = self._file.tell() |