fixed: Some multipart mail messages have parts chosen incorrectly

This commit is contained in:
Graham Knop 2008-08-14 15:45:13 +00:00
parent d721cafc8e
commit 7f095970c6
2 changed files with 30 additions and 21 deletions

View file

@ -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

View file

@ -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;
}
}
#-------------------------------------------------------------------