cURL / Mailing Lists / curl-library / Single Mail


Re: Improving IMAP support

From: Jiří Hruška <>
Date: Thu, 3 Jan 2013 17:33:14 +0100

Hi Daniel and Steve,

thank you for the responses -- unfortunately I had to take care of
more stuff than expected before my annual leave at the end of the
year, so I was not able to prepare anything meaningful in the previous
weeks. However now I'm back at work and I want to resolve this the
first thing in the new year, so I went and created some cleaner
patches with my changes, based on the current GIT version (however
volatile that might be wrt the current renaming, merge of the
always-multi branch etc.).

Steve, I noticed you have been touching the IMAP parts recently as you
said last year and I'm of course afraid you had to do much of the work
I did as well in the last days -- sorry for the delay if you did. But
maybe if you are dealing mostly with the login/authentication phase,
my FETCH/APPEND/CUSTOMREQUEST stuff can still be of some use.
(Also I've seen your inquiry about CAPABILITY support in the test
server - I familiarized myself with the testsuite and, so
I can volunteer to test and finalize your tests if you want.)

Anyway, I divided the changes into three patches - some
(curl_)pingpong.c fix and refactoring, the main imap.c stuff, and
updates to the test suite. There are more comments in the individual
patch files, however the improvements can be summed as
  * Almost full support for IMAP FETCH URLs (UID, UIDVALIDITY, SECTION)
  * Support for uploading messages using APPEND
  * Support for custom commands (e.g. STORE)

The diff of (curl_)imap.c is quite dense, but largely due to me
reordering the functions a bit to be more readable and clean (IMHO, of
  * Low-level protocol routines
      imap_sendf, imap_atom, imap_isdigit, imap_matchresp, imap_endofresp,
  * Connection state machine
        imap_state_servergreet_resp, imap_to_imaps, imap_state_starttls_resp,
    * State: LOGIN
        imap_state_login, imap_state_login_resp
    * State: SELECT
        imap_perform_select, imap_state_select_resp, imap_after_select
    * State: FETCH, FETCH_DONE
        imap_perform_fetch, imap_state_fetch_resp, imap_state_fetch_done_resp
        imap_perform_append, imap_state_append_resp, imap_state_append_done_resp
    * State: CUSTOM
        imap_perform_custom, imap_state_custom_resp
    * State: LOGOUT
  * Connection handling
      imap_statemach_act, imap_multi_statemach, imap_easy_statemach,
      imap_connect, imap_disconnect, imap_setup_connection
  * Request handling
      imap_init, imap_perform, imap_do, imap_doing, imap_done, imap_is_bchar,

For that reason, I've attached an extra file curl_imap-minimal.diff,
which have all the same modifications, except the functions are in
their original order and the separator comments are missing. It's
easier to review and can be also used if you simply don't like it that
way ;)

The code compiles and runs with 716 tests out of 717 reported OK - the
failing test case is #24, which seems unrelated.

There are two things I deem "not too nice", marked by TODO in the source:
  * Reported error codes - CURLE_FTP_WEIRD_SERVER_REPLY looks weird
with IMAP, don't know if CURLE_REMOTE_FILE_NOT_FOUND is reasonable for
"mailbox does not exist" etc.
  * Handling of DONE phase is synchronous and in IMAP this can mean
waiting for socket I/O (e.g. final FETCH response after downloading
the body).

Kind regards,

List admin:

Received on 2013-01-03