This sounds like an easy task at first. But after looking on the Internet for a working and ready to be used solution, it turned out to be not so easy to find. There were some old scripts in python, but they didn't look very promising to me. So after spending some time on search this answer to my question was found.
It requires the following steps to be taken for each set of files that need to be merged:
- Merge two (or more) files in mbox format into one file.
- Open resulting file in mutt.
- Remove all duplicated entries.
- Save mailbox file.
The first step can be done with command like this
cat mbox2 >> mbox1
or
cat mbox1 mbox2 > mbox
Personally I would recommend the second one, because it preserves original files. In case you would like to use the first one, don't forget to make backup copies first.
The second step requires properly setup mutt, which should be pointed out the file you want to work with (you are using mutt for email, don't you?).
The third step is quite easy, you just need to open the mailbox and do this:
- Press
:
(colon) to enter command-line mode. - Enter
exec delete-pattern
command and pressenter
key. - Enter pattern
~=
, which means all duplicated files and pressenter
key.
Or, if default D
mapping is left untouched, just:
- Press
D
key to activatedelete-pattern
command. - Enter pattern
~=
, which means all duplicated files, and pressenter
key.
The last step is probably will be performed by mutt automatically on exit. Say yes when and if you will be prompted about whether messages marked for the deletion should be purged.
That's it. At this point merge is completed.
See also:
- mutt user manual on
exec
command man muttrc
on~=
and other patterns