Re: IMAP - how to correctly fetch header data?

Ray Satiro via curl-users <[email protected]>
Newsgroups gmane.comp.web.curl.general
Message-ID <[email protected]>
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: [email protected]/
>
> //
>
> /From: Dominik <[email protected]>/
>
> //
>
> /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: [email protected]/
>
> //
>
> /From: Dominik <[email protected]>/
>
> //
>
> /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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.