changeset: 78608:770ffc91a82e branch: 3.2 parent: 78606:8ff172a1b679 user: Petri Lehtinen date: Thu Aug 16 07:22:15 2012 +0300 files: Lib/mailbox.py description: #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. diff -r 8ff172a1b679 -r 770ffc91a82e Lib/mailbox.py --- a/Lib/mailbox.py Thu Aug 16 14:13:07 2012 +1000 +++ b/Lib/mailbox.py Thu Aug 16 07:22:15 2012 +0300 @@ -1450,10 +1450,17 @@ 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()