1

I'm trying to empty my trash folder from terminal, but i'm not able to expunge any of the items present there.

Here are the steps that i've been following

> openssl s_client -connect imap.gmail.com:993 -crlf
> a001 login USER_NAME PASSWORD
> a002 select [GMAIL]/Trash

at which i get server response as

* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $NotPhishing $Phishing)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $NotPhishing $Phishing \*)] Flags permitted.
* OK [UIDVALIDITY xxxxxxxxx] UIDs valid.
* y EXISTS
* a RECENT
* OK [UIDNEXT zzz] Predicted next UID.
* OK [HIGHESTMODSEQ bbbbbbb]
a002 OK [READ-WRITE] [Gmail]/Trash selected. (Success)

After this i've tried to delete one file (even though my goal is to delete all) using following commands

> a003 UID STORE zzz +FLAGS (\Delete)
a003 OK Success
> a004 UID EXPUNGE zzz
a004 OK Success

but no mail has been deleted from the trash folder. I've also tried by turning auto-expunge off and choosing Immediately delete the message forever under When a message is marked as deleted and expunged from the last visible IMAP folder: option.

I'm not able to find any documentation regarding the commands so any help will be greatly appreciated.

1 Answer 1

0

Assuming from your previous question that zzz is the number referenced in [UIDNEXT], that UID doesn't actually exist yet, and it is not an error to change flags of a non-existent message.

UIDNEXT represents the next UID expected to be assigned, it does not currently exist. You can do a UID SEARCH ALL to get a list of currently assigned UIDs, or don't use UIDs at all: the message sequence numbers are 1:Y (the number in the EXISTS response).

To delete all messages in Trash, first select the folder, than do:

a001 STORE 1:* +FLAGS (\Deleted)
a002 EXPUNGE

(Thanks @a1626 for correcting my STORE command)

7
  • can you elaborate on 1:Y concept. I tried using 1 like we do for fetch, EXPUNGE 1 but that threw error BAD Could not parse command.
    – a1626
    Dec 18, 2017 at 18:31
  • 1
    Yes, the non UID version of EXPUNGE does not take an ID, it just expunges everything currently marked \Deleted. When the UIDPLUS extension was defined, presumably they thought the more precise command would be more useful.
    – Max
    Dec 18, 2017 at 18:33
  • So i assume everything in Trash folder should already be marked \Deleted or will i need to do that? If yes, then how? and what will be the command to EXPUNGE ?
    – a1626
    Dec 19, 2017 at 4:34
  • 1
    No, the Trash folder is just a folder, the messages look the same as any other folder. You can mark everything as \Deleted, if you really want to, with STORE 1:* (\Deleted). 1:* means from message one to the end so is a shortcut for "everything". Then you can do EXPUNGE.
    – Max
    Dec 19, 2017 at 14:34
  • 1
    1 Small correct command to mark deleted will be STORE 1:* +FLAGS (\Deleted) instead of STORE 1:* (\Deleted).
    – a1626
    Dec 19, 2017 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.