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

Problem while fetching mail via IMAP #99

Closed asc9479 closed 1 year ago

asc9479 commented 2 years ago

Hi! I get an error while fetching a Multipartmail: "No boundary for multipart message."

In the mail are a lot of headers, including:

Content-Type: multipart/mixed;
    boundary="_002_499fd0aeb4974acea221e63dda5e9ed8Exchange33adwortmannde_"
MIME-Version: 1.0

--_002_499fd0aeb4974acea221e63dda5e9ed8Exchange33adwortmannde_
Content-Type: text/html; charset="utf-8"
Content-ID: <6B50FE84DA035F4F8AD46323BD3D2884@primos-datensysteme.de>
Content-Transfer-Encoding: base64

PCEtLURFVURFQSA+IERFVURFUyA+IERFVUVOVUVORyA+IEVOVUZSQU5MRFNQQVBPTElUQS0tPjwh
RE9DVFlQRSBodG1sIFBVQkxJQyAiLS8vVzNDLy9EVEQgWEhUTUwgMS4wIFN0cmljdC8vRU4iICJo
dHRwOi8vd3d3LnczLm9yZy9UUi94aHRtbDEvRFREL3hodG1sMS1zdHJpY3QuZHRkIj4NCjxodG1s.....

Can you give me a hint to find the error in my code to fetch the mail correctly? Thanks!

asc9479 commented 2 years ago

Here a second mail I cant fetch. In this example I have more than one boundary string.

Content-Type: multipart/mixed;
    boundary="_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_"
MIME-Version: 1.0

--_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: multipart/related;
    boundary="_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_";
    type="text/html"

--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: text/html; charset="utf-8"
Content-ID: <52D514BF6FA3414FB2B3A0621851A7D5@primos-datensysteme.de>
Content-Transfer-Encoding: base64

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
[...]
CjwvYm9keT4NCjwvaHRtbD4NCg==

--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: image/png; name="html.1344656541.png"
Content-Description: html.1344656541.png
Content-Disposition: inline; filename="html.1344656541.png"; size=1048;
    creation-date="Mon, 04 Jul 2022 07:52:21 GMT";
    modification-date="Mon, 04 Jul 2022 07:52:21 GMT"
Content-ID: <html.1344656541.png@123>
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAANAAAAATCAYAAADh2INuAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
[...]
yDAGsAYyjAGsgQxjAGsgwxjAGsgwbuP9H3HIf8YvBnWMAAAAAElFTkSuQmCC

--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: image/png; name="html.1892493398.png"
Content-Description: html.1892493398.png
Content-Disposition: inline; filename="html.1892493398.png"; size=1123;
    creation-date="Mon, 04 Jul 2022 07:52:21 GMT";
    modification-date="Mon, 04 Jul 2022 07:52:21 GMT"
Content-ID: <html.1892493398.png@123>
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAANAAAAATCAYAAADh2INuAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
[...]
TkSuQmCC

--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: image/png; name="html.3062375550.png"
Content-Description: html.3062375550.png
Content-Disposition: inline; filename="html.3062375550.png"; size=1340;
    creation-date="Mon, 04 Jul 2022 07:52:21 GMT";
    modification-date="Mon, 04 Jul 2022 07:52:21 GMT"
Content-ID: <html.3062375550.png@123>
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAANAAAAATCAYAAADh2INuAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
[...]
SdJbFRAphW5tKqbOBI6m0+lcSi+gTucT9ALqdC4mpf8v7zMYkBurowAAAABJRU5ErkJggg==

--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: image/png; name="html.3625581849.png"
Content-Description: html.3625581849.png
Content-Disposition: inline; filename="html.3625581849.png"; size=4039;
    creation-date="Mon, 04 Jul 2022 07:52:21 GMT";
    modification-date="Mon, 04 Jul 2022 07:52:21 GMT"
Content-ID: <html.3625581849.png@123>
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAFUAAAAmCAYAAAC1Q9c1AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
[.....]
zPwsAAAAAElFTkSuQmCC

--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_--

