textonly: respect the Content-Length header to delimit the message body
Message boundaries were found only by the mbox "From " line, which is
unreliable: an inlined patch or a quoted mail can contain a line
starting with "From " and would prematurely cut the message. While the
quoted message was deliberately ignored first as rare, the inline patch
regularly causes problems, with changes happening a second time there.
When a Content-Length header is present it is authoritative, so keep its
value in a counter, decrement it by each consumed body line, and stop
once it reaches zero; "From " detection (body_done()) is kept only as the
fallback for messages that have no Content-Length. The parsing stays a
plain byte stream, no buffering or allocation.
The Content-Length is still dropped from the output (the body we emit,
after dropping attachments and decoding, has a different size) since
we're processing it as a stream, we can't roll back to the headers area.
A future patch will permit to save it into an extra file.
1 file changed