copying and renaming mailboxes to clean up directories

Andrew Morgan morgan at
Wed May 2 17:24:30 EDT 2007

On Wed, 2 May 2007, Thorsten B=FCker wrote:

>> I bet the problem is that on a large mailbox, $imap->messages will retur=
n a =

>> really big list of UIDs (longer than the allowed MAXWORD of 32768).  You =

>> may be able to fix this by calling "$imap->Ranges(1);" earlier in the =

>> script.  According to the Mail::IMAPClient docs, with that enabled it wi=
ll =

>> try to generate a condensed list of UIDs when possible.
> Yes, it works fine. In case somebody likes to test, I added =

> "$imap1->Ranges(1);" to line 90.

Great, I added that to my local copy.

>> Did you set "allowusermoves: 1" in imapd.conf?
> I did, but it shows no effect. Indeed "man imapd.conf" doesn't list this =

> option -- is it already implemented in "2.1.18-1+sarge2"?

Hmm, I'm using v2.2.13 here.  Maybe that option/feature didn't exist in =


>> If I understand you correctly, you want to get a list of "valid" UIDs fr=
om =

>> the folder listing, and then delete (from the filesystem) anything which=
 is =

>> not in that list of "valid" UIDs?
>> Or do you intend to just copy the mailbox to a new mailbox, delete the o=
ld =

>> mailbox, and copy it back?  That sounds pretty reasonable to me.  One =

>> problem you might have is the loss of the seen state for each mailbox =

>> because the mailbox unique ID will change with the copy.  The unique ID =
is =

>> stored in the cyrus.header file in each mailbox/folder, so you might be =

>> able to save those and copy them back as you go.
> I just hat some tries on the latter way.
> Beside the seen state the subscription list of a user needs to be transfe=
rred =

> in some way. Manually duplicating thorsten.sub to thorsten_neu.sub =

> (overwritten file of copied mailbox) and modifiying the file lead to a =

> restore of subscription on the new (temporary) mailbox. But, as you alrea=
dy =

> assumed, the seen state gets lost...
> Is there anything else in addition to the seen state and subscriptions, w=
hich =

> needs to be kept?

You should probably check if other message flags (Important, Answered, =

etc) are copied.  I can't remember.

> Furthermore I must admit, that I wasn't aware right now, that by copying =
a =

> mailbox the name/number of a mail in the filesystem changes, too. I just =
had =

> the idea to copy a mailbox, execute "find" in both directories, "diff" th=
e =

> differences and create some kind of remove loop on filesystem level outsi=
de =

> of Cyrus. But oviously this stays an idea :-/
> Is this name/number the key, which you are refering to by "mailbox unique =

> ID"?

Have a look at any cyrus.header file and you'll see something like:

Cyrus mailbox header
"The best thing about this system was that it had lots of goals."
         --Jim Morris on Andrew
user.morgan     3e671c013f511626
morgan  lrswipcda

The string "3e671c013f511626" is the unique mailbox ID for this particular =

mailbox.  It is the key value used in the seen files to track which =

message UIDs have been seen for each mailbox.

> Another attempt:
> Are there any reasons, why something like
> ORIG=3D`grep -R -e '^Message-ID:' $originalmbox | awk '{print $2}' | sort`
> KOPIE=3D`grep -R -e '^Message-ID:' $copyofmbox | awk '{print $2}' | sort`
> some diff and some improved awking (spaces won't work in case of spaces i=
n =

> folder names) is not a sufficient way to create a list of files, which mi=
ght =

> be deleted in the original mailbox?

That sounds like a reasonable approach, but obviously you should be =

careful anytime you modify the cyrus files directly.  :)


More information about the Info-cyrus mailing list