我正在尝试使用以下代码,但我还无法测试,因为我收到以下错误:
#!/usr/bin/perl
use warnings;
use strict;
use Text::Wrap;
use Mail::Box::Manager;
use HTML::Obliterate qw(extirpate_html);
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;
if ( $msg->isMultipart ) {
foreach my $part ( $msg->parts ) {
if ( $part->contentType eq 'text/html' ) {
my $nohtml = extirpate_html( $msg );
$body =~ s/^>.*$//msg;
$Text::Wrap::columns=80;
print MYFILE wrap("", "", <<"");
\n
From: $from
To: $to
Date: $date
Subject: $subject
\n
$body
}
else {
$body =~ s/^>.*$//msg;
$Text::Wrap::columns=80;
print MYFILE wrap("", "", <<"");
\n
From: $from
To: $to
Date: $date
Subject: $subject
\n
$body
}
}}
所有的大括号似乎都匹配,所以我不确定问题出在哪里
syntax error at x.pl line 46, near "else"
(Might be a runaway multi-line << string starting on line 36)
Missing right curly or square bracket at x.pl line 63, at end of line
syntax error at x.pl line 63, at EOF
Execution of x.pl aborted due to compilation errors.
编辑:
它现在可以工作了,但是 html 没有条带化:取而代之的是几封电子邮件,其中包含
>
> 之类的东西交错贯穿,导致它的页面比应有的多得多。有一个更好的方法吗