summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-08-16 04:22:15 (GMT)
committerPetri Lehtinen <petri@digip.org>2012-08-16 04:27:01 (GMT)
commit88614948c08aa583c41176d05eec5cf099c9d04d (patch)
tree904918c0d6bfbf4d6aecb8d466bfeba1dba7dcde /Lib
parent573b1fd7794e01575736826300a6d3291818f2c4 (diff)
downloadcpython-88614948c08aa583c41176d05eec5cf099c9d04d.zip
cpython-88614948c08aa583c41176d05eec5cf099c9d04d.tar.gz
cpython-88614948c08aa583c41176d05eec5cf099c9d04d.tar.bz2
#11062: Fix universal newline support in Babyl._install_message()
When adding a message from a binary file, \r\n was translated to \r\r\n in the message body.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/mailbox.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 73fe7d6..282c055 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -1450,10 +1450,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()