Commit e75e0859 authored by VERDIN David's avatar VERDIN David
Browse files

Two bug fixes for Urlize mode:

1- message text was treated as attachment and remained on the server as either "msg.0.bin" or "msg.0.txt" files. Fixed by testing the part type before urlizing it.
2- some special characters in message id led to the attachment to be considered missing by Sympa.

I had to refactor the code a bit to allow urlizing of nested multiparts.

The detail of urlization treatment is as follows:

1- any multipart/mixed message part will be analyzed to look for urlizable parts,
2- any mulitpart/related message part will be be analyzed to look for multiârt/mixed sub parts,
3- within the multipart/mixed parts, any text/* part whose "Content-Disposition" header is not "attachment" and has a correct Content-Type.charset value is kept untouched,
4- any other subpart is kept on the server an replaced by a download link.
parent 42eb8805
......@@ -2088,7 +2088,7 @@ sub _urlize_parts {
## Only multipart/mixed messages are modified.
my $eff_type = $entity->effective_type || 'text/plain';
unless ($eff_type eq 'multipart/mixed') {
unless ($eff_type eq 'multipart/mixed' or $eff_type eq 'multipart/alternative') {
return undef;
}
......@@ -2098,31 +2098,48 @@ sub _urlize_parts {
return undef;
}
## Clean up Message-ID
my $dir1 = Sympa::Tools::Text::escape_chars($message_id);
## Clean up Message-ID and preventing double percent encoding.
my $dir1 = Sympa::Tools::Text::encode_filesystem_safe($message_id);
#XXX$dir1 = '/' . $dir1;
unless (mkdir "$expl/$dir1", 0775) {
$log->syslog('err', 'Unable to create urlized directory %s/%s',
$expl, $dir1);
return 0;
}
return _urlize_sub_parts($entity, $list, $message_id, $dir1, 0, 0);
}
sub _urlize_sub_parts {
my $entity = shift;
my $list = shift;
my $message_id = shift;
my $directory = shift;
my $is_sub_part = shift;
my $i = shift;
my @parts = ();
my $i = 0;
use Data::Dumper;
foreach my $part ($entity->parts) {
my $p = _urlize_one_part($part->dup, $list, $dir1, $i);
if (defined $p) {
my $eff_type = $part->effective_type || 'text/plain';
if ($eff_type eq 'multipart/mixed') {
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, 0, $i);
push @parts, $p;
$i++;
} elsif ($eff_type eq 'multipart/alternative' and !$is_sub_part) {
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, 1, $i);
push @parts, $p;
$i++;
} else {
push @parts, $part;
my $p = _urlize_one_part($part->dup, $list, $directory, $i);
if (defined $p) {
push @parts, $p;
$i++;
} else {
push @parts, $part;
}
}
}
if ($i) {
## Replace message parts
$entity->parts(\@parts);
}
$entity->parts(\@parts);
return $entity;
}
......@@ -2145,6 +2162,15 @@ sub _urlize_one_part {
$filename = Encode::encode_utf8($filename)
if Encode::is_utf8($filename);
} else {
my $content_disposition = $entity->head->get('Content-Disposition');
if ($entity->effective_type =~ m{\Atext}
&& (!$content_disposition
|| $content_disposition !~ m{\A\s*attachment}
)
&& $entity->head->mime_attr('content-type.charset')
){
return undef;
}
my $fileExt = Conf::get_mime_type($entity->effective_type || '')
|| 'bin';
$filename = sprintf 'msg.%d.%s', $i, $fileExt;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment