use MIME::Parser;
use Mail::POP3Client;
use MIME::Base64;
use MIME::QuotedPrint;
use Encode;

my $pop=Mail::POP3Client->new(
USER=>'xxxx',
PASSWORD=>'xxxxxxxx',
HOST=>'xxx.url.com.tw',
AUTH_MODE => 'PASS',
DEBUG=>0,
) or die "can't connect the server.\n";

if(($pop->Count()) < 1){
print "No messages...\n";
exit;
}

print $pop->Count() . " messages found!\n";
for($i=1; $i <= $pop->Count(); $i++) {
print $i, "\n";
foreach my $header($pop->Head($i)){
&get_subject($header);
}
my $msg=$pop->HeadAndBody($i);
my $parser=new MIME::Parser;
my $entity=$parser->parse_data($msg);
$parser->output_dir();
}
$pop->Close();

sub get_subject{
my $header=shift;
if($header =~ /^Subject:\s+=\?big5\?q\?(.*)\?=$/i){
$subject=decode_qp($1);
print $subject, "\n";
}elsif($header =~ /^Subject:\s+=\?big5\?B(.*)$/i){
$subject=decode_base64($1);
print $subject, "\n";
}elsif($header =~ /^Subject:\s+=\?utf\-8\?q\?(.*)\?=$/i){
$subject=decode_qp($1);
print encode(big5, decode(utf8, $subject)), "\n";
}elsif($header =~ /^Subject:\s+=\?utf\-8\?B(.*)$/i){
$subject=decode_base64($1);
print encode(big5, decode(utf8, $subject)), "\n";
}
}

jck11 發表在 痞客邦 PIXNET 留言(0) 人氣()