Commit 59c8ec06 authored by sympa-authors's avatar sympa-authors
Browse files

[Soji Ikeda] Fix: Some paths of message processing in Sympa can't recognize

Unicode strings.  At least MIME::Parser::parse_data() and
Template::proccess(): these methods occationalily break
strings containing Unicode characters.

My mail_utf8 patch expects the behavior as following ---

Sub-messages to be attached (into digests, moderation
notices etc.) will passed to mail::reformat_message()
separately then attached to reformatted parent message
again.  As a result, sub-messages won't be broken.  Since
they won't cause mixture of Unicode string (parent message
generated by tt2::parse_tt2()) and byte string (sub-messages).

Note: For compatibility with old style, data passed to
mail::reformat_message() already includes sub-message(s).  Then:
- When a part has an `X-Sympa-Attach:' header field for
internal use, new style, mail::reformat_message() attaches
raw sub-message to reformatted parent message again;
- When a part doesn't have any `X-Sympa-Attach:' header
fields, sub-messages generated by [% INSERT %] directive(s)
in the template will be used.
See src/mail.pm hunk #4.

More Note: Latter behavior above will give expected result
only if contents of sub-messages are US-ASCII or ISO-8859-1.
In other cases customized templates (if any) should be
modified so that they have appropriate `X-Sympa-Attach:'
header fileds.

Sub-messages are gathered from template context paramenters.
  See src/mail.pm hunk #1.

Other trivial fixes:
  mail_tt2/listmaster_notification.tt2 hunk #1
  mail_tt2/request_auth.tt2
  src/Commands.pm: informations of list in INFO message will
be translated.
  src/mail.pm hunk #5: fallback to UTF-8 when locale of user
was not same as that of list.


git-svn-id: https://subversion.renater.fr/sympa/trunk@4007 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent ab022ae5
......@@ -9,6 +9,7 @@ Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Type: message/rfc822
Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Disposition: inline
X-Sympa-Attach: yes
[% INSERT $file IF file %]
......
......@@ -25,12 +25,13 @@ This is a multi-part message in MIME format...
--[% boundary2 %]
Content-Type: message/rfc822
Content-Disposition: inline
X-Sympa-Attach: yes
[% m.full_msg %]
[% END %]
--[% boundary2 %]
Content-Type: text/plain
Content-Type: text/plain; charset=[%|loc%]_charset_[%END%];
Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Disposition: inline
......
......@@ -24,12 +24,13 @@ This is a multi-part message in MIME format...
--[% boundary2 %]
Content-Type: message/rfc822
Content-Disposition: inline
X-Sympa-Attach: yes
[% m.full_msg %]
[% END %]
--[% boundary2 %]
Content-Type: text/plain
Content-Type: text/plain; charset=[%|loc%]_charset_[%END%];
Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Disposition: inline
......
From: SYMPA <[% conf.email %]@[% conf.host %]>
To: [% FILTER qencode %][%|loc%]Listmaster <[% to %]>[%END%][%END%]
To: [% FILTER qencode %][%|loc%]Listmaster[%END%] <[% to %]>[%END%]
[% IF type == 'request_list_creation' -%]
Subject: [% FILTER qencode %][%|loc(list.name)%]List "%1" creation request[%END%][%END%]
MIME-Version: 1.0
......@@ -91,6 +91,7 @@ Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Type: message/rfc822
Content-Transfer-Encoding:[%|loc%]_encoding_[%END%]
Content-Disposition: inline
X-Sympa-Attach: yes
[% INSERT $msg IF msg %]
......
......@@ -34,6 +34,7 @@ REJECT [% list.name %] [% modkey %]
Content-Type: message/rfc822
Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Disposition: inline
X-Sympa-Attach: yes
[% INSERT $msg IF msg %]
......
......@@ -28,7 +28,7 @@ Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
[%- END -%]
[%- END -%]
[%|loc(conf.sympa)-%]If you want this action to be taken, please
[%|loc(conf.sympa,command)-%]If you want this action to be taken, please
- reply to this mail
OR
......
......@@ -26,6 +26,7 @@ CONFIRM %2
Content-Type: message/rfc822
Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
Content-Disposition: inline
X-Sympa-Attach: yes
[% INSERT $file IF file %]
......
......@@ -916,7 +916,7 @@ sub info {
}
foreach my $p ('subscribe','unsubscribe','send','review') {
$data->{$p} = $list->{'admin'}{$p}{'title'}{'gettext'};
$data->{$p} = gettext($list->{'admin'}{$p}{'title'}{'gettext'});
}
## Digest
......
......@@ -3902,7 +3902,7 @@ sub archive_send_last {
my $subject = 'File '.$self->{'name'}.'.last_message' ;
my $param = {'to' => $who,
'subject' => $subject,
'msg_list' => @msglist } ;
'msg_list' => \@msglist } ;
$param->{'boundary1'} = &tools::get_message_id($self->{'domain'});
......
......@@ -231,7 +231,17 @@ sub mail_file {
$headers .= "\n";
}
unless ($message = &reformat_message("$headers"."$message")) {
my @msgs = ();
if (ref($data->{'msg_list'}) eq 'ARRAY') {
@msgs = map {$_->{'msg'} || $_->{'full_msg'}} @{$data->{'msg_list'}};
} elsif ($data->{'msg'} and open IN, '<'.$data->{'msg'}) {
push @msgs, join('', <IN>);
close IN;
} elsif ($data->{'file'} and open IN, '<'.$data->{'file'}) {
push @msgs, join('', <IN>);
close IN;
}
unless ($message = &reformat_message("$headers"."$message", \@msgs)) {
&do_log('err', "mail::mail_file: Failed to reformat message");
}
......@@ -777,26 +787,29 @@ sub send_in_spool {
# header is appended :).
#
# IN : $msg: ref(MIME::Entity) | string - message to reformat
# $attachments: ref(ARRAY) - messages to be attached as subparts.
# OUT : string
#
####################################################
sub reformat_message($) {
sub reformat_message($;$) {
my $message = shift;
my $attachments = shift || [];
my $msg;
my $parser = new MIME::Parser;
unless (defined $parser) {
&do_log('err', "mail::reformat_message: Failed to create MIME parser");
return undef;
}
$parser->output_to_core(1);
if (ref($message) eq 'MIME::Entity') {
$msg = $message;
} else {
my $parser = new MIME::Parser;
unless (defined $parser) {
&do_log('err', "mail::reformat_message: Failed to create MIME parser");
return undef;
}
$parser->output_to_core(1);
$parser->ignore_errors(1);
# Turn off utf8 flag so that message will be safely passed to
# MIME::Parser::parse_data that breaks Unicode strings.
$message = Encode::encode_utf8($message);
eval {
$msg = $parser->parse_data($message);
};
......@@ -807,14 +820,15 @@ sub reformat_message($) {
}
$msg->head->delete("X-Mailer");
$msg = &fix_part($msg);
$msg = &fix_part($msg, $parser, $attachments);
$msg->head->add("X-Mailer", sprintf "Sympa %s", $Version::Version);
$msg->sync_headers(Length => 'COMPUTE');
return $msg->as_string;
}
sub fix_part($) {
sub fix_part($$$) {
my $part = shift;
my $parser = shift;
my $attachments = shift || [];
return $part unless $part;
my $enc = $part->head->mime_attr("Content-Transfer-Encoding");
......@@ -823,11 +837,26 @@ sub fix_part($) {
if $enc and $enc !~ /^(?:base64|quoted-printable|[78]bit|binary)$/i;
my $eff_type = $part->effective_type;
if ($part->parts) {
return $part if $eff_type =~ m{^multipart/(signed|encrypted)$};
if ($part->head->get('X-Sympa-Attach')) { # Need re-attaching data.
my $data = shift @{$attachments};
if (ref($data) ne 'MIME::Entity') {
eval {
$data = $parser->parse_data($data);
};
if ($@) {
&do_log('warn',
"mail::reformat_message: Failed to parse MIME data");
$data = $parser->parse_data('');
}
}
$part->head->delete('X-Sympa-Attach');
$part->parts([$data]);
} elsif ($part->parts) {
my @newparts = ();
foreach ($part->parts) {
push @newparts, &fix_part($_);
push @newparts, &fix_part($_, $parser, $attachments);
}
$part->parts(\@newparts);
} elsif ($eff_type =~ m{^(?:multipart|message)(?:/|\Z)}i) {
......@@ -843,7 +872,8 @@ sub fix_part($) {
my $charset = $head->mime_attr("Content-Type.Charset");
my ($newbody, $newcharset, $newenc) =
MIME::Charset::body_encode($body, $charset);
MIME::Charset::body_encode(Encode::decode_utf8($body), $charset,
Replacement => 'FALLBACK');
if ($newenc eq $enc and $newcharset eq $charset and
$newbody eq $body) {
return $part;
......@@ -864,10 +894,12 @@ sub fix_part($) {
$io->print($newbody);
$io->close;
$part->sync_headers(Length => 'COMPUTE');
} else {
# Binary or text with long lines will be suggested to be BASE64.
$part->head->mime_attr("Content-Transfer-Encoding",
$part->suggest_encoding);
$part->sync_headers(Length => 'COMPUTE');
}
return $part;
}
......
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