How to recover mailbox for cyrus-imap?

From the guide, we know that cyrus saves emails in mailboxes under /var/spool/imap/. But deleting mailbox is not equal to deleting the folders and files in /var/spool/imap/. If you just remove the directories under /var/spool/imap/, you will get the error like:

IOERROR: opening /var/spool/imap/a/user/admin/cyrus.header: No such file or directory(for IMAP)

Or,

IOERROR: opening /var/spool/imap/a/user/admin/cyrus.header: No such file or directory
Unable to open maildrop user.admin: System I/O error(for POP3)

After you remove the folders, you can not even operate on the mailbox in cyradm such as:

sam user.admin admin all

setaclmailbox: admin: lrswiklxtja: System I/O error

If you accidentally erased the folders inĀ  /var/spool/imap/, how to recover the mailbox? You can use the reconstruct command in cyradm:

cyradm -u admin localhost

reconstruct user.admin

cyrus will recover the folders pertaining to the mailbox.

The correct way to delete a user’s mailbox is:

  1. Create another user other than the user whose mailbox is to be deleted: saslpasswd2 -c -u domainhostseotool.com cyrus
  2. list the new user(cyrus) in the “admins:” parameter in /etc/imapd.conf
  3. restart cyrus-imapd service
  4. login cyradm as the new user(cyrus): cyradm -u cyrus localhost
  5. Grant all privileges of to-be-deleted mailbox to the new user:sam user.admin cyrus all
  6. delete the mailbox: dm user.admin

Deleting the mailbox of current login user is prohibited:

localhost.localdomain> dm user.admin
deletemailbox: Operation is not supported on mailbox

Deleting other user’s mailbox is also prohibited if no privilege is granted to the current user:

localhost.localdomain> dm user.admin
deletemailbox: Permission denied

Here are common used cyradm commands:

  • create a mailbox: cm user.admin
  • list mailboxes in the system: lm
  • set ACL on a mailbox:sam user.admin
  • delete a mailbox: dm user.admin
  • quit cyradm:quit

Reference: http://doc.norang.ca/cyrus-imap-server.html

Posted in tips of hosting