copying and renaming mailboxes to clean up directories

Thorsten Büker mailinglists at bueker.net
Wed May 2 16:16:57 EDT 2007


Dear Andrew, hi list,

> Ack, someone using my scripts!  :)

First of all thanks for providing them!

> I bet the problem is that on a large mailbox, $imap->messages will return 
> 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 will 
> 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.

[...]

>> Furthermore I tried to rename a mailbox via cyradm in advance, but this leads 
>> to the following:
>>
>> ~~~~
>>
>> mail.myhostname.de> renm user.thorsten user.thorsten_orig
>> renamemailbox: Operation is not supported on mailbox
>>
>> ~~~~
> 
> 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"?

> If I understand you correctly, you want to get a list of "valid" UIDs from 
> 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 old 
> 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 
transferred 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 already assumed, the seen state gets lost...

Is there anything else in addition to the seen state and subscriptions, 
which needs to be kept?

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" the differences and create some kind of remove loop on filesystem 
level outside of Cyrus. But oviously this stays an idea :-/

Is this name/number the key, which you are refering to by "mailbox 
unique ID"?

Another attempt:
Are there any reasons, why something like

ORIG=`grep -R -e '^Message-ID:' $originalmbox | awk '{print $2}' | sort`
KOPIE=`grep -R -e '^Message-ID:' $copyofmbox | awk '{print $2}' | sort`

some diff and some improved awking (spaces won't work in case of spaces 
in folder names) is not a sufficient way to create a list of files, 
which might be deleted in the original mailbox?

kind regards,
   Thorsten


More information about the Info-cyrus mailing list