Deleting a message over imap using curl
Asked Answered
F

2

8

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'
Fuchsin answered 26/10, 2018 at 18:17 Comment(2)
curl --version ?Clownery
I've been trying on Window 10, version 7.55.1Fuchsin
F
4

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"
Fuchsin answered 30/10, 2018 at 18:56 Comment(0)
N
1

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.

Nikolai answered 26/10, 2018 at 18:19 Comment(4)
I was but now I've put that in I get exactly the same response so that's a bit odd so unfortunately hasn't helped :(Fuchsin
It doesn't come up with any errors error now, although doesn't delete the email eitherFuchsin
guess so thought the deleting would be the easy bit :(Fuchsin
Try putting \r\n on the end of the -X part and brackets round \Deleted. I.e. -X "UID STORE 1 +Flags (\Deleted)\r\n"Slender

© 2022 - 2024 — McMap. All rights reserved.