karastojko/mailio

'Line policy overflow in a header.' exception thrown for every message in the mailbox.

tsilia opened this issue · 1 comments

Hello.
Great library! However I've run into an issue I can't seem to resolve on my own.

I have a mailbox which has lots of messages inside, nothing unusual. Every time I try to fetch a message from that mailbox via pop3::fetch() method, an exception is thrown, as the title says: Line policy overflow in a header.
I was able to trace the issue to some internal methods and came to a conclusion that the default policy for header length, RECOMMENDED, is the root cause of the issue. As far as I could understand, it sets maximum header line size to 78 bytes. Each message in my mailbox seems to contain the following header:

Received: from [XXX.XX.XXX.XXX] (port=42456 helo=xxxx.xxxxxxxxx.xx)
	by pop5.intr with esmtp (Exim 4.90_1)
	(envelope-from <xxxxxxxxxx@xxxxxxx.xx>)
	id 1krkeu-0007Ua-UQ
	for xxxxxxxxxx@xxxxxxx.xx; Tue, 22 Dec 2020 16:37:13 +0000

which gets concatenated by the library into single lengthy header:

Received: from [XXX.XX.XXX.XXX] (port=42456 helo=xxxx.xxxxxxxxx.xx)by pop5.intr with esmtp (Exim 4.90_1)(envelope-from <xxxxxxxxxx@xxxxxxx.xx>)id 1krkeu-0007Ua-UQfor xxxxxxxxxx@xxxxxxx.xx; Tue, 22 Dec 2020 16:37:13 +0000

and causes an exception (I redacted email and server addresses but kept their length intact).

If I'm correct I should just set another policy, but I can't figure out how to do it. As far as I can see, the policy is set somewhere in the guts of the library.

Is there any interface method on pop3 or another class that I could use to change the restriction to smth else, like MANDATORY or NONE? I couldn't find one.
Or, alternatively, is there any way to fetch raw message and parse it using a mime class instance tuned to use other header policy than RECOMMENDED?

Thank you in advance.

I have just figured out that message is a descendant of mime which allows me to do the following:

message msg;
msg.line_policy(codec::line_len_policy_t::MANDATORY, codec::line_len_policy_t::MANDATORY);

And this totally resolves the issue.

Sorry for bothering. As it often happens you just have to describe someone your issue and it alone can solve it. Thanx for being my rubber duck 🦆