##---------------------------------------------------------------------------##
## $Id: mhtxtenrich.pl,v 2.5 2001/08/25 19:57:59 ehood Exp $
## Earl Hood mhonarc@mhonarc.org
## Library defines a routine for MHonArc to filter text/enriched
## Filter routine can be registered with the following:
## text/enriched:m2h_text_enriched'filter:mhtxtenrich.pl
## text/richtext:m2h_text_enriched'filter:mhtxtenrich.pl
##---------------------------------------------------------------------------##
## MHonArc -- Internet mail-to-HTML converter
## Copyright (C) 1997-2001 Earl Hood, mhonarc@mhonarc.org
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
##---------------------------------------------------------------------------##
package m2h_text_enriched
;
##---------------------------------------------------------------------------
my($fields, $data, $isdecode, $args) = @_;
my($innofill, $chunk, $ret, $charset);
$args = "" unless defined($args);
## Grab charset parameter (if defined)
$ctype = $fields->{'content-type'}[0] || "";
if ($ctype =~ /charset=(\S+)/) {
## Translate text/enriched commands
foreach $chunk (split(m
|(</?nofill
>)|i
, $$data)) {
if ($chunk =~ m
|<nofill
>|i
) {
if ($chunk =~ m
|</nofill
>|i
) {
$chunk =~ s
|(\r?
\n\s
*)|&nl_seq_to_brs
($1)|gie
;
## Translate 8-bit characters to entity refs based on charset
## (we already did '<' and '&' characters)
if ($charset =~ /iso-8859-([2-9]|10)/i) {
$ret = iso_8859
::str2sgml
($ret, $charset, 1);
##---------------------------------------------------------------------------
## convert_tags translates text/enriched commands to HTML tags.
$$str =~ s
|<(/?
)bold
>|<$1B>|gi
;
$$str =~ s
|<(/?
)italic
>|<$1I>|gi
;
$$str =~ s
|<(/?
)underline
>|<$1U>|gi
;
$$str =~ s
|<(/?
)fixed
>|<$1TT>|gi
;
$$str =~ s
|<(/?
)smaller
>|<$1SMALL>|gi
;
$$str =~ s
|<(/?
)bigger
>|<$1BIG>|gi
;
$$str =~ s
|<fontfamily
>\s
*<param
>([^<]+)</param
>|<FONT face
="$1">|gi
;
$$str =~ s
|</fontfamily>|</FONT
>|gi
;
$$str =~ s
|<color
>\s
*<param
>\s
*(\S
+)\s
*</param
>|<FONT color
="$1">|gi
;
$$str =~ s
|</color>|</FONT
>|gi
;
$$str =~ s
|<center
>|<P align
="center">|gi
;
$$str =~ s
|</center>|</P
>|gi
;
$$str =~ s
|<flushleft
>|<P align
="left">|gi
;
$$str =~ s
|</flushleft>|</P
>|gi
;
$$str =~ s
|<flushright
>|<P align
="right">|gi
;
$$str =~ s
|</flushright>|</P
>|gi
;
$$str =~ s
|<flushboth
>|<P align
="both">|gi
; # Not supported in HTML
$$str =~ s
|</flushboth>|</P
>|gi
;
$$str =~ s
|<paraindent
>\s
*<param
>([^<]*)</param
>|<BLOCKQUOTE
>|gi
;
$$str =~ s
|</paraindent>|</BLOCKQUOTE
>|gi
;
$$str =~ s
|<excerpt
>\s
*(<param
>([^<]*)</param
>)?
|<BLOCKQUOTE
>|gi
;
$$str =~ s
|</excerpt>|</BLOCKQUOTE
>|gi
;
$$str =~ s
|<lang
>\s
*<param
>([^<]*)</param
>||gi
;
##---------------------------------------------------------------------------
## nl_seq_to_brs returns a "<BR>" string based on the number
##---------------------------------------------------------------------------
## preserve_space returns a string with all spaces and tabs
$str =~ s/^([^\t]*)(\t+)/$1 . ' ' x (length($2) * 8 - length($1) % 8)/e;
##---------------------------------------------------------------------------