Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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?


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.


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

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
thanks a lot, you have saved my day. By specifying range I could solve it for one of the mailbox under INBOX. I have multiple mailboxes under INBOX like INBOX.folder1, INBOX.folder2 etc. Is there any way to use this functionality recursively? – Sachin Divekar Apr 9 '12 at 3:15
Not with the standard IMAP protocol; you need to SELECT each folder individually. – geekosaur Apr 9 '12 at 3:17
thanks for your tips. I have started working on it. Still I am keeping the question open for some time. – Sachin Divekar Apr 9 '12 at 4:03
Unfortunately, as presently designed the protocol doesn't really support multifolder operations (note how the notion of current folder is built into the protocol, and how hierarchy is kinda hacked in with various special flags in LIST etc.). IMAP is overdue for a redesign for better multifolder support, but various proposed extensions for it have languished. – geekosaur Apr 9 '12 at 4:12
thanks geekosaur, I succeeded in solving it using Perl's IMAPClient module. I will soon post my solution on my blog and post the link here. – Sachin Divekar Apr 10 '12 at 14:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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