Boardy
Boardy

Reputation: 36217

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'

Upvotes: 8

Views: 2200

Answers (2)

Boardy
Boardy

Reputation: 36217

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"

Upvotes: 4

ᴇʟᴇvᴀтᴇ
ᴇʟᴇvᴀтᴇ

Reputation: 12751

I wonder whether you should be using double quotes instead of single quotes?

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

Should be:

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

It looks like "STORE" etc. are being interpreted by curl as separate arguments that it's trying to treat as URLs.

Upvotes: 1

Related Questions