Bug report
Bug description:
Babyl._install_message() flattens the visible headers of a BabylMessage into a BytesIO and then reads it back line by line, but never rewinds the buffer first. The first readline() returns b'', so neither the visible headers nor the blank line after them are written.
Reading the message back then fails with AssertionError, because get_message() consumes the body as visible headers and runs past the end of the message:
import mailbox
mbox = mailbox.Babyl('test.babyl')
msg = mailbox.BabylMessage()
msg['Subject'] = 'Test subject'
msg.set_payload('Test body')
msg.update_visible()
key = mbox.add(msg)
mbox.get(key)
The message section written to test.babyl contains *** EOOH ***\nTest body\n\x1f where *** EOOH ***\nSubject: Test subject\n\nTest body\n\x1f was expected. get_bytes() fails the same way, and so does a BabylMessage with no visible headers at all, since the blank line is missing too.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
Babyl._install_message()flattens the visible headers of aBabylMessageinto aBytesIOand then reads it back line by line, but never rewinds the buffer first. The firstreadline()returnsb'', so neither the visible headers nor the blank line after them are written.Reading the message back then fails with AssertionError, because
get_message()consumes the body as visible headers and runs past the end of the message:The message section written to
test.babylcontains*** EOOH ***\nTest body\n\x1fwhere*** EOOH ***\nSubject: Test subject\n\nTest body\n\x1fwas expected.get_bytes()fails the same way, and so does aBabylMessagewith no visible headers at all, since the blank line is missing too.CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs