如何删除mbox格式电子邮箱的重复项(重复数据删除)?

时间:2012-05-09 19:06:43

标签: parsing email deduplication mbox

我有一个mbox邮箱,其中包含重复的邮件副本,这些邮件的区别仅在于其“X-Evolution:”标题。

我希望尽可能快速简单地删除重复的内容。看起来这已经写好了,但是我还没有找到它,虽然我看过Python邮箱模块,各种perl mbox解析器,formail等等。

有人有任何建议吗?

3 个答案:

答案 0 :(得分:6)

这就是我使用的:

rm -f idcache; \
zcat archive_2012.gz  | \
formail -D $((1024*1024*10)) idcache -s | \
gzip -9c  > archive_2012-dedup.gz
  1. 删除旧的缓存条目
  2. 将旧文件解压缩到stdout
  3. 运行formail作为过滤器(具有10兆字节缓存,称为idcache,stdout-to-stdout)
  4. 动态重新压缩重复数据删除的流并将其转储到新文件中
  5. 经过一些检查后,我用新文件覆盖旧文件。

    formail是procmail实用程序的一部分

答案 1 :(得分:0)

我没有详细查看formail(procmail的一部分)。 确实有这样的选项,例如:http://hints.macworld.com/comment.php?mode=view&cid=115683http://us.generation-nt.com/answer/deleting-duplicate-mail-messages-help-172481881.html

答案 2 :(得分:0)

' formail -D'和'重新格式-D'每次执行只能处理一封电子邮件。在处理之前,每个邮件都需要先与mbox分开。我使用来自maildrop的reformail,因为它仍在积极开发中。

  1. 删除旧的idcache,tmpmail,nmbox
  2. 运行dedup.sh。
  3. nmbox是删除了重复邮件的输出。
  4. <强> dedup.sh

    #! /bin/sh
    # $1 = mbox, thunderbird mailbox
    # wmbox.sh is called for each mail.
    
    cat $1 | reformail -s ./wmbox.sh
    

    <强> wmbox.sh

    #! /bin/sh
    # stdin: a email
    # called by dedup.sh
    
    TM=tmpmail
    if [ -f $TM ] ; then
       echo error!
       exit 1
    fi
    cat > $TM
    # mbox format, each mail end with a blank line
    echo "" >> $TM
    
    cat $TM | reformail -D 99999999 idcache
    
    # if this mail isn't a dup (reformail return 1 if message-id is not found)
    if [ $? != 0 ]; then
       # each mail shall have a message-id
       if grep -q -i '^message-id:' $TM; then
          cat tmpmail >> nmbox
       fi
    fi
    
    rm $TM