mailio icon indicating copy to clipboard operation
mailio copied to clipboard

Line policy overflow in a header (mime.cpp)

Open Displacer opened this issue 1 year ago • 5 comments

There is a condition for line.length() in mime.cpp parse_by_line function:

if (line.length() > string::size_type(decoder_line_policy_))
    throw mime_error("Line policy overflow in a header.");

decoder_line_policy_ is set to mailio::codec::line_len_policy_t::RECOMMENDED which equals 73.

In some cases MS Exchange mail server produces lines with larger size, leading to exception thrown.

Can this value be increased to support such messages?

Displacer avatar Apr 30 '24 14:04 Displacer

setting codition to mailio::codec::line_len_policy_t::MANDATORY seems fixing this problem

Displacer avatar Apr 30 '24 15:04 Displacer

Correct, that's the purpose of the line policy.

karastojko avatar Apr 30 '24 16:04 karastojko

Correct, that's the purpose of the line policy.

I have provided pull request https://github.com/karastojko/mailio/pull/167 to quick merge if this is correct changes.

PS: There is also pull request to support boost versions before 1.81 (Ubuntu 22.04 LTS have 1.74)

Displacer avatar May 01 '24 07:05 Displacer

It seems decoder_line_policy_ should be set for mailio::codec::line_len_policy_t::MANDATORY in class initialization since there are overflows in mailio::bit8::decode (line 80) in some cases with RECOMMENDED value.

Displacer avatar May 05 '24 08:05 Displacer

there seems to be a problem in imap.cpp (line 458): msg.line_policy(line_policy, line_policy); the second parameter of msg.line_policy seems should be MANDATORY also

Displacer avatar May 05 '24 08:05 Displacer

I have the same issue. In my case, the IMAP server is ionos.com. So, to fix it, I need to modify the source and build the project, right? Right now, I am using vcpkg for this library.

Nullarity avatar Oct 23 '24 01:10 Nullarity

I have the same issue. In my case, the IMAP server is ionos.com. So, to fix it, I need to modify the source and build the project, right? Right now, I am using vcpkg for this library.

You probably could try something like this in client code without rebuilding library:

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

I hope this will help.

Displacer avatar Oct 23 '24 15:10 Displacer

@Displacer That's right.

There is also the NONE policy which means unlimited.

karastojko avatar Oct 23 '24 15:10 karastojko

Thank you, guys, it helped, but unfortunately, while fetching other emails, I get SIGSEGV.

code snippet:

    for (const auto msg_uid : messages) {
      message msg;
      msg.line_policy(codec::line_len_policy_t::NONE,
                      codec::line_len_policy_t::NONE);
      conn.fetch(msg_uid, msg);
      if (!msg.empty()) {
        cout << msg.subject() << endl;
      }
    }

stacktrace.txt

image

Nullarity avatar Oct 23 '24 20:10 Nullarity

Thanks for the report. Can you please in the method mime::content_type_t::operator=(const mime::content_type_t&) before the line with to_lower_copy put printing of cont_type.subtype and paste the result here? I am interested to understand the reason of the crash of to_lower_copy() in your case.

karastojko avatar Oct 24 '24 16:10 karastojko