curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: IMAP - how to correctly fetch header data?

From: Ray Satiro via curl-users <curl-users_at_lists.haxx.se>
Date: Mon, 6 Mar 2023 01:19:53 -0500

On 2/21/2023 7:55 AM, Dominik Ritter via curl-users wrote:
>
> since a couple of days I am exploring curl in order to retrieve mails.
>
> Currently I struggle with the CURLOPT_CUSTOMREQUEST not providing all
> data.
>
> I found a couple of very old sources in the WWW that had the same
> issue but these are a couple of years old and I wonder if there is a
> solution?
>
> What I tried so far is the following:
>
> /        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);////       
> curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, &debugger);////       
> curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &trace);//// <--- trace
> ////        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
> &writer_function);////        curl_easy_setopt(curl,
> CURLOPT_WRITEDATA, &buffer);//// <--- buffer /
>
> /        curl_easy_setopt(curl, CURLOPT_URL,
> currentInbox.toStdString().c_str()); //
> /
>
> /        /* Perform the fetch */////        res =
> curl_easy_perform(curl);//////        curl_easy_setopt(curl,
> CURLOPT_CUSTOMREQUEST, "FETCH 1:* (RFC822.SIZE BODY[HEADER.FIELDS
> (from to subject date)])");///
>
> /        /* Perform the fetch */////        res =
> curl_easy_perform(curl);//////        return
> QString::fromUtf8(buffer.c_str()) + QString("TRACE STARTS HERE\n") +
> QString::fromStdString(trace.c_str());/
>
> The buffer that should contain all the data only has the summary:
>
> /* 1 FETCH (RFC822.SIZE 1212 BODY[HEADER.FIELDS (FROM TO SUBJECT
> DATE)] {126} /
>
> /* 2 FETCH (RFC822.SIZE 2876 BODY[HEADER.FIELDS (FROM TO SUBJECT
> DATE)] {153}/
>
> //
>
> /* 3 FETCH (RFC822.SIZE 268 BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)]
> {131}/
>
> ...
>
> Only he trace got the data i wanted:
>
> /[...]/
>
> /* 1 FETCH (RFC822.SIZE 1212 BODY[HEADER.FIELDS (FROM TO SUBJECT
> DATE)] {126} /
>
> /Date: Sun, 12 Feb 2023 14:12:32 +0100/
>
> //
>
> /To: demo_at_domain.de/
>
> //
>
> /From: Dominik <dominik_at_domain.de>/
>
> //
>
> /Subject: Hallo/
>
> /[...]/
>
> Trying to do this without the CURLOPT_CUSTOMREQUEST is even worse
>
> When i use
>
> /curl_easy_setopt(curl, CURLOPT_URL;
> "imaps://<domain>/;UID=1:*/;section=HEADER.FIELDS%20(From%20Date%20Subject)");/
>
> The result from WRITEFUNCTION contains only the requested data from
> the first mail and the trace is incomplete (first mail has no data -
> but the rest of mails are displayed:
>
>
> /Found bundle for host: 0x562c629b4260 [serially]/
>
> //
>
> /Re-using existing connection #0 with host mail.cadori.de/
>
> //
>
> /[CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS header, Supplemental data (23):/
>
> //
>
> /T/
>
> //
>
> /A005 UID FETCH 1:* BODY[HEADER.FIELDS (From Date Subject)]/
>
> //
>
> /[CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Supplemental data (23):/
>
> //
>
> /�/
>
> //
>
> /* 1 FETCH (UID 2 BODY[HEADER.FIELDS (FROM DATE SUBJECT)] {106}/
>
> //
>
> /Found 106 bytes to download/
>
> //
>
> /Written 106 bytes, 0 bytes are left for transfer/
>
> //
>
> /)/
>
> //
>
> /* 2 FETCH (UID 3 BODY[HEADER.FIELDS (FROM DATE SUBJECT)] {110}/
>
> /Date: Sun, 12 Feb 2023 14:15:32 +0100/
>
> //
>
> /To: demo_at_domain.de/
>
> //
>
> /From: Dominik <dominik_at_domain.de>/
>
> //
>
> /Subject: TEST/
>
>
> I can use the trace to get the data i need, but I wonder if there is a
> better way? Is there any best practices?
>
CUSTOMREQUEST replies aren't parsed as body. Try CURLOPT_HEADERFUNCTION.
Also see https://github.com/curl/curl/issues/2055


-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-03-06