cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Question regarding multiple IMAP operations

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 27 May 2015 02:33:37 -0400

On 5/26/2015 9:31 AM, Adam wrote:
> What is the proper way to send multiple IMAP commands? For example,
> first I'd like to get a listing of all the folder names, then I want
> to list the unread files in the folder names.
>
> I've tried using the same CURL* curl handle, sometimes it crashes on
> curl_easy_cleanup() (single threaded app), and sometimes it crashes on
> the second call to curl_easy_perform(). It depends on the IMAP server,
> gmail causes a crash, hotmail doesn't. I've even tried opening/closing
> a new handle for each operation and this causes crashes also.
>
> What is the proper way to do this? There are no code samples for this
> on the libcurl homepage. Thanks.

The proper way is multiple requests and don't call curl_easy_cleanup
until after you're done with the handle. You want to reuse the handle
until then. Please note as mentioned in the curl_easy_cleanup doc that
"Any use of the handle after this function has been called and have
returned, is illegal." [1]

So you have custom request(s) to get the unread ids then you get the
subjects. Getting the subjects from what I remember is tricky, they only
show up in the header section and not the body unless behavior was
improved in the last year or two. As I think I mentioned to you off-list
somewhere libcurl has minimal support for IMAP command parsing. You'll
have to do a lot of the parsing yourself. The actual command to get the
subject for an id is:
"FETCH " + id + " BODY.PEEK[HEADER.FIELDS (SUBJECT)]"

You may want to check out LibEtPan [2] or take a closer look at Vmime
which you've mentioned.

[1]: http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html
[2]: https://github.com/dinhviethoa/libetpan

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-05-27