Mail::Message::Encode Class

fml 8 tutorial
Prev |  | Next

# Chapter 53. Mail::Message::Encode Class

[References] fml-help ML's Count: 02012, 02013, 02016.

    [Usage]

    	use Mail::Message::Encode;
    	my $encode  = new Mail::Message::Encode;
    	my $str_euc = $encode->convert( $s, 'euc-jp' );
    	my $str_euc = $encode->convert( $s, 'euc-jp', 'iso-2022-jp' );

    	my $encode  = new Mail::Message::Encode;
    	my $status  = $encode->convert_str_ref( \$s, 'euc-jp' );
    	my $status  = $encode->convert_str_ref( \$s, 'euc-jp', 'jis' );

    	my $fp = sub { ... };
    	$encode->run_in_chcode( $fp, $oout, $in );

      * If you want to use 4.0 compatible functions,
    	ues Mail::Message::Encode qw(STR2EUC);
    	my $euc_s = STR2EUC( $s );

# Mail::Message::Encode Specification

The main code is within _convert_str_ref() method.

       sub convert # if the argument is STR.
       {
    	my ($self, $str, $out_code, $in_code) = @_;
    	_convert_str_ref(\$str, $out, $in);

            return $str;
       }

       sub convert_str_ref # if the argument is STR_REF.
       {
    	my ($self, $str, $out, $in) = @_;
    	_convert_str_ref($str, $out, $in);
       }

       sub _convert_str_ref # if the argument is STR_REF.
       {
            my ($str, $out, $in) = @_;

            # 1. speculate charset
            if $in unspecified -> speculat -> fail -> return 0

            # 2. try conversion
            if ($in resolved or or $in specified in @_) {
                    converted to $out charset
                    (use jcode, Jcode, use Encode if perl version > 5.8).
                    conversion
                    return 1 ; # success
            }
            else { # principle of least surprise ?
                    nothing todo ;
                    return $str;
            }

            return 0 ; # failed
       }

    sub base64 {}
    sub quoted_printable {}

is implemented for convenience.

    $x = $encode->base64($s);

For backward compatibility, STR2XXX() functoins are prepared, too.

       STR2EUC(  $str, [$icode] )
       STR2JIS(  $str, [$icode] )
       STR2SJIS( $str, [$icode] )

These wraps convert_str_ref().

Prev | Home | Next
Language Dependent Functions | Up | run_in_chcode()

fml 8.0 (fml-devel) project homepage is www.fml.org/software/fml8/.
fml 4.0 project homepage is www.fml.org/software/fml4/.
about one floppy bsd routers, see www.bsdrouter.org/.
other free softwares are found at www.fml.org/software/.

author's homepage is www.fml.org/home/fukachan/.
Also, visit nuinui's world :) at www.nuinui.net.

For questions about FML, e-mail <fml-bugs@fml.org>.