How \Deleted flag can be unset for all mails in cyrus-imapd mailbox

cyrusemailemail-serverimap

I have a 5GB mailbox which I moved using imapsync. But somehow I
messed up with –delete/–delete2 option and end up with almost all the messages
having \Deleted flag set. I do not have delayed expunge enabled, so
I can not use unexpunge utility. I am using cyrus-imapd v2.3.7.
Using cyrus-imapd's debugging feature I found out that email client(Roundcube in my case) fires following IMAP command to unset it.

UID STORE 179 -FLAGS.SILENT (\Deleted)

I don't know if somehow I can fire this command for all the mails.

Is there any way I can unset \Deleted flag for all the mails in the mailbox?

UPDATE:

Using @geekosaur's tip of specifying range of message-ids in the above command, I could solve it for one mailbox under INBOX like INBOX.folder1. Is there any way I can do it for multiple mailboxes under INBOX recursively? Now I am working on solving it using/creating some script, maybe using Perl's IMAP related module. But still I need to solve it asap so inputs are welcome.

UPDATE:

Thanks to geekosaur, I succeeded in solving it using Perl's IMAPClient module.

Best Answer

You can specify a range of messages start:end in place of the single message number (179 in your example); use SEARCH ALL to find out the valid message number range.

Note, this is assuming you can use raw IMAP, which can be painful to impossible if it is (as it should be) using AUTHENTICATE instead of LOGIN.. You may prefer to find an IMAP toolkit of some kind (note that Cyrus imapd comes with Perl libraries that can be used to script logging in and performing various operations, although you will need to have some familiarity with RFC 2060.

Related Topic