Commit 649a0bcc authored by IKEDA Soji's avatar IKEDA Soji
Browse files

tyidyall

parent 69c9e749
......@@ -969,12 +969,11 @@ our @params = (
'message_header,message_header.mime,message_footer,message_footer.mime,info',
'vhost' => '1',
},
{
'name' => 'family_signoff',
{ 'name' => 'family_signoff',
'gettext_id' => 'Global unsubscription',
'default' => 'auth', # Compat. to <=6.2.52
'scenario' => 1,
'vhost' => '1',
'default' => 'auth', # Compat. to <=6.2.52
'scenario' => 1,
'vhost' => '1',
},
{'gettext_id' => 'Tag based spam filtering'},
......
......@@ -356,7 +356,7 @@ sub get_uncompellable_param {
# OUT : -directory name or undef if the directory does not exist
sub _get_directory {
$log->syslog('debug3', '(%s)', @_);
my $self = shift;
my $self = shift;
my $name = $self->{'name'};
my $robot = $self->{'domain'};
......
......@@ -647,8 +647,7 @@ sub check_dkim_signature {
return unless $Mail::DKIM::Verifier::VERSION;
my $robot_id =
(ref $self->{context} eq 'Sympa::List')
? $self->{context}->{'domain'}
(ref $self->{context} eq 'Sympa::List') ? $self->{context}->{'domain'}
: (ref $self->{context} eq 'Sympa::Family')
? $self->{context}->{'domain'}
: $self->{context};
......@@ -1575,9 +1574,9 @@ sub personalize_text {
my $listname = $list->{'name'};
my $robot_id = $list->{'domain'};
$data->{'listname'} = $listname;
$data->{'domain'} = $robot_id;
$data->{'robot'} = $data->{'domain'}; # Compat.<=6.2.52.
$data->{'listname'} = $listname;
$data->{'domain'} = $robot_id;
$data->{'robot'} = $data->{'domain'}; # Compat.<=6.2.52.
$data->{'wwsympa_url'} = Conf::get_robot_conf($robot_id, 'wwsympa_url');
my $message_output;
......@@ -2096,7 +2095,9 @@ sub _urlize_parts {
## Only multipart/mixed messages are modified.
my $eff_type = $entity->effective_type || 'text/plain';
unless ($eff_type eq 'multipart/mixed' or $eff_type eq 'multipart/alternative' or $eff_type eq 'multipart/related') {
unless ($eff_type eq 'multipart/mixed'
or $eff_type eq 'multipart/alternative'
or $eff_type eq 'multipart/related') {
return undef;
}
......@@ -2121,23 +2122,34 @@ sub _urlize_sub_parts {
my $entity = shift;
my $list = shift;
my $message_id = shift;
my $directory = shift;
my $i = shift;
my @parts = ();
my $directory = shift;
my $i = shift;
my @parts = ();
use Data::Dumper;
my $parent_eff_type = $entity->effective_type();
foreach my $part ($entity->parts) {
my $eff_type = $part->effective_type || 'text/plain';
if ($eff_type eq 'multipart/mixed') {
$i++;
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, $i);
my $p =
_urlize_sub_parts($part->dup, $list, $message_id, $directory,
$i);
push @parts, $p;
} elsif (($eff_type eq 'multipart/alternative' or $eff_type eq 'multipart/related') and $i < 2) {
} elsif (
( $eff_type eq 'multipart/alternative'
or $eff_type eq 'multipart/related'
)
and $i < 2
) {
$i++;
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, $i);
my $p =
_urlize_sub_parts($part->dup, $list, $message_id, $directory,
$i);
push @parts, $p;
} else {
my $p = _urlize_one_part($part->dup, $list, $directory, $i, $parent_eff_type);
my $p = _urlize_one_part($part->dup, $list, $directory, $i,
$parent_eff_type);
if (defined $p) {
push @parts, $p;
$i++;
......@@ -2146,18 +2158,18 @@ sub _urlize_sub_parts {
}
}
}
$entity->parts(\@parts);
return $entity;
}
sub _urlize_one_part {
my $entity = shift;
my $list = shift;
my $dir = shift;
my $i = shift;
my $parent_eff_type = shift;
my $entity = shift;
my $list = shift;
my $dir = shift;
my $i = shift;
my $parent_eff_type = shift;
return undef unless ($parent_eff_type eq 'multipart/mixed');
my $expl = $list->{'dir'} . '/urlized';
......@@ -2173,13 +2185,13 @@ sub _urlize_one_part {
$filename = Encode::encode_utf8($filename)
if Encode::is_utf8($filename);
} else {
my $content_disposition = lc($entity->head->mime_attr('Content-Disposition') // '');
my $content_disposition =
lc($entity->head->mime_attr('Content-Disposition') // '');
if ($entity->effective_type =~ m{\Atext}
&& (!$content_disposition
|| $content_disposition eq 'attachment'
)
&& ( !$content_disposition
|| $content_disposition eq 'attachment')
&& $entity->head->mime_attr('content-type.charset')
){
) {
return undef;
}
my $fileExt = Conf::get_mime_type($entity->effective_type || '')
......
......@@ -175,9 +175,7 @@ sub new {
$data->{'list'}{'domain'} = $list->{'domain'};
$data->{'list'}{'host'} = $list->{'domain'};
} elsif ($family) {
$data->{family} = {
name => $family->{'name'},
};
$data->{family} = {name => $family->{'name'},};
}
# Sign mode
......
......@@ -567,7 +567,8 @@ sub _compile_scenario {
my $required = join "\n", map {
my $req;
if ($_ eq 'list_object') {
$req = 'die "No list context" unless ref $that eq \'Sympa::List\';';
$req =
'die "No list context" unless ref $that eq \'Sympa::List\';';
} elsif ($_ eq 'message') {
$req = '$context->{message} ||= Sympa::Message->new("\n");';
} else {
......@@ -671,7 +672,8 @@ sub _compile_condition {
$log->syslog('err', 'Bad regexp /%s/: %s', $re, $EVAL_ERROR);
return undef;
}
$value = sprintf 'Sympa::Scenario::safe_qr(\'%s\', $context)', $re;
$value = sprintf 'Sympa::Scenario::safe_qr(\'%s\', $context)',
$re;
} elsif ($value =~ /\[custom_vars\-\>([\w\-]+)\]/i) {
# Custom vars
$value = sprintf '$context->{custom_vars}{\'%s\'}', $1;
......@@ -766,11 +768,13 @@ sub _compile_condition {
## available.
if (defined $index) {
$value =
sprintf 'do { my @h = $context->{message}->get_header(\'%s\'); $h[%s] // \'\' }',
sprintf
'do { my @h = $context->{message}->get_header(\'%s\'); $h[%s] // \'\' }',
$field_name, $index;
} else {
$value =
sprintf 'do { my @h = $context->{message}->get_header(\'%s\'); @h ? [@h] : [\'\'] }',
sprintf
'do { my @h = $context->{message}->get_header(\'%s\'); @h ? [@h] : [\'\'] }',
$field_name;
}
$required_keys{message} = 1;
......
......@@ -263,8 +263,13 @@ sub _twist {
$log->syslog('err', 'Cannot create dynamic list %s', $listname);
return undef;
} elsif (
not( $spindle_req->success
and $list = Sympa::List->new($listname, $dyn_family->{'domain'}, {just_try => 1}))
not($spindle_req->success
and $list = Sympa::List->new(
$listname,
$dyn_family->{'domain'},
{just_try => 1}
)
)
) {
$log->syslog('err',
'Unable to create list %s. Message %s ignored',
......
......@@ -370,7 +370,7 @@ sub _url_func {
my $that = $self->{context};
my $robot_id =
(ref $that eq 'Sympa::List') ? $that->{'domain'}
(ref $that eq 'Sympa::List') ? $that->{'domain'}
: (ref $that eq 'Sympa::Family') ? $that->{'domain'}
: ($that and $that ne '*') ? $that
: '*';
......
......@@ -10,9 +10,7 @@ use Test::More;
use Sympa::Log;
use Sympa::Message;
%Conf::Conf = (
sender_headers => 'From',
);
%Conf::Conf = (sender_headers => 'From',);
Sympa::Log->instance->{log_to_stderr} = 'err';
......@@ -26,7 +24,7 @@ Sympa::Log->instance->{log_to_stderr} = 'err';
# is_signed()
is test_is_signed('t/samples/unsigned.eml'), 0, 'never signed';
is test_is_signed('t/samples/signed.eml'), 1, 'multipart/signed S/MIME';
is test_is_signed('t/samples/signed.eml'), 1, 'multipart/signed S/MIME';
#is test_is_signed('t/samples/signed-pkcs7.eml'), 1, 'PKCS#7 S/MIME';
#is test_is_signed('t/samples/signed-pgp.eml'), 0, 'multipart/signed PGP/MIME';
#is test_is_signed('t/samples/signed-pgp-inline.eml'), 0, 'PGP inline';
......
......@@ -17,27 +17,27 @@ BEGIN {
use_ok('Sympa::Message');
}
my $tmp_dir = 't/tmp';
my $home_dir = $tmp_dir.'/list_data';
my $etc_dir = $tmp_dir.'/etc';
my $tmp_dir = 't/tmp';
my $home_dir = $tmp_dir . '/list_data';
my $etc_dir = $tmp_dir . '/etc';
my $test_list_name = 'test';
%Conf::Conf = (
domain => 'lists.example.com', # mandatory
listmaster => 'dude@example.com', # mandatory
lang => 'en-US',
sender_headers => 'From',
tmpdir => $tmp_dir,
home => $home_dir,
etc => $etc_dir,
cache_list_config => '',
supported_lang => 'en-US',
domain => 'lists.example.com', # mandatory
listmaster => 'dude@example.com', # mandatory
lang => 'en-US',
sender_headers => 'From',
tmpdir => $tmp_dir,
home => $home_dir,
etc => $etc_dir,
cache_list_config => '',
supported_lang => 'en-US',
filesystem_encoding => 'utf-8',
urlize_min_size => 0,
urlize_min_size => 0,
);
if (-d $tmp_dir) {
rmtree($tmp_dir);
rmtree($tmp_dir);
}
make_path($tmp_dir);
make_path($home_dir);
......@@ -48,125 +48,99 @@ my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'err';
my $list = bless {
dir => "$home_dir/$test_list_name",
name => $test_list_name,
dir => "$home_dir/$test_list_name",
name => $test_list_name,
domain => $Conf::Conf{domain},
} => 'Sympa::List';
my $root_url = '/attach/test/';
my @to_urlize = (
{
test_case => 'simple',
filename => 't/samples/urlize-simple.eml',
attachments =>
[
{
name => 'attachment.pdf',
escaped_name => 'attachment.pdf',
},
],
dirname => 'simple@example.com',
{ test_case => 'simple',
filename => 't/samples/urlize-simple.eml',
attachments => [
{ name => 'attachment.pdf',
escaped_name => 'attachment.pdf',
},
],
dirname => 'simple@example.com',
escaped_dirname => 'simple%40example.com',
},
{
test_case => 'simple with several attachments',
filename => 't/samples/urlize-simple-mutiple-attachments.eml',
attachments =>
[
{
name => 'attachment.pdf',
escaped_name => 'attachment.pdf',
},
{
name => 'text.txt',
escaped_name => 'text.txt',
},
{
name => 'image.png',
escaped_name => 'image.png',
},
],
dirname => 'simple@example.com',
{ test_case => 'simple with several attachments',
filename => 't/samples/urlize-simple-mutiple-attachments.eml',
attachments => [
{ name => 'attachment.pdf',
escaped_name => 'attachment.pdf',
},
{ name => 'text.txt',
escaped_name => 'text.txt',
},
{ name => 'image.png',
escaped_name => 'image.png',
},
],
dirname => 'simple@example.com',
escaped_dirname => 'simple%40example.com',
},
{
test_case => 'encoding',
filename => 't/samples/urlize-encoding.eml',
attachments =>
[
{
name => 'ございます.pdf',
escaped_name => '%25e3%2581%2594%25e3%2581%259',
},
],
dirname => 'globuz_24_3c_3e_25@example.com',
{ test_case => 'encoding',
filename => 't/samples/urlize-encoding.eml',
attachments => [
{ name => 'ございます.pdf',
escaped_name => '%25e3%2581%2594%25e3%2581%259',
},
],
dirname => 'globuz_24_3c_3e_25@example.com',
escaped_dirname => 'globuz_24_3c_3e_25%40example.com',
},
{
test_case => 'nested in multipart/mixed message',
filename => 't/samples/urlize-nested-mixed.eml',
attachments =>
[
{
name => 'Würzburg.txt',
escaped_name => 'W%25c3%25bcrzburg.txt',
},
],
dirname => '3_24@domain.tld',
{ test_case => 'nested in multipart/mixed message',
filename => 't/samples/urlize-nested-mixed.eml',
attachments => [
{ name => 'Würzburg.txt',
escaped_name => 'W%25c3%25bcrzburg.txt',
},
],
dirname => '3_24@domain.tld',
escaped_dirname => '3_24%40domain.tld',
},
{
test_case => 'nested in multipart/alternative message',
filename => 't/samples/urlize-nested-alternative.eml',
attachments =>
[
{
name => 'globuz.pdf',
escaped_name => 'globuz.pdf',
},
],
dirname => '4_24@domain.tld',
{ test_case => 'nested in multipart/alternative message',
filename => 't/samples/urlize-nested-alternative.eml',
attachments => [
{ name => 'globuz.pdf',
escaped_name => 'globuz.pdf',
},
],
dirname => '4_24@domain.tld',
escaped_dirname => '4_24%40domain.tld',
},
{
test_case => 'Deep nested message',
filename => 't/samples/urlize-deep-nested-mixed.eml',
attachments =>
[
{
name => 'Würzburg.txt',
escaped_name => 'W%25c3%25bcrzburg.txt',
},
{
name => 'msg.3.bin',
escaped_name => 'msg.3.bin',
},
],
dirname => 'deep-nested@domain.tld',
{ test_case => 'Deep nested message',
filename => 't/samples/urlize-deep-nested-mixed.eml',
attachments => [
{ name => 'Würzburg.txt',
escaped_name => 'W%25c3%25bcrzburg.txt',
},
{ name => 'msg.3.bin',
escaped_name => 'msg.3.bin',
},
],
dirname => 'deep-nested@domain.tld',
escaped_dirname => 'deep-nested%40domain.tld',
},
{
test_case => 'Related/alternative nested message',
filename => 't/samples/urlize-nested-alternative-and-related.eml',
attachments =>
[
{
name => 'document.pdf',
escaped_name => 'document.pdf',
},
],
dirname => 'alt-nested@domain.tld',
{ test_case => 'Related/alternative nested message',
filename => 't/samples/urlize-nested-alternative-and-related.eml',
attachments => [
{ name => 'document.pdf',
escaped_name => 'document.pdf',
},
],
dirname => 'alt-nested@domain.tld',
escaped_dirname => 'alt-nested%40domain.tld',
},
);
foreach my $test_file (@to_urlize) {
my $to_urlize_file = $test_file->{filename};
my $lock_fh = Sympa::LockedFile->new($to_urlize_file, -1, '+<');
my $to_urlize_file = $test_file->{filename};
my $lock_fh = Sympa::LockedFile->new($to_urlize_file, -1, '+<');
my $to_urlize_string = do { local $RS; <$lock_fh> };
my $to_urlize = Sympa::Message->new($to_urlize_string);
my $to_urlize = Sympa::Message->new($to_urlize_string);
my $parser = MIME::Parser->new;
$parser->extract_nested_messages(0);
......@@ -178,51 +152,97 @@ foreach my $test_file (@to_urlize) {
$msg_string =~ s/\AReturn-Path: (.*?)\n(?![ \t])//s;
my $entity = $parser->parse_data($msg_string);
my $new_entity = Sympa::Message::_urlize_parts($entity, $list, $to_urlize->{'message_id'});
my $new_entity = Sympa::Message::_urlize_parts($entity, $list,
$to_urlize->{'message_id'});
### Preparation done. Actual testing starts here.
my $urlized_directory;
opendir my $dh, $home_dir.'/'.$test_list_name.'/urlized/';
opendir my $dh, $home_dir . '/' . $test_list_name . '/urlized/';
foreach my $file (readdir $dh) {
next if $file =~ m{\A\.+\Z};
$urlized_directory = $file; last;
next if $file =~ m{\A\.+\Z};
$urlized_directory = $file;
last;
}
closedir $dh;
is($urlized_directory, $test_file->{dirname}, 'Test case: '.$test_file->{test_case}.' - Directory where urlized parts are stored correctly escaped.');
is($urlized_directory, $test_file->{dirname},
'Test case: '
. $test_file->{test_case}
. ' - Directory where urlized parts are stored correctly escaped.'
);
ok( !-f $home_dir . '/'
. $test_list_name
. '/urlized/'
. $urlized_directory
. '/msg.0.bin',
'Test case: '
. $test_file->{test_case}
. ' - The text of the message has not been converted to binary attachment.'
);
ok( !-f $home_dir . '/'
. $test_list_name
. '/urlized/'
. $urlized_directory
. '/msg.0.txt',
'Test case: '
. $test_file->{test_case}
. ' - The text of the message has not been converted to text attachment.'
);
ok(! -f $home_dir.'/'.$test_list_name.'/urlized/'.$urlized_directory.'/msg.0.bin', 'Test case: '.$test_file->{test_case}.' - The text of the message has not been converted to binary attachment.') ;
ok(! -f $home_dir.'/'.$test_list_name.'/urlized/'.$urlized_directory.'/msg.0.txt', 'Test case: '.$test_file->{test_case}.' - The text of the message has not been converted to text attachment.') ;
my @expected_files;
foreach my $file (@{$test_file->{attachments}}) {
ok( -f "$home_dir/$test_list_name/urlized/$urlized_directory/$file->{name}", 'Test case: '.$test_file->{test_case}.' - The attachment '.$file->{name}.' has been stored on the filesystem.') ;
if (-f "$home_dir/$test_list_name/urlized/$urlized_directory/$file->{name}") {
ok( -f "$home_dir/$test_list_name/urlized/$urlized_directory/$file->{name}",
'Test case: '
. $test_file->{test_case}
. ' - The attachment '
. $file->{name}
. ' has been stored on the filesystem.'
);
if (-f "$home_dir/$test_list_name/urlized/$urlized_directory/$file->{name}"
) {
push @expected_files, $file->{name};
}
my $found_url_to_attachment = 0;
foreach my $line (split '\n', $new_entity->as_string()) {
my $line_to_match = $root_url.$test_file->{escaped_dirname}.'/'.$file->{escaped_name};
my $line_to_match =
$root_url
. $test_file->{escaped_dirname} . '/'
. $file->{escaped_name};
if ($line =~ m{$line_to_match}) {
$found_url_to_attachment = 1;
last;
}
}
is( $found_url_to_attachment, 1, 'Test case: '.$test_file->{test_case}.' - The attachment '.$file->{name}.' stored on the filesystem has an URL to retrieve it in the new message.');
is($found_url_to_attachment, 1,
'Test case: '
. $test_file->{test_case}
. ' - The attachment '
. $file->{name}
. ' stored on the filesystem has an URL to retrieve it in the new message.'
);
}
my @found_files;
opendir my $dh2, "$home_dir/$test_list_name/urlized/$urlized_directory/";
foreach my $file (readdir $dh2) {
next if $file =~ m{\A\.+\Z};
push @found_files, $file;
next if $file =~ m{\A\.+\Z};
push @found_files, $file;
}
closedir $dh2;
my $total_expected_files = $#expected_files+1;
is($#found_files, $#expected_files, 'Test case: '.$test_file->{test_case}.' - Found the urlized attachments (total: '.$total_expected_files.') and only them.');
rmtree $home_dir.'/'.$test_list_name.'/urlized/'.$urlized_directory;
my $total_expected_files = $#expected_files + 1;
is($#found_files, $#expected_files,
'Test case: '
. $test_file->{test_case}
. ' - Found the urlized attachments (total: '
. $total_expected_files
. ') and only them.');
rmtree $home_dir. '/'
. $test_list_name
. '/urlized/'
. $urlized_directory;
}
rmtree $tmp_dir;
done_testing();
......@@ -49,5 +49,10 @@ is $dec, $unicode_email, 'decode_filesystem_safe, Unicode';
# ToDo: wrap_text()
# Noncharacters: U+d800, U+10FFE, U+110000, U+200000
is Sympa::Tools::Text::canonic_text("\xED\xA0\x80\n\xF4\x8F\xBF\xBE\n\xF4\x90\x80\x80\n\xF8\x88\x80\x80\x80\n"), Encode::encode_utf8("\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n");
is Sympa::Tools::Text::canonic_text(
"\xED\xA0\x80\n\xF4\x8F\xBF\xBE\n\xF4\x90\x80\x80\n\xF8\x88\x80\x80\x80\n"
),
Encode::encode_utf8(
"\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n"
);