diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d5b96b059..093ea0fed 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.5.20 + - fixed: Some multipart mail messages have parts chosen incorrectly - fixed: File Pile doesn't respect edit permissions of parent asset - fixed: shortcut overrides new value column doesn't show macros as unparsed - fixed: shortcut select by alternate criteria wizard doesn't show lists properly diff --git a/lib/WebGUI/Mail/Get.pm b/lib/WebGUI/Mail/Get.pm index 24911dae7..47cf50f5a 100644 --- a/lib/WebGUI/Mail/Get.pm +++ b/lib/WebGUI/Mail/Get.pm @@ -243,32 +243,40 @@ sub parseParts { my $body = $message->bodyhandle; if (defined $body) { my $filename = $message->head->mime_attr('content-disposition.filename'); - my $decoder = Encode::find_encoding($message->head->mime_attr('content-type.charset')); + my $charset = $message->head->mime_attr('content-type.charset'); + my $decoder; + if ($charset) { + $decoder = Encode::find_encoding($charset); + } return [{ content => $decoder ? $decoder->decode($body->as_string) : $body->as_string, type => $type, - filename => $filename, + $filename ? (filename => $filename) : (), }]; } - my @parts = (); - foreach my $part ($message->parts) { - @parts = (@parts, @{$self->parseParts($part)}); - } - # deal with messages that have two or more chunks of the same content with different formatting - if ($type =~ m{multipart/alternative}i) { - my $first = {}; - my @others = (); - foreach my $part (reverse @parts) { - if ($first->{type} eq "" && ($part->{type} eq "text/html" || $part->{type} eq "text/plain")) { - $first = $part; - } else { - push @others, $part; - } - } - $first->{alternative} = \@others; - return [$first]; - } - return \@parts; + if ($type =~ m{multipart/alternative}i) { + foreach my $part (reverse $message->parts) { + my $parsedParts = $self->parseParts($part); + my $supported = 1; + foreach my $parsedPart (@$parsedParts) { + # we support html, text, and attachments + if ($parsedPart->{type} !~ /^text\/html/ && $parsedPart->{type} !~ /^text\/plain/ && !$parsedPart->{filename}) { + $supported = 0; + } + } + if ($supported) { + return $parsedParts; + } + } + return []; + } + else { + my @parts; + foreach my $part ($message->parts) { + push @parts, @{ $self->parseParts($part) }; + } + return \@parts; + } } #-------------------------------------------------------------------