--_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_
Content-Type: application/pdf; name="Beleg_2022-058332.pdf"
Content-Description: Beleg_2022-058332.pdf
Content-Disposition: attachment; filename="Beleg_2022-058332.pdf";
    size=144158; creation-date="Mon, 04 Jul 2022 07:52:21 GMT";
    modification-date="Mon, 04 Jul 2022 07:52:21 GMT"
Content-ID: <Beleg_2022-058332.pdf>
Content-Transfer-Encoding: base64

JVBERi0xLjMKJeLjz9MKMSAwIG9iago8PC9BdXRob3IoKS9DcmVhdG9yKE1pY3Jvc29mdCBSZXBv
[.......]
YjY3NGQ4MGUzYzFhZjcyODFiZjY5PjwwOGZjNjQ1NGM3NWI2NzRkODBlM2MxYWY3MjgxYmY2OT5d
Pj4Kc3RhcnR4cmVmCjE0MzE4NQolJUVPRgo=

--_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_--
karastojko commented 2 years ago

For the first example, I copied your email raw content and added the address headers:

    string msg_str = "From: mailio <mailio@gmail.com>\r\n"
        "To: mailio <mailio@gmail.com>\r\n"
        "Date: Thu, 11 Feb 2016 22:56:22 +0000\r\n"
        "Subject: Test\r\n"
        "Content-Type: multipart/mixed;\r\n"
        "   boundary=\"_002_499fd0aeb4974acea221e63dda5e9ed8Exchange33adwortmannde_\"\r\n"
        "MIME-Version: 1.0\r\n"
        "\r\n"
        "--_002_499fd0aeb4974acea221e63dda5e9ed8Exchange33adwortmannde_\r\n"
        "Content-Type: text/html; charset=\"utf-8\"\r\n"
        "Content-ID: <6B50FE84DA035F4F8AD46323BD3D2884@primos-datensysteme.de>\r\n"
        "Content-Transfer-Encoding: base64\r\n"
        "\r\n"
        "PCEtLURFVURFQSA+IERFVURFUyA+IERFVUVOVUVORyA+IEVOVUZSQU5MRFNQQVBPTElUQS0tPjwh\r\n"
        "RE9DVFlQRSBodG1sIFBVQkxJQyAiLS8vVzNDLy9EVEQgWEhUTUwgMS4wIFN0cmljdC8vRU4iICJo\r\n"
        "dHRwOi8vd3d3LnczLm9yZy9UUi94aHRtbDEvRFREL3hodG1sMS1zdHJpY3QuZHRkIj4NCjxodG1s\r\n";
    message msg;
    msg.line_policy(codec::line_len_policy_t::MANDATORY, codec::line_len_policy_t::MANDATORY);
    msg.parse(msg_str);
    cout << msg.subject() << endl;

There are no errors reported. So, does this fails in your case?

For the second example, are the parts [...] added by you to shorten the content?

asc9479 commented 2 years ago

Hi, thanks for the first example, I will check it as soon as possible.

for the second example: Yes, that should shorten the content.

It’s an incoming Invoice-Mail with two attachments: an pdf and a signature. Plus html-Part.

If it helps, I could send you a few full example mails, but I think it’s better I don’t post it here.

karastojko commented 2 years ago

The second example also works fine in my case:

