Contribute  :  Advanced Search  :  Directory  :  Forum  :  FAQ's  :  My Downloads  :  Links  :  Polls  
AFP548 Changing the world one server at a time.
Welcome to AFP548
Thursday, July 29 2010 @ 09:24 am MDT
   

Cyrus IMAP Mailbox Recovery

Articles

I've occasionally encountered IMAP mailboxes that were unreadable and undeletable using any mail client. In Mac OS X Mail, this usually produces an "Unable to Select" error.

Here's how to fix the server-side mailbox. At the bottom is a bonus: how to recover the locally cached .imapmbox file from Mail.



I learned how to do these steps from two web pages: Bynari Support and Code Comments.

Step 1: Backup the locally-cached mail

The file will be inside ~/Library/Mail/IMAP-email-address, with an extension ".imapmbox". Copy this file to your Desktop.

Step 2: Repairing the Cyrus folder

  1. Use Server Admin to stop the mail server
  2. Change to root, and enter the directory /var/imap:

    # sudo -s
    # cd /var/imap
  3. backup mailboxes.db:

    # cp mailboxes.db mailboxes.db-backup
  4. Using Workgroup Manager, set user cyrus's shell to bash

  5. (Ed. note: Rather than give cyrus a shell you could just use sudo -u cyrus to do the following steps.)
  6. su to cyrus, and dump the database to a text file:

    # su cyrus
    # /usr/bin/cyrus/bin/ctl_mboxlist -d > /tmp/mboxlist.txt
  7. Edit the text file and remove the lines that contain the problem folders:

    # pico /tmp/mboxlist.txt
    
  8. remove mailboxes.db:

    # rm mailboxes.db
  9. rebuild mailboxes.db from the new text file:

    # cat /tmp/mboxlist.txt | /usr/bin/cyrus/bin/ctl_mboxlist -u
  10. Reconstruct all mailboxes

    # /usr/bin/cyrus/bin/reconstruct -r -f user

    If there are any remaining folders that print an error, they'll be listed when performing cyrus reconstruct: (ie.. user.someuser: Mailbox does not exist).

  11. Exit back from cyrus and root

    # exit
    # exit
  12. Using Workgroup Manager, set user cyrus's shell back to /usr/bin/false.
  13. Restart Mail using Server Admin

Step Three: Recovering a locally-cached imapmbox

  1. Create a fake imap email account. Don't use a real name or password. We want the account to remain offline.

  2. Quit Mail

  3. In the Finder, open the directory holding the newly-created INBOX.imapmbox file (It's in ~/Library/Mail/IMAP-something/").

  4. Move this (empty) INBOX.imapmbox to the trash.

  5. Move the cached mail file you had copied to the Desktop to this folder. Rename the file to "INBOX.imapmbox".

  6. Start Mail again, and click on the new account name. Your messages should reappear.

  7. Copy the messages from this folder to another one, either IMAP or locally.

  8. In Mail's preferences, delete the account you had created.

Make sure you keep this fake account offline, or else Mail will overwrite your cached mailbox with an empty one!

Story Options

Advertising

Cyrus IMAP Mailbox Recovery | 11 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Cyrus IMAP Mailbox Recovery
Authored by: hkmacs on Thursday, August 26 2004 @ 04:05 am MDT
I'm having a problem whereby now after running the server quite happily for
4 months if I create a new user on the Server in Mail when I try to access the
account I get "IMAP command “SELECT” failed" so I'm presuming this is the
same problem. However when I follow your steps, when I enter su cyrus, I get
su:Sorry. What am I doing wrong?
Recovering one user's mailbox
Authored by: rshah on Thursday, October 07 2004 @ 11:57 pm MDT
To reconstruct one mailbox just use this command
sudo -u cyrus /usr/bin/cyrus/bin/reconstruct -r -f user/xxx

I found this at:
http://www.macosxhints.com/article.php?story=20040914201805804

and remember to stop the server before doing this
Cyrus IMAP Mailbox Recovery
Authored by: Anonymous on Wednesday, November 30 2005 @ 03:48 pm MST
This operation just save my life! Thanks!
Cyrus IMAP Mailbox Recovery
Authored by: Anonymous on Tuesday, January 27 2009 @ 07:45 am MST
Thank you guys. You've saved my day. Over a month I have got curious errors like deliver[23437]: DBERROR: dbenv->open '/var/lib/imap/db' failed: Permission denied deliver[2222]: DBERROR: dbenv->open '/var/lib/imap/db' failed: Permission denied Jan 27 11:58:53 f2 deliver[2222]: DBERROR: init() on berkeley Jan 27 12:02:20 f2 deliver[2766]: DBERROR: dbenv->open '/var/lib/imap/db' failed: Permission denied Jan 27 12:02:20 f2 deliver[2766]: DBERROR: init() on berkeley Jan 27 12:02:47 f2 deliver[2828]: DBERROR: dbenv->open '/var/lib/imap/db' failed: Permission denied Jan 27 12:02:47 f2 deliver[2828]: DBERROR: init() on berkeley or ctl_cyrusdb[25540]: DBERROR: archive /var/lib/imap/db: cyrusdb error Jan 27 10:56:04 f2 ctl_cyrusdb[25540]: DBERROR: error archiving log file: /var/lib/imap/db/log.0000000333 Jan 27 10:56:04 f2 ctl_cyrusdb[25540]: DBERROR: archive /var/lib/imap/db: cyrusdb error Jan 27 10:56:04 f2 ctl_cyrusdb[25540]: DBERROR: error archiving database file: /var/lib/imap/mailboxes.db Jan 27 10:56:04 f2 ctl_cyrusdb[25540]: DBERROR: archive /var/lib/imap/db: cyrusdb error Jan 27 10:56:04 f2 ctl_cyrusdb[25540]: DBERROR: error archiving log file: /var/lib/imap/db/log.0000000333 Jan 27 10:56:04 f2 ctl_cyrusdb[25540]: DBERROR: archive /var/lib/imap/db: cyrusdb error I tried db_recover on the db files with no results. After reconstructing my mailboxes.db file, which contained one bad subfolder, all errors vanished. Thank you! Gerhard Lehmann