2

我正在尝试修改以下程序以确保使用 Encode::decode() 将每个 msg 转换为 utf-8,但我不确定如何以及在何处放置它以使其工作。

#!/usr/bin/perl
use warnings;
use strict;
use Mail::Box::Manager;

open (MYFILE, '>>data.txt');
binmode(MYFILE, ':encoding(UTF-8)');


my $file = shift || $ENV{MAIL};
my $mgr = Mail::Box::Manager->new(
    access          => 'r',
);

my $folder = $mgr->open( folder => $file )
or die "$file: Unable to open: $!\n";

for my $msg ( sort { $a->timestamp <=> $b->timestamp } $folder->messages)
{
    my $to          = join( ', ', map { $_->format } $msg->to );
    my $from        = join( ', ', map { $_->format } $msg->from );
    my $date        = localtime( $msg->timestamp );
    my $subject     = $msg->subject;
    my $body        = $msg->decoded->string;

    # Strip all quoted text
    $body =~ s/^>.*$//msg;

    print MYFILE <<"";
From: $from
To: $to
Date: $date
Subject: $subject
\n
$body

}
4

2 回答 2

0

脚本中的任何内容似乎都没有指定您期望输入的编码......通常这很重要,因为自动检测硬字符编码(并且通常不被编码库支持)。

于 2008-12-16T19:53:59.887 回答
0

从我怀疑你想替换的文档中

my $body        = $msg->decoded->string;

my $body        = $msg->decoded('UTF-8')->string;

虽然我不完全确定,也可能根本不重要。

于 2008-12-16T20:44:33.280 回答