Re: Fetching emails via imap without setting the "\Seen" flag (i.e. using BODY.PEEK)
Date: Sun, 31 Mar 2019 16:15:47 +0200
On Fri, 15 Mar 2019 at 09:25, Daniel Stenberg <daniel_at_haxx.se> wrote:
> This is hardly an approach that we can use in curl so while this might fix
> Luca's current problem, it is not a patch we can merge as-is.
> I would be interested in discussing what we should or could do to support this
> feature in a more proper and curl-friendly way.
Hello Daniel, after my initial quick modification, I have spent some time analyzing curl IMAP implementation and I'm confident that the attached patch is a good implementation of the fetch of a message body via custom request, which has the advantage (over the fetch via URL) to allow the usage of body.peek in order not to change the \Seen flag of the fetched message.
Hereunder are the accepted custom requests to fetch a message body:
- FETCH <id> (BODY[<section>]<<partial>>)
- FETCH <id> (BODY.PEEK[<section>]<<partial>>)
- UID FETCH <uid> (BODY[<section>]<<partial>>)
- UID FETCH <uid> (BODY.PEEK[<section>]<<partial>>)
where <id> and <uid> are mandatory numbers, while <section>, <<partial>> and ( ) are optional.
The implementation is straightforward and reuses existing code and current IMAP state machine logic as much as possible, because fetching a message via custom request has just a different syntax, but the interworking logic with the IMAP server is the same as fetching a message via URL.
I have added a new local function ( is_custom_fetch_body_request ) to lib/imap.c, to parse the custom request and check for the above formats.
I have modified the imap_perform_list function (lib/imap.c), where all custom requests are executed, in order to check if the request is a fetch of a message body and make the IMAP state machine transit into the IMAP_FETCH state (similarly to fetch via URL).
If possible, I would like to have this little feature included in curl, in order to avoid modifying and recompiling each new release of curl.
I think it's a very simple yet powerful enhancement of IMAP functionality of curl, because not only it allows the full fetch of a message (with sections and partial) via custom request, but also the usage of body.peek to leave the \Seen flag unchanged. I believe this enhancement could be useful to others too.
Please, let me know if the patch is ok with you and if I have to do anything else (e.g. write new tests ?) to have the feature added to curl.
Thank you and kind regards,
Received on 2019-03-31