fixed: CS mail retrieval doesn't decode subject properly

This commit is contained in:
Graham Knop 2008-05-20 15:49:33 +00:00
parent dc8b887cca
commit 6812c043f4
2 changed files with 63 additions and 55 deletions

View file

@ -64,6 +64,7 @@
- add: Delete multiple revisions from a version tag at the same time
- add: Approval activities now have a better parent class and more
flexibility (multiple groups to approve, do on approve)
- fixed: CS mail retrieval doesn't decode subject properly
7.5.10
- fix: Syntax error in GetCsMail

View file

@ -21,6 +21,7 @@ use MIME::Parser;
use LWP::MediaTypes qw(guess_media_type);
use WebGUI::Group;
use WebGUI::User;
use Encode qw(decode);
=head1 NAME
@ -157,61 +158,67 @@ sub getNextMessage {
my $parsedMessage = $parser->parse_data($rawMessage);
if (defined $parsedMessage) {
$self->{_pop}->delete($id);
} else {
$self->session->errorHandler->error("Could not parse POP3 message $id");
return undef;
}
my $head = $parsedMessage->head;
my $type = $head->get("Content-Type");
# try to detect auto generated messages and drop them
my $skipAuto = 0;
my @headlines = split("\n",$head->stringify);
foreach my $headline (@headlines) {
$skipAuto = 1 if ($headline =~ m/^X-Auto/);
$skipAuto = 1 if ($headline =~ m/^X-Mirror/);
}
my $returnPath = $head->get("Return-Path");
chomp($returnPath);
$skipAuto = 1 if ($returnPath eq "<>");
my $precedence = $head->get("Precedence");
chomp($precedence);
$skipAuto = 1 if ($precedence eq "bulk");
$skipAuto = 1 if ($precedence eq "junk");
$skipAuto = 1 if ($head->get("Content-Type") =~ m/multipart\/report/);
$skipAuto = 1 if ($head->get("Content-Type") =~ m/report-type=.*delivery-status/);
my $to = $head->get("To") || undef;
chomp($to);
my $from = $head->get("From") || undef;
chomp($from);
my $messageId = $head->get("Message-Id") || undef;
chomp($messageId);
if ($skipAuto) { # drop autogenerated messages
$self->session->errorHandler->info("POP3: Dropped auto generated message ".$messageId." from ".$from." to ".$to);
return $self->getNextMessage;
}
my $cc = $head->get("Cc") || undef;
chomp($cc);
my $subject = $head->get("Subject") || undef;
chomp($subject);
my $inReplyTo = $head->get("In-Reply-To") || $head->get("References") || undef;
chomp($inReplyTo);
my %data = (
rawMessage=> $rawMessage,
to => $to,
from => $from,
cc => $cc,
subject => $subject,
inReplyTo => $inReplyTo,
messageId => $messageId,
"Return-Path" => $returnPath,
date => $self->session->datetime->mailToEpoch($head->get("Date")),
);
$data{parts} = $self->parseParts($parsedMessage);
unless (scalar(@{$data{parts}}) > 0) { # drop empty messages
$self->session->errorHandler->info("POP3: Dropped empty message ".$data{messageId}." from ".$data{from}." to ".$data{to});
return $self->getNextMessage;
}
return \%data;
}
else {
$self->session->errorHandler->error("Could not parse POP3 message $id");
return undef;
}
my $head = $parsedMessage->head;
my $type = $head->get("Content-Type");
# try to detect auto generated messages and drop them
my $skipAuto = 0;
my @headlines = split("\n",$head->stringify);
foreach my $headline (@headlines) {
$skipAuto = 1
if $headline =~ m/^X-Auto/
|| $headline =~ m/^X-Mirror/;
}
my $returnPath = decode('MIME-Header', $head->get("Return-Path"));
chomp $returnPath;
$skipAuto = 1
if $returnPath eq "<>";
my $precedence = decode('MIME-Header', $head->get("Precedence"));
chomp $precedence;
$skipAuto = 1
if $precedence eq "bulk"
|| $precedence eq "junk"
|| $head->get("Content-Type") =~ m/multipart\/report/
|| $head->get("Content-Type") =~ m/report-type=.*delivery-status/;
my $to = decode('MIME-Header', $head->get("To")) || undef;
chomp $to;
my $from = decode('MIME-Header', $head->get("From")) || undef;
chomp $from;
my $messageId = decode('MIME-Header', $head->get("Message-Id")) || undef;
chomp $messageId;
if ($skipAuto) { # drop autogenerated messages
$self->session->errorHandler->info("POP3: Dropped auto generated message ".$messageId." from ".$from." to ".$to);
return $self->getNextMessage;
}
my $cc = decode('MIME-Header', $head->get("Cc")) || undef;
chomp $cc;
my $subject = decode('MIME-Header', $head->get("Subject")) || undef;
chomp $subject;
my $inReplyTo = decode('MIME-Header', $head->get("In-Reply-To") || $head->get("References")) || undef;
chomp $inReplyTo;
my %data = (
rawMessage => $rawMessage,
to => $to,
from => $from,
cc => $cc,
subject => $subject,
inReplyTo => $inReplyTo,
messageId => $messageId,
"Return-Path" => $returnPath,
date => $self->session->datetime->mailToEpoch($head->get("Date")),
);
$data{parts} = $self->parseParts($parsedMessage);
unless (scalar(@{$data{parts}}) > 0) { # drop empty messages
$self->session->errorHandler->info(
"POP3: Dropped empty message ".$data{messageId}." from ".$data{from}." to ".$data{to}
);
return $self->getNextMessage;
}
return \%data;
}
#-------------------------------------------------------------------