curl / Mailing Lists / curl-library / Single Mail

curl-library

RE: Fetching emails via imap without setting the "\Seen" flag (i.e. using BODY.PEEK)

From: Luca Di Rocco via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 14 Mar 2019 23:24:18 +0100

Hello,

> On Wed, 13 Mar 2019, Christian Schmitz via curl-library wrote:
> we use
>
> "UID FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS
> (Message-Id DATE FROM SUBJECT TO SENDER REPLY-TO CC BCC)])"
>
> As custom command for CURL.
> Than we grab result from debug log.
>

thanks for your suggestion.

However, instead of developing a script to get the needed info from the
debug log, I have modified curl (imap.c file) in order to fetch a message
for one of the following custom commands:
1) FETCH <id> (BODY.PEEK[<section>]<<partial>>)
2) FETCH <id> (BODY[<section>]<<partial>>)
3) UID FETCH <uid> (BODY.PEEK[<section>]<<partial>>)
4) UID FETCH <uid> (BODY[<section>]<<partial>>)
where <section>, <<partial>> and () are optional

Since I didn't have so much time to investigate and understand all the
software structure, I focused on imap.c and implemented a simple trick.
In the imap_state_select_resp function, after a custom command is
successfully sent, I parse the command to check if it meets one of the 4
formats above.
If so, I change the state to IMAP_FETCH.

I run all the tests, they work with the exception of test841, because the
test custom command -X 'FETCH 123 BODY[1]' now has a different behavior.

I have attached the patch file, it's just consists of a new function to
parse the custom command and very few lines of code in the the
imap_state_select_resp function.
Please let me know if the modification can be useful to anybody or instead a
similar functionality should be implemented differently according to the
curl design principles.
In the latter case, I will use it just for my ongoing application, in the
hope that one day curl will properly support BODY.PEEK via custom command.

Thanks and BR,
Luca Di Rocco

Received on 2019-03-14