Header.pm revision 7c478bd95313f5f23a4c958a745db2134aa03244
use strict;
# use warnings;
use Carp;
my %seed =
(
);
bless {
%seed,
Name => 'MIME-Header',
} => __PACKAGE__;
bless {
%seed,
decode_q => 0,
Name => 'MIME-B',
} => __PACKAGE__;
bless {
%seed,
decode_q => 1,
encode => 'Q',
Name => 'MIME-Q',
} => __PACKAGE__;
sub needs_lines { 1 }
sub perlio_ok{ 0 };
sub decode($$;$){
use utf8;
# zap spaces between encoded words
# multi-line header to single line
$str =~
s{
=\? # begin encoded word
\?([QqBb])\? # delimiter
(.*?) # Base64-encodede contents
\?= # end encoded word
}{
if (uc($2) eq 'B'){
}elsif(uc($2) eq 'Q'){
}else{
}
}egox;
return $str;
}
sub decode_b{
my $enc = shift;
my $db64 = decode_base64(shift);
return $d->name eq 'utf8' ?
}
sub decode_q{
my ($enc, $q) = @_;
$q =~ s/_/ /go;
return $d->name eq 'utf8' ?
}
my $especials =
join('|' =>
map {quotemeta(chr($_))}
unpack("C*", qq{()<>@,;:\"\'/[]?.=}));
my $re_encoded_word =
qr{
(?:
=\? # begin encoded word
\?(?:[QqBb])\? # delimiter
(?:.*?) # Base64-encodede contents
\?= # end encoded word
)
}xo;
sub encode($$;$){
my @line = ();
}else{
}
}
my $subline = '';
use bytes ();
$subline = '';
}
}
}
return join("\n", @line);
}
sub _encode{
my ($o, $str) = @_;
# to coerce a floating-point arithmetics, the following contains
# .0 in numbers -- dankogai
my @result = ();
my $chunk = '';
use bytes ();
$chunk = '';
}
}
return @result;
}
sub _encode_b{
}
sub _encode_q{
my $chunk = shift;
$chunk =~ s{
}{
join("" => map {sprintf "=%02X", $_} unpack("C*", $1))
}egox;
}
1;
=head1 NAME
Encode::MIME::Header -- MIME 'B' and 'Q' header encoding
=head1 SYNOPSIS
$utf8 = decode('MIME-Header', $header);
$header = encode('MIME-Header', $utf8);
=head1 ABSTRACT
This module implements RFC 2047 Mime Header Encoding. There are 3
variant encoding names; C<MIME-Header>, C<MIME-B> and C<MIME-Q>. The
difference is described below
decode() encode()
----------------------------------------------
MIME-Header Both B and Q =?UTF-8?B?....?=
MIME-B B only; Q croaks =?UTF-8?B?....?=
MIME-Q Q only; B croaks =?UTF-8?Q?....?=
=head1 DESCRIPTION
When you decode(=?I<encoding>?I<X>?I<ENCODED WORD>?=), I<ENCODED WORD>
is extracted and decoded for I<X> encoding (B for Base64, Q for
Quoted-Printable). Then the decoded chunk is fed to
decode(I<encoding>). So long as I<encoding> is supported by Encode,
any source encoding is fine.
When you encode, it just encodes UTF-8 string with I<X> encoding then
quoted with =?UTF-8?I<X>?....?= . The parts that RFC 2047 forbids to
encode are left as is and long lines are folded within 76 bytes per
line.
=head1 BUGS
It would be nice to support encoding to non-UTF8, such as =?ISO-2022-JP?
and =?ISO-8859-1?= but that makes the implementation too complicated.
These days major mail agents all support =?UTF-8? so I think it is
just good enough.
=head1 SEE ALSO
L<Encode>
RFC 2047, L<http://www.faqs.org/rfcs/rfc2047.html> and many other
locations.
=cut