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
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:
:(colon) to enter command-line mode.
exec delete-patterncommand and press
- Enter pattern
~=, which means all duplicated files and press
Or, if default
D mapping is left untouched, just:
Dkey to activate
- Enter pattern
~=, which means all duplicated files, and press
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.
- mutt user manual on
~=and other patterns