karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3 and IMAP protocols. It is based on standard C++ 17 and Boost library.
Other
374 stars 98 forks source link

References Id Parse Error #85

Closed ArcaneEcholan closed 2 years ago

ArcaneEcholan commented 2 years ago

When I use POP3 protocol to pull mail, the program reports an error:

'Parsing failure of the ID: xxxxxx'

I checked the error stack and found that the function message::parse_many_ids() performs regular matching on Message-ID:

else if (iequals(header_name, MESSAGE_ID_HEADER))
{
    auto ids = parse_many_ids(header_value);
    if (!ids.empty())
    _message_id = ids[0];
}

The Message-ID of one of my emails is as follows:

<2uf7mx4k3q95k6r23xc60kvsc254re-60q5dtl4ln4v-gzybkr-h6pbri-7gbfzj-xhwst0-p9owg5hobveo-rypeifu6sp5t-it9vds-z770c1-zdjhdr-mhqq5l

The regular expression inside the function message::parse_many_ids() is as follows:

(<([a-zA-Z0-9\!#\$%&'\*\+\-\./=\?\^\_`\{\|\}\~]+)\@([a-zA-Z0-9\!#\$%&'\*\+\-\./=\?\^\_`\{\|\}\~]+)>)

The regular expression will only match the text like:

<A@test.com>

Obviously, the Message-ID of my mail will cause the program to report an error.

But I want to know, can I not check the Message-ID of the message? Will this have any side effects? Because I found that the Message-ID format of messages sent by different servers seems to be different. I found the same problem with the References header. Moreover, I specially compared the implementation of Java's POP3 protocol(javax.mail). It seems that Java does not perform any matching on the Message-ID and References header fields.

karastojko commented 2 years ago

By the specification this is the required format of the message ID. Since there is a possibioity to use the non-strict parsing of messages, I will add this feature at the end of the week. If you are in a hurry, you may create a PR and I will merge it.

karastojko commented 2 years ago

@Aaron-srider Maybe the change from this branch may work for you. To use it you need to set the strict mode to false (set by default). Although the tests look fine, I still have to check if something is broken.

karastojko commented 2 years ago

Should be fixed with the latest commit.