Commit a7ba7f99 authored by david.verdin's avatar david.verdin
Browse files

[feature][#5887][Submitted by S. Ikeda] A few years ago, Soji posted several...

[feature][#5887][Submitted by S. Ikeda] A few years ago, Soji posted several patches to support legacy character set support for service messages.  See
https://listes.cru.fr/sympa/arc/sympa-dev/2006-09/msg00029.html and its follow-ups.
As this feature has been disabled temporarily, he decided to maintain it again.



git-svn-id: https://subversion.renater.fr/sympa/trunk@5672 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 1e28e926
Legacy character set (charset) support for Sympa
IKEDA Soji <ikeda@conversion.co.jp>
16, Mar 2009
In some language environments, legacy encoding (character set) is
preferred for e-mail messages: for example iso-2022-jp in Japanese
language.
charset.conf defines mappings between locale and legacy character
set for service messages. If you want to disable legacy character
set support, simply create empty charset.conf onto etc directory:
# touch /home/sympa/etc/charset.conf
Note: if you are planning to upgrade Sympa earlier than 5.3a.8,
original charset.conf is required to convert shared documents
during upgrade process.
$$
......@@ -5,8 +5,7 @@ Subject: [% FILTER qencode %][%|loc(list.name)%]Digest for list %1[%END%] [% IF
Content-Type: multipart/mixed; boundary="[% boundary1 %]"
--[% boundary1 %]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc%]Table of contents:[%END%]
......@@ -30,8 +29,6 @@ X-Sympa-Attach: yes
[% END %]
--[% boundary2 %]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc(list.name,date)%]End of digest for list %1 - %2[%END%]
......
......@@ -4,8 +4,7 @@ Subject: [% FILTER qencode %][%|loc(list.name)%]Archive of %1, file %2[%END%][%E
Content-Type: multipart/mixed; boundary="[% boundary1 %]"
--[% boundary1 %]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc%]Table of contents:[%END%]
......@@ -29,8 +28,6 @@ X-Sympa-Attach: yes
[% END %]
--[% boundary2 %]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc(list.name,date)%]End of digest for list %1 - %2[%END%]
......
......@@ -6,7 +6,6 @@ Content-Type: multipart/report; report-type=delivery-status;
--[% boundary %]
Content-Description: Notification
Content-Type: text/plain; charset="UTF-8";
[%|loc%]This is an automatic response sent by Sympa Mailing Lists Manager.[%END%]
......
......@@ -22,9 +22,6 @@ To moderate this document :
[% ELSE -%]
Subject: [% FILTER qencode %][%|loc(list.name,type)%]Moderators List %1 / %2[%END%][%END%]
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
[% param0 %]
[% END %]
......@@ -85,8 +85,7 @@ MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="[% boundary %]"
--[% boundary %]
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc%]A loop has been detected with the following message[%END%]
......
......@@ -6,7 +6,7 @@ Content-Type: multipart/mixed; boundary="[% boundary %]"
Content-Transfer-Encoding: 8bit
--[% boundary %]
Content-Type: text/plain; charset="UTF-8";
Content-Disposition: inline
[% IF entry == 'forward' %]
[%|loc(list.name,function)%]Impossible to forward your message to '%1-%2' because of an internal server error.[%END%]
......@@ -24,7 +24,7 @@ Content-Type: multipart/mixed; boundary="[% boundary %]"
Content-Transfer-Encoding: 8bit
--[% boundary %]
Content-Type: text/plain; charset="UTF-8";
Content-Disposition: inline
[% IF list.name -%]
[%|loc(list.name)%]Impossible to distribute your message for list '%1' for the following reason :[%END%]
......@@ -81,7 +81,7 @@ Content-Type: multipart/mixed; boundary="[% boundary %]"
Content-Transfer-Encoding: 8bit
--[% boundary %]
Content-Type: text/plain; charset="UTF-8";
Content-Disposition: inline
[%|loc(list.name)%]Your message for list '%1' (attached below) was rejected.
You are not allowed to send this message for the following reason :[%END%]
......@@ -93,8 +93,6 @@ You are not allowed to send this message for the following reason :[%END%]
[%##################### %]
[% ELSIF type == 'success' -%]
Subject: [% FILTER qencode %][%|loc%]Message distribution[%END%][%END%]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
[% IF entry == 'moderating_message' -%]
......@@ -135,4 +133,4 @@ X-Sympa-Attach: yes
[% msg %]
--[% boundary %]--
[% END %]
\ No newline at end of file
[% END %]
......@@ -8,9 +8,8 @@ Reply-To: [% conf.email %]@[% conf.host %]
Content-Type: multipart/mixed; boundary="[% boundary %]"
--[% boundary %]
Content-Disposition: inline
[% END -%]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
[%|loc(list.name,msg_from)%]One new message from list %1 from %2 arrived. [%END%]
[%- IF spam_status == 'spam' -%][%|loc%]This message has been tagged as spam[%END%][% END %]
......
......@@ -3,8 +3,7 @@ Subject: [% FILTER qencode %][%|loc(list.name)%]Moderation spool for list %1[%EN
Content-Type: multipart/mixed; boundary="[% boundary1 %]"
--[% boundary1 %]
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc(total,list.name,list.host)%]There are %1 messages to be moderated for list %2@%3[%END%]
......
......@@ -6,7 +6,7 @@ Reply-to: [% conf.sympa %]
Content-Type: multipart/mixed; boundary="[% boundary %]"
--[% boundary %]
Content-Type: text/plain; charset=[% charset %];
Content-Disposition: inline
[% IF request_topic -%][%|loc(list.name,conf.wwsympa_url,authkey)%]List %1 allows you to tag your messages, using a set of defined topics. To tag the attached message go to the following page :[%END%]
......
Content-Type: text/plain; charset=UTF-8;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
[%|loc(file_name)%]The %1 file that was initially attached to this message has been stored on the mailing lists server:[%END%]
[% file_url %]
......@@ -521,6 +521,9 @@ sub load {
}
}
## Load charset.conf file
my $charset_conf = &load_charset;
$Conf{'locale2charset'} = $charset_conf;
unless ($no_db){
#load parameter from database if database value as prioprity over conf file
......@@ -629,6 +632,41 @@ sub load {
return 1;
}
## load charset.conf file (charset mapping for service messages)
sub load_charset {
my $charset = {};
my $config = $Conf{'etc'}.'/charset.conf' ;
$config = '--ETCBINDIR--/charset.conf' unless -f $config;
if (-f $config) {
unless (open CONFIG, $config) {
printf STDERR 'unable to read configuration file %s: %s\n',$config, $!;
return {};
}
while (<CONFIG>) {
chomp $_;
s/\s*#.*//;
s/^\s+//;
next unless /\S/;
my ($locale, $cset) = split(/\s+/, $_);
unless ($cset) {
printf STDERR 'charset name is missing in configuration file %s line %d\n',$config, $.;
next;
}
unless ($locale =~ s/^([a-z]+)_([a-z]+)/lc($1).'_'.uc($2).$'/ei) { #'
printf STDERR 'illegal locale name in configuration file %s line %d\n',$config, $.;
next;
}
$charset->{$locale} = $cset;
}
close CONFIG;
}
return $charset;
}
## load nrcpt file (limite receipient par domain
sub load_nrcpt_by_domain {
my $config = $Conf{'etc'}.'/nrcpt_by_domain.conf';
......
......@@ -192,7 +192,8 @@ sub SetLang {
$current_lang = $lang;
$current_locale = $locale;
$current_charset = 'utf-8';
my $locale2charset = &Conf::get_robot_conf('', 'locale2charset');
$current_charset = $locale2charset->{$locale} || 'utf-8';
return $locale;
}#SetLang
......@@ -347,9 +348,7 @@ sub gettext_strftime {
return &POSIX::strftime($format, @_) unless $current_charset;
$format = gettext($format);
Encode::from_to($format, 'utf8', $current_charset);
my $datestr = &POSIX::strftime($format, @_);
Encode::from_to($datestr, $current_charset, 'utf8');
return $datestr;
}
......
## Legacy character sets for service messages sent by Sympa.
## Default character set is utf-8.
de_DE iso-8859-1
es_ES iso-8859-1
et_EE iso-8859-4
fi_FI iso-8859-1
fr_FR iso-8859-1
hu_HU iso-8859-2
it_IT iso-8859-1
ja_JP euc-jp # for compatibility: see README.charset
nl_NL iso-8859-1
oc_FR iso-8859-1
pl_PL iso-8859-2
pt_PT iso-8859-1
ro_RO iso-8859-2
zh_TW big5
......@@ -222,7 +222,7 @@ sub mail_file {
$headers .= "MIME-Version: 1.0\n";
}
unless ($header_ok{'content-type'}) {
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$headers .= "Content-Type: text/plain; charset=".$data->{'charset'}."\n";
}
unless ($header_ok{'content-transfer-encoding'}) {
$headers .= "Content-Transfer-Encoding: 8bit\n";
......@@ -262,7 +262,7 @@ sub mail_file {
$listname = $data->{'list'};
}
unless ($message = &reformat_message("$headers"."$message", \@msgs)) {
unless ($message = &reformat_message("$headers"."$message", \@msgs, $data->{'charset'})) {
&do_log('err', "mail::mail_file: Failed to reformat message");
}
......@@ -890,9 +890,10 @@ sub send_in_spool {
##
## Sub-messages are gathered from template context paramenters.
sub reformat_message($;$) {
sub reformat_message($;$$) {
my $message = shift;
my $attachments = shift || [];
my $defcharset = shift;
my $msg;
my $parser = new MIME::Parser;
......@@ -915,15 +916,16 @@ sub reformat_message($;$) {
}
$msg->head->delete("X-Mailer");
$msg = &fix_part($msg, $parser, $attachments);
$msg = &fix_part($msg, $parser, $attachments, $defcharset);
$msg->head->add("X-Mailer", sprintf "Sympa %s", $Version::Version);
return $msg->as_string;
}
sub fix_part($$$) {
sub fix_part($$$$) {
my $part = shift;
my $parser = shift;
my $attachments = shift || [];
my $defcharset = shift;
return $part unless $part;
my $enc = $part->head->mime_attr("Content-Transfer-Encoding");
......@@ -951,7 +953,7 @@ sub fix_part($$$) {
} elsif ($part->parts) {
my @newparts = ();
foreach ($part->parts) {
push @newparts, &fix_part($_, $parser, $attachments);
push @newparts, &fix_part($_, $parser, $attachments, $defcharset);
}
$part->parts(\@newparts);
} elsif ($eff_type =~ m{^(?:multipart|message)(?:/|\Z)}i) {
......@@ -964,13 +966,14 @@ sub fix_part($$$) {
my $head = $part->head;
my $body = $bodyh->as_string;
my $charset = $head->mime_attr("Content-Type.Charset");
my $charset = $head->mime_attr("Content-Type.Charset") || $defcharset;
my ($newbody, $newcharset, $newenc) =
MIME::Charset::body_encode(Encode::decode('utf8', $body), $charset,
Replacement => 'FALLBACK');
if ($newenc eq $enc and $newcharset eq $charset and
$newbody eq $body) {
$head->add("MIME-Version", "1.0") unless $head->get("MIME-Version");
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