Search code examples
curlimapgmail-imap

Deleting a message over imap using curl


I am working on a project where I need to read messages in an inbox on an imap server, process it and then delete the email from the inbox.

I can successufully get the email without any issue, the problem I am having is the delete.

I can fetch the email using the following:

curl --url "imaps://imap.gmail.com:993/inbox;UID=1" --user "user:password"

This works perfectly fine for getting the email, I successfully process it without issue so now when I try and delete it I use the following:

curl --url "imaps://imap.gmail.com:993/inbox;UID=1" --user "user:password" -X 'UID STORE 1 +Flags \Deleted'

But I then get the following response:

curl: (21) Quote command returned error
curl: (6) Could not resolve host: STORE
curl: (6) Could not resolve host: 1
curl: (6) Could not resolve host: +Flags
curl: (6) Could not resolve host: \Deleted'

Solution

  • I finally found the answer, it seems like gmail is slightly different to every other example but found an example that works:

    The following works:

    curl --url "imaps://imap.gmail.com:993/Inbox;UID=1" --user "user:password" -X "STORE 1 +Flags \Deleted"
    

    Followed by

    curl --url "imaps://imap.gmail.com:993/Inbox;UID=1" --user "user:password" -X "EXPUNGE"