LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1373|回复: 2

转移foxmail的信件到linux下

[复制链接]
发表于 2005-10-26 19:37:17 | 显示全部楼层 |阅读模式
最近有了台笔记本,终于可以按自己的心意用linux了。
不过首先得把foxmial下的信给搞过来。
找了下没找到这种工具,foxmail本身好像也不支持导出(至少俺没找到:)。
粗粗看了下foxmail的邮箱格式和mbox差不多,有一点点差别,于是用perl写了一个转换。
凑合能用,放上来共享一下。
试了试自己的信箱,没发现什么问题。但不保证真的没问题哦 ^_^

因为俺的信件比较多(万多封,4G多),导出好花了一阵子时间,不过导入evolution之后倒是可以,速度也没太受影响。
但是mutt处理这个巨大无比的mbox可真是费劲,不晓得怎么转换成maildir的格式,只好以后再说。

evolution虽然比较好用,但是好像因为版本和locale的不同,不同系统之间好像不能共用数据。至少,在俺的debian和suse之间,很容易crash:(
mutt就没有这个问题,但一来太慢,二来这个转换出来的全都不认得,一堆乱码(evolution倒是没问题),最主要的还是不熟,呵呵,没办法,只好以后再说罗~~


PS:
这次才发现foxmail的加密简直是扯淡。打开加密帐户的邮件文件夹,直接打开.box文件,全都在里头。
只有加密邮箱才算是屏蔽了这个,但也不知道到底加密强度怎么样。
所以提醒各位,在别人机器上用fox收信之后一定要把帐户,邮箱都干掉才行。

下面是文件

#!/usr/bin/env perl
# the format of Foxmail mailbox:
#  use "\x10\x10\x10\x10\x10\x10\x10\x11\x11\x11\x11\x11\x11\x53"
#     as a separator.
#  Normally, this separator take a single line.
#  And a mail is end by a single line with only '.'
#  But, there are exceptions.
#
#  Some mails with attach are not end by '.',
#    maybe followed by the separator at same line.
#  I'm not sure why this happened.
#  Maybe it's relate with "Foxmail support mail" when you setup Foxmail.
#  So, it's good idea to delete the support mail from foxmail immediatly
#    after you install foxmail.
#                        yanwuhuan 2005.10.26

my ($foxbox, $mbox) = @ARGV;
if ($#ARGV < 1)
{
        print "用法:\n" .
                "   fox2mbox.pl mailbox_for_foxmail mbox_output\n" .
                "注意:\n" .
                "   最好保证foxmail的邮箱文件是正确的。\n" .
                "   右键点击信箱,选择“属性”,先压缩一下。\n" .
                "   记住它的邮件数目,等一下好验证转换是否正确。\n" .
                "   启动工具转换,可能需要时间比较久,要保证磁盘空间。\n\n" .
                "   转换完毕,可以核对一下信件数量,看是否转换成功。\n\n" .
                "   记得在Linux下执行,因为对Perl的跨平台处理还不是很熟悉,\n" .
                "若在Windows下执行,换行符将导致MUA不认为它是邮箱文件。\n\n" .
                "   此脚本基于GPL,你可以在GPL许可证下做你想做的任何事\n" .
                "──包括使它更完善 \n\n" .
                "请将错误报告或建议寄给 <yanwuhuan\@gmail.com>。\n";
        exit(0);
}

open FOXMAIL, $foxbox || die "$!\n";
open MBOX, ">$mbox" || die "$!\n";

my $separator="\x10\x10\x10\x10\x10\x10\x10\x11\x11\x11\x11\x11\x11\x53";

my @mailhead=(), @mailbody=();

my $count=0;
my $linecount=0;

sub mailprint
{
        # find From header
        my $print_from=0;
        my $time='';
        my $from='';
        foreach (@mailhead)
        {
                if (($time eq '') and /\t.*?([a-zA-Z]+), ([0-9]{1,2}) ([a-zA-Z]+) ([0-9]+) ([0-9\:]+)/)
                {
                        $time = "$1 $3 $2 $5 $4";
                        $print_from ++;
                }
                if (($from eq '') and (/^From: .+<(.+)>$/ or /^From: (.+)/))
                {
                        $from = $1;
                        $print_from ++;
                }
        }
        if ($print_from != 2)
        {
        # for debug, if error, dump head to analyse
                my @temp = @mailhead;
                print $_, "\n" foreach (@temp);
                die "From not found: $count $linecount!\n";
        }
        print MBOX "From $from $time\n" if ($print_from==2);
       
        foreach (@mailhead)
        {
                print MBOX $_, "\n";
        }
        my $length=0;
        foreach (@mailbody)
        {
                $length = $length + length($_);
        }
        my $bodylines = $#mailbody+1;
        my $bodylength = $length + $bodylines;
        print MBOX "Content-Length: ", $bodylength, "\n";
        print MBOX "Lines: ", $bodylines, "\n";
        print MBOX "\n"; # the empty line between head and body
        foreach (@mailbody)
        {
                print MBOX $_, "\n";
        }
        @mailhead=();
        @mailbody=();
        print MBOX "\n"; # end of every mail, a empty line needed
}


# state:
# 0: not ready
# 1: reading head
# 2: reading body

my $state=0;

while (my $line = <FOXMAIL>)
{
        $line =~ s/[\r\n]*$//; # remove \r\n
        $linecount ++;
        # separator only valid at state 0, and 2
        if ((($state==0) or ($state==2))
                and (index($line, $separator,0) != -1))
        {
                #end a mail if count != 0;
                if ($count > 0)
                {
                        my $start=index($line,$separator,0);
                        if ($start != 0) # body has
                        {
                                      #push body if exists
                                $line = substr($line, 0, $start);
                                push @mailbody, $line;
                        }
                        #pop last '.' if exists;
                        pop @mailbody if ('.' eq $mailbody[$#maibody]);
                        #dump the mail;
                        $state = 0;
                        mailprint();
                }
                #start a mail;
                @mailhead = ();
                @mailbody = ();
                $state = 1;
                # anyway, a mail found
                $count ++;
                print "The $count mail found!\n";
        }
        elsif (($state==1) and (0 == index($line, "X-UIDL:",0)))
        {
                push @mailhead, $line;
                my $templine = <FOXMAIL>;
                $templine =~ s/[\r\n]*$//; # remove \r\n
                if ($templine eq '')
                { # so it must be end of head
                  # skip this line, and go mailbody
                        $state = 2;
                }
                else
                { # not end of head, go on
                        push @mailhead, $templine;
                }
        }
        else
        {
                push @mailhead, $line if ($state == 1);
                push @mailbody, $line if ($state == 2);
        }
}


if ($#mailhead + $#mailbody >0 )
{
        # print last mail
        # becase I use separator as a mark, so miss last mail
        pop @mailbody if ('.' eq $mailbody[$#maibody]);
        #print the mail;
        $state = 0;
        mailprint();
}

close MBOX;
close FOXMAIL;

print "This box have $count mails!\n";
发表于 2005-10-26 20:29:32 | 显示全部楼层
sylpheed可以转换到maildir
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-26 21:37:46 | 显示全部楼层
补一下,mutt使用没问题,是俺xterm的设置不对,呵呵。

记得mutt也可以用maildir的,俺还是想用这个,时不时欧得在几个系统下来回转转的。
suse哄老婆比较容易些~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表