<<< Date Index >>>     <<< Thread Index >>>

Re: Does anyone know of a mailbox merging utility?



* Chris Green <chris@xxxxxxxxxxx> [01-27-04 11:45]:
> I know it's a bit OT but does anyone know of a utility for merging
> mbox type mailboxes?  I want to merge two mailbox files in the sense
> of adding them together and then deleting all duplicate messages.
> 
> I have mbox1 and mbox2 where mbox2 will have some newer messages not
> in mbox1 and mbox1 may have some older messages not in mbox2.  I just
> want to add the newer messages from mbox2 into mbox1.
> 
> Don't say "use maildir", I have been using maildir but the
> disadvantages outweigh the advantages for me.  If I can do this merge
> then mbox format is just so much more convenient, I don't have any
> issues with locking problems, only I use the mbox files in question
> and new mail doesn't get delivered to them.
 
Procmailf(and formail) is what you want and is OT here but:

here is a sample recipe to get you started

# -------------------------------------------------------
# remove duplicates ## from man procmailex examples ##
# 12-13-2002
# -------------------------------------------------------
LOCKFILE = msgid.cache.lock

:0 Wh: msgid.lock
| formail -D 4096 msgid.cache

LOCKFILE
# -------------------------------------------------------

# -------------------------------------------------------
### deliver to mbox mail file
:0 a:
$MAILDIR/mbox.merge.to.file
# -------------------------------------------------------



and,

formail -ds procmail -m temp.procmail.rc <mbox.merge.from#1.file
formail -ds procmail -m temp.procmail.rc <mbox.merge.from#2.file

The reason for running formail twice is to get the message id numbers
from the first mbox.file into a database (msgid.cache) to check against
the second mbox.file.  They will end up in a third mbox.file which you
can rename after deleting the first two.

There may be a better way, but this should work.  As always, do not
delete the originals until you are satisfied.
-- 
Patrick Shanahan                        Registered Linux User #207535
http://wahoo.no-ip.org                        @ http://counter.li.org