Question

We're using Delphi XE5 Architect & the version of Indy that comes with it. We have an app that sends and receives messages with different exchange partners. Some of these messages are formatted like emails, with MIME encoded parts in the body of the email. We use TIdMessage to process/decode/reconstruct the MIME parts and this works really well.

Today we started receiving errors from the TIdMessage while it is decoding the MIME parts

Max line length exceeded

We're trying to troubleshoot and see if there is a character issue?

In a hex editor, when we examine the messages, they have the text

\.br\

, followed by a hex 09, which appears as a '.' after the

\.br\. 

Could this appear as an improper line break to the parser?

Also we're considering if the content length is just too much?

With proper line breaks the messages range between 2k - 6.6k lines.

Was it helpful?

Solution

Indy's MIME parser reads data line by line from the data source so it does not have to load the entire email into memory before parsing it. TIdMessage uses TIdIOHandlerStreamMsg internally as its data source. That particular error means the TIdIOHandler.ReadLn() method (which stops reading on a (CR)LF line break by default) encountered a line that is longer than allowed.
Indy's default max line length is 16384 characters, and TIdMessage does not override that. Typically, you don't see emails with individual lines that long, they are usually capped at 70-odd characters for historic reasons. If the MIME data does not have any LF characters before the 16K limit is reached, that will cause problems. That could happen, for instance, if the MIME data is using a Content-Transfer-Encoding header that is set to 8bit or binary so the data does not have to be encoded in an 7bit-safe manner, which most email transports use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top