string msg_str = "From: mailio <mailio@gmail.com>\r\n"
    "To: mailio <mailio@gmail.com>\r\n"
    "Date: Thu, 11 Feb 2016 22:56:22 +0000\r\n"
    "Subject: Proba\r\n"
    "Content-Type: multipart/mixed;\r\n"
    "  boundary=\"_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\"\r\n"
    "MIME-Version: 1.0\r\n"
    "\r\n"
    "--_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: multipart/related;\r\n"
    "  boundary=\"_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\";\r\n"
    "  type=\"text/html\"\r\n"
    "\r\n"
    "--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: text/html; charset=\"utf-8\"\r\n"
    "Content-ID: <52D514BF6FA3414FB2B3A0621851A7D5@primos-datensysteme.de>\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "\r\n"
    "PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs\r\n"
    "\r\n"
    "--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: image/png; name=\"html.1344656541.png\"\r\n"
    "Content-Description: html.1344656541.png\r\n"
    "Content-Disposition: inline; filename=\"html.1344656541.png\"; size=77;\r\n"
    "  creation-date=\"Mon, 04 Jul 2022 07:52:21 GMT\";"
    "  modification-date=\"Mon, 04 Jul 2022 07:52:21 GMT\"\r\n"
    "Content-ID: <html.1344656541.png@123>\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "\r\n"
    "iVBORw0KGgoAAAANSUhEUgAAANAAAAATCAYAAADh2INuAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\r\n"
    "\r\n"
    "--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: image/png; name=\"html.1892493398.png\"\r\n"
    "Content-Description: html.1892493398.png\r\n"
    "Content-Disposition: inline; filename=\"html.1892493398.png\"; size=77;\r\n"
    "  creation-date=\"Mon, 04 Jul 2022 07:52:21 GMT\";\r\n"
    "  modification-date=\"Mon, 04 Jul 2022 07:52:21 GMT\"\r\n"
    "Content-ID: <html.1892493398.png@123>\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "\r\n"
    "iVBORw0KGgoAAAANSUhEUgAAANAAAAATCAYAAADh2INuAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\r\n"
    "\r\n"
    "--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: image/png; name=\"html.3062375550.png\"\r\n"
    "Content-Description: html.3062375550.png\r\n"
    "Content-Disposition: inline; filename=\"html.3062375550.png\"; size=77;\r\n"
    "  creation-date=\"Mon, 04 Jul 2022 07:52:21 GMT\";\r\n"
    "  modification-date=\"Mon, 04 Jul 2022 07:52:21 GMT\"\r\n"
    "Content-ID: <html.3062375550.png@123>\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "\r\n"
    "iVBORw0KGgoAAAANSUhEUgAAANAAAAATCAYAAADh2INuAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\r\n"
    "\r\n"
    "--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: image/png; name=\"html.3625581849.png\"\r\n"
    "Content-Description: html.3625581849.png\r\n"
    "Content-Disposition: inline; filename=\"html.3625581849.png\"; size=77;\r\n"
    "  creation-date=\"Mon, 04 Jul 2022 07:52:21 GMT\";\r\n"
    "  modification-date=\"Mon, 04 Jul 2022 07:52:21 GMT\"\r\n"
    "Content-ID: <html.3625581849.png@123>\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "\r\n"
    "iVBORw0KGgoAAAANSUhEUgAAAFUAAAAmCAYAAAC1Q9c1AAAAAXNSR0IArs4c6QAAAARnQU1BAACx\r\n"
    "\r\n"
    "--_006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_--\r\n"
    "\r\n"
    "--_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_\r\n"
    "Content-Type: application/pdf; name=\"Beleg_2022-058332.pdf\"\r\n"
    "Content-Description: Beleg_2022-058332.pdf\r\n"
    "Content-Disposition: attachment; filename=\"Beleg_2022-058332.pdf\";\r\n"
    "  size=77; creation-date=\"Mon, 04 Jul 2022 07:52:21 GMT\";\r\n"
    "  modification-date=\"Mon, 04 Jul 2022 07:52:21 GMT\"\r\n"
    "Content-ID: <Beleg_2022-058332.pdf>\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "\r\n"
    "JVBERi0xLjMKJeLjz9MKMSAwIG9iago8PC9BdXRob3IoKS9DcmVhdG9yKE1pY3Jvc29mdCBSZXBv\r\n"
    "--_007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_--";
message msg;
msg.line_policy(codec::line_len_policy_t::MANDATORY, codec::line_len_policy_t::MANDATORY);
msg.parse(msg_str);
cout << msg.subject() << " " << msg.parts().size() << " " << msg.parts().at(0).parts().size() << endl;

Everything is same as in your sample, except that mime parts are shortened to one line and thus the size in the headers is set to 77 bytes. The message correctly has two mime parts for the boundary _007_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_. The first part has another five nested parts for the boundary _006_c9456a8d39634a4794a4df150b5b82bbsv0012020pinaglocal_.