cURL / Mailing Lists / curl-library / Single Mail

curl-library

IMAP and POP3 with libcurl 7.30

From: xyzzyx <1xyzzyx1_at_gmx.de>
Date: Sun, 12 May 2013 17:37:09 +0200

Hello,

we compiled libcurl 7.30 with OpenSSL 1.0.1e for mipsel-linux-uclibc (before
that we compiled libcurl 7.29 too).
We used the source archive from here: http://curl.haxx.se/download.html.

I have some questions how to use libcurl for IMAP
because it seems so for us that the new IMAP functions are only working in
the command line curl and not with the libcurl functions.
But as I understood the published changelog and the updated documentation
for setopt (http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) they should
also work for the libcurl functions, or am I mistaken?

For initializing I use the following (and the corresponding functions for
cleaning up):
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
But I think curl_global_init is not meant to activate the new IMAP
functions, right?

curl command line version:
curl 7.30.0 (mipsel-unknown-linux-uclibc) libcurl/7.30.0 OpenSSL/1.0.1e
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp
smtp smtps telnet tftp
Features: Largefile NTLM NTLM_WB SSL TLS-SRP

libcurl version result from "curl_version()" <libcurl/7.30.0 OpenSSL/1.0.1e>

Some examples:
For all of these: I exchanged the real user and password with just
“user:password”, user is in this case normally the complete email address
with %40 instead of the @ sign.
The command line curl version works always pretty fine, but with the same
url the libcurl function do not deliver the same result (or no result).
There are two mails in this INBOX.

1a) IMAP test 1, command line:
curl -v -o imap.txt 'imap://user:password_at_imap.1und1.de'

- delivers the folder list including the folder “INBOX”
* LIST (\HasNoChildren) "/" Drafts
* LIST (\HasNoChildren) "/" INBOX
* LIST (\HasNoChildren) "/" Sent
* LIST (\HasNoChildren) "/" Spam
* LIST (\HasNoChildren) "/" Trash

1b) IMAP test 1, libcurl functions:
CURLOPT_URL, “imap://user:password_at_imap.1und1.de
CURLOPT_HEADER, 1
CURLOPT_WRITEFUNCTION, WriteMemoryCallback
CURLOPT_WRITEDATA, (void *)&data
CURLOPT_HEADERFUNCTION, WriteMemoryCallback
CURLOPT_WRITEHEADER, (void *)&header

- delivers the multipart message from the body of the first mail as data

- delivers the IMAP protocol handshake and messages as header

- It should normally list the folders
Even if I would use the mail content from here, the email header would be
missing (although I used CURLOPT_HEADER, 1) and I do not know from, to,
subject and date.

2a) IMAP test 2, command line:
curl -v -o imap.txt 'imap://user:password_at_imap.1und1.de/INBOX'

- delivers:
* LIST (\HasNoChildren) "/" INBOX

2b) IMAP test 2, libcurl functions:
CURLOPT_URL, “imap://user:password_at_imap.1und1.de/INBOX”
CURLOPT_HEADER, 1
CURLOPT_WRITEFUNCTION, WriteMemoryCallback
CURLOPT_WRITEDATA, (void *)&data
CURLOPT_HEADERFUNCTION, WriteMemoryCallback
CURLOPT_WRITEHEADER, (void *)&header

- delivers the multipart message from the body of the first mail as data

- delivers the IMAP protocol handshake and messages as header

- It should normally list the folders
Even if I would use the mail content from here, the email header would be
missing (although I used CURLOPT_HEADER, 1) and I do not know from, to,
subject and date.

3a) IMAP test 3, command line:
curl -v -o imap.txt 'imap://user:password_at_imap.1und1.de/INBOX/;uid=1'

- delivers the complete email header (Return-Path, ... From:, To:, Subject:,
Date:, ...) and multipart message of the body

3b) IMAP test 3, libcurl functions:
CURLOPT_URL, “imap://user:password_at_imap.1und1.de/INBOX/;uid=1”
CURLOPT_HEADER, 1
CURLOPT_WRITEFUNCTION, WriteMemoryCallback
CURLOPT_WRITEDATA, (void *)&data
CURLOPT_HEADERFUNCTION, WriteMemoryCallback
CURLOPT_WRITEHEADER, (void *)&header

- delivers no data

- delivers only the header saying unknown folder:
* OK IMAP server ready H mimap12 95897
B OK LOGIN completed
C NO unknown folder
* BYE Server logging out
D OK LOGOUT completed

4a) POP3 test, command line:
curl -v -o pop3.txt 'pop3://user:password_at_pop.1und1.de'

- delivers the result that there are two emails:
1 2559
2 2722

4b) POP3 test, libcurl functions:
CURLOPT_URL, “pop3://user:password_at_pop.1und1.de
CURLOPT_HEADER, 1
CURLOPT_WRITEFUNCTION, WriteMemoryCallback
CURLOPT_WRITEDATA, (void *)&data
CURLOPT_HEADERFUNCTION, WriteMemoryCallback
CURLOPT_WRITEHEADER, (void *)&header

- delivers the result that there are two emails as data:
1 2559
2 2722

- delivers POP3 handshake and message as header (not shown here)

POP3 seems to work quite fine.

Questions regarding IMAP:
Why does IMAP work with the command line curl but not with the libcurl
functions?

How would I get the mail header (it should be included when using
"CURLOPT_HEADER, 1" or why not?)?

Is there any easy possibility to get the total number of messages?
Ok, I could parse the header to find the following which is included there,
but is there a IMAP url with which I get this as result in data, like pop3
example 4a?:
* 2 EXISTS
* 0 RECENT

Thanks,
Regards,
xyzzyx

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