summaryrefslogtreecommitdiff
path: root/fml/lib/Mail
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-12-23 02:59:48 +0000
committerfukachan <fukachan>2001-12-23 02:59:48 +0000
commitacf12ab4efcc87222f708a4338ad73a6e6ef169b (patch)
tree6a8daa0bae5d8f6c301ffa1faa11aee752157f42 /fml/lib/Mail
parent4597ffb059c0e50bb26feaf04bd8faadda73f80d (diff)
downloadfml8-acf12ab4efcc87222f708a4338ad73a6e6ef169b.tar.gz
fml8-acf12ab4efcc87222f708a4338ad73a6e6ef169b.tar.bz2
fml8-acf12ab4efcc87222f708a4338ad73a6e6ef169b.zip
FML::MIME -> Mail::Message::{En,De}code
Diffstat (limited to 'fml/lib/Mail')
-rw-r--r--fml/lib/Mail/Message/Decode.pm100
-rw-r--r--fml/lib/Mail/Message/Encode.pm104
2 files changed, 204 insertions, 0 deletions
diff --git a/fml/lib/Mail/Message/Decode.pm b/fml/lib/Mail/Message/Decode.pm
new file mode 100644
index 00000000..d65ee8a9
--- /dev/null
+++ b/fml/lib/Mail/Message/Decode.pm
@@ -0,0 +1,100 @@
+#-*- perl -*-
+#
+# Copyright (C) 2001 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: MIME.pm,v 1.15 2001/12/22 09:21:01 fukachan Exp $
+#
+
+package Mail::Message::Decode;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK);
+use Carp;
+
+
+=head1 NAME
+
+Mail::Message::Decode - handle a MIME encoded string
+
+=head1 SYNOPSIS
+
+ use Mail::Message::Decode qw(decode_mime_string encode_mime_string);
+ $decoded = decode_mime_string( $message );
+
+=head1 DESCRIPTION
+
+MIME utilities to encode and decode string.
+It uses C<MIME::Base64> and C<MIME::QuotedPrint> as encoding/decoding
+engines.
+
+=head1 METHODS
+
+=cut
+
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(decode_mime_string encode_mime_string);
+
+
+=head2 C<decode_mime_string(string, [$options])>
+
+decode a base64/quoted-printable encoded string to a plain message.
+The encoding method is automatically detected.
+
+C<$options> is a HASH REFERENCE.
+You can specify the charset of the string to return
+by $options->{ charset }.
+
+=cut
+
+sub decode_mime_string
+{
+ my ($str, $options) = @_;
+ my $charset = $options->{ 'charset' } || 'euc-japan';
+
+ if ($charset eq 'euc-japan') {
+ use MIME::Base64;
+ if ($str =~ /=\?ISO\-2022\-JP\?B\?(\S+\=*)\?=/i) {
+ $str =~ s/=\?ISO\-2022\-JP\?B\?(\S+\=*)\?=/decode_base64($1)/gie;
+ }
+
+ use MIME::QuotedPrint;
+ if ($str =~ /=\?ISO\-2022\-JP\?Q\?(\S+\=*)\?=/i) {
+ $str =~ s/=\?ISO\-2022\-JP\?Q\?(\S+\=*)\?=/decode_qp($1)/gie;
+ }
+ }
+
+ use Jcode;
+ &Jcode::convert(\$str, 'euc');
+ $str;
+}
+
+
+=head1 SEE ALSO
+
+L<Jcode>,
+L<MIME::Base64>,
+L<MIME::QuotedPrint>.
+
+=head1 AUTHOR
+
+Ken'ichi Fukamachi
+
+=head1 COPYRIGHT
+
+Copyright (C) 2001 Ken'ichi Fukamachi
+
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the same terms as Perl itself.
+
+=head1 HISTORY
+
+Mail::Message::Decode appeared in fml5 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+
+1;
diff --git a/fml/lib/Mail/Message/Encode.pm b/fml/lib/Mail/Message/Encode.pm
new file mode 100644
index 00000000..74b387ba
--- /dev/null
+++ b/fml/lib/Mail/Message/Encode.pm
@@ -0,0 +1,104 @@
+#-*- perl -*-
+#
+# Copyright (C) 2001 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: MIME.pm,v 1.15 2001/12/22 09:21:01 fukachan Exp $
+#
+
+package Mail::Message::Encode;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK);
+use Carp;
+
+
+=head1 NAME
+
+Mail::Message::Encode - handle a MIME encoded string
+
+=head1 SYNOPSIS
+
+ use Mail::Message::Encode qw(decode_mime_string encode_mime_string);
+ $decoded = decode_mime_string( $message );
+
+=head1 DESCRIPTION
+
+MIME utilities to encode and decode string.
+It uses C<MIME::Base64> and C<MIME::QuotedPrint> as encoding/decoding
+engines.
+
+=head1 METHODS
+
+=cut
+
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(decode_mime_string encode_mime_string);
+
+
+=head2 C<encode_mime_string(string, [$options])>
+
+encode the C<string> by the encoder $options->{ encode }.
+The encode is base64 by default.
+
+C<options> is a HASH REFERENCE.
+You can specify the charset of string to return
+by $options->{ charset }.
+
+=cut
+
+
+sub encode_mime_string
+{
+ my ($str, $options) = @_;
+ my $charset = $options->{ 'charset' } || 'iso-2022-jp';
+ my $encode = $options->{ 'encode' } || 'base64';
+ my $header = '=?'. $charset;
+ my $trailor = '?=';
+
+ use Jcode;
+ &Jcode::convert(\$str, 'jis');
+
+ use IM::Iso2022jp;
+
+ if ($encode eq 'base64') {
+ line_iso2022jp_mimefy($str);
+ }
+ elsif ($encode eq 'qp') {
+ $main::HdrQEncoding = 1;
+ line_iso2022jp_mimefy($str);
+ $main::HdrQEncoding = 0;
+ }
+
+ return $str;
+}
+
+
+=head1 SEE ALSO
+
+L<Jcode>,
+L<MIME::Base64>,
+L<MIME::QuotedPrint>.
+
+=head1 AUTHOR
+
+Ken'ichi Fukamachi
+
+=head1 COPYRIGHT
+
+Copyright (C) 2001 Ken'ichi Fukamachi
+
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the same terms as Perl itself.
+
+=head1 HISTORY
+
+Mail::Message::Encode appeared in fml5 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+
+1;