From 6812c043f4f72c8d38990a50102c1496c006a470 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 20 May 2008 15:49:33 +0000 Subject: [PATCH] fixed: CS mail retrieval doesn't decode subject properly --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Mail/Get.pm | 117 +++++++++++++++++++++------------------ 2 files changed, 63 insertions(+), 55 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ba117cf69..122cb5b59 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 diff --git a/lib/WebGUI/Mail/Get.pm b/lib/WebGUI/Mail/Get.pm index 252d22397..eb40182ce 100644 --- a/lib/WebGUI/Mail/Get.pm +++ b/lib/WebGUI/Mail/Get.pm @@ -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; } #-------------------------------------------------------------------