curl / Mailing Lists / curl-library / Single Mail

curl-library

Propose 2 patches of lib/imap.c for comments

From: kinglt <kinglotterry_at_163.com>
Date: Tue, 08 May 2018 18:33:57 +0800

Hello,

When programming IMAP with libcurl, I got 2 enhancements for it.

1. a bug fix

Problem: When using url
"imap://user:password_at_example.com/INBOX/;UID=123" to fetch email,
libcurl treat UID as MSN(message sequence number) and get wrong
result. 

By RFC 5092 "IMAP URL Scheme" section 6 , An IMAP URL referring to a
specific message or message part has the following form:
imap://<iserver>/<enc-mailbox>[<uidvalidity>]<iuid>..., The <iuid>
refers to an IMAP4 message Unique Identifier (UID), and it SHOULD be
used as the <set> argument to the IMAP4 "UID FETCH" command.

Libcurl verbose mode present: "> A004 FETCH 123 BODY[]". The number is
MSN, not UID.

Fix: In source file lib/imap.c, function imap_perform_fetch() does this
work. Line #695 and #700 have the command string "FETCH ...", they
should be modified to "UID FETCH ...". When fixed, it gets well. See
attachment/patch 1.

2. a patch for CUSTOMREQUEST FETCH write-back

With current version 7.59, for CUSTOMREQUEST FETCH command, libcurl
just write-back "* 1 FETCH (BODY[TEXT] {322}" to user and no other
download been write-back. I think  write-back the whole download to
user is valuable. Because by url search scheme we can just get MSN not
UID, it surely need customized request to get UID, then should set
CUSTOMREQUEST to NULL for using url to fetch , but cannot directly call
CUSTOMREQUEST fetch. It's inconvenient. Hope it can get as a patch.

I tried this: lib/imap.c imap_perform() is the actual DO function. Line
#1545-1550 tells if there is a customrequest, then do
imap_perform_list(), never do imap_perform_fetch(), so we cannot get
ideal result. I add a little code in imap_perform_list() line #630:
when there is a customized FETCH or UID FETCH, change the connection
state to IMAP_FETCH(state(conn, IMAP_FETCH)), instead of IMAP_LIST. It
does. 

Customized FETCH and url FETCH command have the same function, so they
should have same state. That is the change has no influence with
IMAP_FETCH. To IMAP_LIST, it has 2 usage. One at imap_statemach_act()
line #1302 for acquiring LIST and SEARCH response, this is the place
where the above single status response line write-back to user. The
other one at imap_endofresp() line #275, which the two FETCHs have the
same logic. Maybe i guess :)

I wrote a patch with poor code for function imap_perform_list(). It
worked in my single machine Debian 9.4 with libcurl 7.52(libcurl3-
gnutls). See attachment/patch 2.

Attachment 3 is a simple test program. 

Cheers.
Kinglt

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html

  • text/x-csrc attachment: test.c
Received on 2018-05-08