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'
IMAP accounts provide several options to delete messages that aren't available in POP accounts. Tools -> Account Settings -> Account Name -> Server Settings -> "When I delete a message" has choices for "Move it to the Trash folder", "Mark it as deleted" and "Remove it immediately".
Yes, the IMAP sync deleted messages from server. It means, if you delete a message, it will get removed from the server. This article will guide you about IMAP synchronization.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With