Update of /cvsroot/mhonarc/mhonarc/MHonArc/lib
In directory subversions:/tmp/cvs-serv10909
Modified Files:
readmail.pl
Log Message:
* Removed -pass-:function specification support for
%MIMECharSetConverters(). The feature is not publicly documented
and it no longer works as documented according to source comments.
Removal also simplifies non-ASCII encoded words decoding.
* Added support for charset aliases. New public functions
MAILset_charset_aliases() and MAILload_charset_converter() added
to help support it.
Index: readmail.pl
===================================================================
RCS file: /cvsroot/mhonarc/mhonarc/MHonArc/lib/readmail.pl,v
retrieving revision 2.18
retrieving revision 2.19
diff -C2 -r2.18 -r2.19
*** readmail.pl 28 Jun 2002 03:28:10 -0000 2.18
--- readmail.pl 10 Oct 2002 22:21:32 -0000 2.19
***************
*** 157,163 ****
## $converted_data = &function($data, $charset);
##
- ## A function called "-pass-:function" implies that the data should be
- ## passed to the converter "function" but not decoded.
- ##
## A function called "-decode-" implies that the data should be
## decoded, but no converter is to be invoked.
--- 157,160 ----
***************
*** 231,234 ****
--- 228,242 ----
unless defined(%MIMEExcs);
+ ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ ## %MIMECharsetAliases is a mapping of charset names to charset names.
+ ## The MAILset_charset_aliases() routine should be used to set the
+ ## values of this hash.
+ ##
+ ## Keys => charset name
+ ## Values => real charset name
+ ##
+ %MIMECharsetAliases = ()
+ unless defined(%MIMECharsetAliases);
+
##---------------------------------------------------------------------------
## Variables holding functions for generating processed output
***************
*** 309,332 ****
sub MAILdecode_1522_str {
my($str) = shift;
! my($decoding_flag) = shift;
my($charset,
- $lcharset,
$encoding,
$dec,
$charcnv,
! $defcharcnv,
$plaincnv,
$strtxt,
$str_before);
my($ret) = ('');
- $defcharcnv = '-bogus-';
-
- # Get default converter
- $defcharcnv = &load_charset('default');
-
# Get plain converter
! $plaincnv = &load_charset('plain');
! $plaincnv = $defcharcnv unless $plaincnv;
# Decode string
--- 317,335 ----
sub MAILdecode_1522_str {
my($str) = shift;
! my($decoding_flag) = shift || 0;
my($charset,
$encoding,
$dec,
$charcnv,
! $real_charset,
$plaincnv,
+ $plain_real_charset,
$strtxt,
$str_before);
my($ret) = ('');
# Get plain converter
! ($plaincnv, $plain_real_charset) = MAILload_charset_converter('plain');
! $plain_real_charset = 'us-ascii' if $plain_real_charset eq 'plain';
# Decode string
***************
*** 348,355 ****
$ret .= $str_before;
} elsif (defined(&$plaincnv)) { # decode and convert
! $ret .= &$plaincnv($str_before,'');
! } elsif (($plaincnv =~ /-pass-:(.*)/) && # pass
! (defined(&${1}))) {
! $ret .= &${1}($str_before,'');
} else { # ignore
$ret .= $str_before;
--- 351,355 ----
$ret .= $str_before;
} elsif (defined(&$plaincnv)) { # decode and convert
! $ret .= &$plaincnv($str_before, $plain_real_charset);
} else { # ignore
$ret .= $str_before;
***************
*** 357,366 ****
# Convert encoded text
- ($lcharset = $charset) =~ tr/A-Z/a-z/;
if ($decoding_flag == DECODE_ALL) {
$charcnv = '-decode-';
} else {
! $charcnv = &load_charset($lcharset);
! $charcnv = $defcharcnv unless $charcnv;
}
--- 357,364 ----
# Convert encoded text
if ($decoding_flag == DECODE_ALL) {
$charcnv = '-decode-';
} else {
! ($charcnv, $real_charset) = MAILload_charset_converter($charset);
}
***************
*** 377,386 ****
} elsif (defined(&$charcnv)) {
$strtxt =~ s/_/ /g;
! $ret .= &$charcnv(&$dec($strtxt),$lcharset);
!
! # Do not decode, but convert
! } elsif (($charcnv =~ /-pass-:(.*)/) &&
! (defined(&${1}))) {
! $ret .= &${1}($strtxt,$lcharset);
# Fallback is to ignore
--- 375,379 ----
} elsif (defined(&$charcnv)) {
$strtxt =~ s/_/ /g;
! $ret .= &$charcnv(&$dec($strtxt), $real_charset);
# Fallback is to ignore
***************
*** 394,401 ****
$ret .= $str;
} elsif (defined(&$plaincnv)) { # decode and convert
! $ret .= &$plaincnv($str,'');
! } elsif (($plaincnv =~ /-pass-:(.*)/) && # pass
! (defined(&${1}))) {
! $ret .= &${1}($str,'');
} else { # ignore
$ret .= $str;
--- 387,391 ----
$ret .= $str;
} elsif (defined(&$plaincnv)) { # decode and convert
! $ret .= &$plaincnv($str, $plain_real_charset);
} else { # ignore
$ret .= $str;
***************
*** 823,827 ****
##
sub MAILis_excluded {
! my $content = lc($_[0]) || 'text/plain';
if ($MIMEExcs{$ctype}) {
return 1;
--- 813,817 ----
##
sub MAILis_excluded {
! my $ctype = lc($_[0]) || 'text/plain';
if ($MIMEExcs{$ctype}) {
return 1;
***************
*** 974,977 ****
--- 964,1012 ----
$_MIMEAltPrefs{$ctype} = $i++;
}
+ }
+
+ ##---------------------------------------------------------------------------##
+ ## MAILset_charset_aliases() is used to define name aliases for
+ ## charset names.
+ ##
+ ## Example usage:
+ ## MAILset_charset_aliases( {
+ ## 'iso-8859-1' => [ 'latin1', 'iso_8859_1', '8859-1' ],
+ ## 'iso-8859-15' => [ 'latin9', 'iso_8859_15', '8859-15' ],
+ ## }, $override );
+ ##
+ sub MAILset_charset_aliases {
+ my $map = shift;
+ my $override = shift;
+
+ %MIMECharsetAliases = () if $override;
+ my($charset, $aliases, $alias);
+ while (($charset, $aliases) = each(%$map)) {
+ $charset = lc $charset;
+ foreach $alias (@$aliases) {
+ $MIMECharsetAliases{lc $alias} = $charset;
+ }
+ }
+ }
+
+ ##---------------------------------------------------------------------------##
+ ## MAILload_charset_converter() loads the charset converter function
+ ## associated with given charset name.
+ ##
+ ## Example usage:
+ ## ($func, $real_charset) = MAILload_charset_converter($charset);
+ ##
+ ## $func is the reference to the converter function, which may be
+ ## undef. $real_charset is the real charset name that should be
+ ## used when invoking the function.
+ ##
+ sub MAILload_charset_converter {
+ my $charset = lc shift;
+ $charset = $MIMECharsetAliases{$charset} if $MIMECharsetAliases{$charset};
+ my $func = load_charset($charset);
+ if (!defined($func) || !defined(&$func)) {
+ $func = load_charset('default');
+ }
+ ($func, $charset);
}
---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-DEV