| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
=head1 NAME
|
| 3 |
|
|
|
| 4 |
|
|
Message::Util Perl module
|
| 5 |
|
|
|
| 6 |
|
|
=head1 DESCRIPTION
|
| 7 |
|
|
|
| 8 |
|
|
Utilities for Message::* Perl modules.
|
| 9 |
|
|
|
| 10 |
|
|
=cut
|
| 11 |
|
|
|
| 12 |
|
|
package Message::Util;
|
| 13 |
|
|
use strict;
|
| 14 |
|
|
use vars qw(%REG $VERSION);
|
| 15 |
|
|
$VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 16 |
|
|
|
| 17 |
|
|
$REG{WSP} = qr/[\x09\x20]/;
|
| 18 |
|
|
$REG{FWS} = qr/[\x09\x20]*/;
|
| 19 |
|
|
|
| 20 |
wakaba |
1.2 |
sub encode_header_string ($$;%) {
|
| 21 |
wakaba |
1.1 |
require Message::MIME::Charset;
|
| 22 |
|
|
my $self = shift; my $s = shift; my %o = @_;
|
| 23 |
|
|
$o{charset} ||= $self->{option}->{encoding_after_encode};
|
| 24 |
|
|
$o{charset} = Message::MIME::Charset::name_normalize ($o{charset});
|
| 25 |
|
|
$o{current_charset} = Message::MIME::Charset::name_normalize ($o{current_charset});
|
| 26 |
|
|
my ($t,$r) = Message::MIME::Charset::encode ($o{charset}, $s);
|
| 27 |
|
|
my @o = (language => $o{language});
|
| 28 |
|
|
if ($r>0) { ## Convertion successed
|
| 29 |
|
|
(value => $t, @o, charset => ($o{charset}=~/\*/?'':$o{charset}));
|
| 30 |
|
|
} else { ## Fault
|
| 31 |
|
|
(value => $s, @o, charset => ($o{current_charset}=~/\*/?'':$o{current_charset}));
|
| 32 |
|
|
}
|
| 33 |
|
|
}
|
| 34 |
|
|
|
| 35 |
wakaba |
1.2 |
sub decode_header_string ($$;%) {
|
| 36 |
wakaba |
1.1 |
require Message::MIME::EncodedWord;
|
| 37 |
|
|
require Message::MIME::Charset;
|
| 38 |
|
|
my $self = shift; my $s = shift; my %o = @_;
|
| 39 |
|
|
$o{charset} ||= $self->{option}->{encoding_before_decode};
|
| 40 |
|
|
$o{charset} = Message::MIME::Charset::name_normalize ($o{charset});
|
| 41 |
|
|
$s = Message::MIME::EncodedWord::decode ($s)
|
| 42 |
|
|
if $o{type} !~ /quoted/ && $o{type} !~ /encoded/;
|
| 43 |
|
|
my ($t,$r) = Message::MIME::Charset::decode ($o{charset}, $s);
|
| 44 |
|
|
$r>0 ? (value => $t, language => $o{language}): ## suceess
|
| 45 |
|
|
(value => $s, language => $o{language},
|
| 46 |
|
|
charset => ($o{charset}=~/\*/?'':$o{charset})); ## fault
|
| 47 |
|
|
}
|
| 48 |
|
|
|
| 49 |
|
|
sub encode_body_string {
|
| 50 |
|
|
require Message::MIME::Charset;
|
| 51 |
|
|
my $self = shift; my $s = shift; my %o = @_;
|
| 52 |
|
|
$o{charset} ||= $self->{option}->{encoding_after_encode};
|
| 53 |
|
|
$o{charset} = Message::MIME::Charset::name_normalize ($o{charset});
|
| 54 |
|
|
$o{current_charset} = Message::MIME::Charset::name_normalize ($o{current_charset});
|
| 55 |
|
|
my ($t,$r) = Message::MIME::Charset::encode ($o{charset}, $s);
|
| 56 |
|
|
my @o = ();
|
| 57 |
|
|
if ($r>0) { ## Convertion successed
|
| 58 |
|
|
(value => $t, @o, charset => ($o{charset}=~/\*/?'':$o{charset}));
|
| 59 |
|
|
} else { ## Fault
|
| 60 |
|
|
(value => $s, @o, charset => ($o{current_charset}=~/\*/?'':$o{current_charset}));
|
| 61 |
|
|
}
|
| 62 |
|
|
}
|
| 63 |
|
|
|
| 64 |
|
|
sub decode_body_string {
|
| 65 |
|
|
require Message::MIME::EncodedWord;
|
| 66 |
|
|
require Message::MIME::Charset;
|
| 67 |
|
|
my $self = shift; my $s = shift; my %o = @_;
|
| 68 |
|
|
$o{charset} ||= $self->{option}->{encoding_before_decode};
|
| 69 |
|
|
$o{charset} = Message::MIME::Charset::name_normalize ($o{charset});
|
| 70 |
|
|
my ($t,$r) = Message::MIME::Charset::decode ($o{charset}, $s);
|
| 71 |
|
|
$r>0 ? (value => $t): ## suceess
|
| 72 |
|
|
(value => $s,
|
| 73 |
|
|
charset => ($o{charset}=~/\*/?'':$o{charset})); ## fault
|
| 74 |
|
|
}
|
| 75 |
|
|
|
| 76 |
|
|
=head1 LICENSE
|
| 77 |
|
|
|
| 78 |
|
|
Copyright 2002 wakaba E<lt>[email protected]<gt>.
|
| 79 |
|
|
|
| 80 |
|
|
This program is free software; you can redistribute it and/or modify
|
| 81 |
|
|
it under the terms of the GNU General Public License as published by
|
| 82 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
| 83 |
|
|
(at your option) any later version.
|
| 84 |
|
|
|
| 85 |
|
|
This program is distributed in the hope that it will be useful,
|
| 86 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 87 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 88 |
|
|
GNU General Public License for more details.
|
| 89 |
|
|
|
| 90 |
|
|
You should have received a copy of the GNU General Public License
|
| 91 |
|
|
along with this program; see the file COPYING. If not, write to
|
| 92 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
| 93 |
|
|
Boston, MA 02111-1307, USA.
|
| 94 |
|
|
|
| 95 |
|
|
=head1 CHANGE
|
| 96 |
|
|
|
| 97 |
|
|
See F<ChangeLog>.
|
| 98 |
wakaba |
1.2 |
$Date: 2002/03/25 10:18:35 $
|
| 99 |
wakaba |
1.1 |
|
| 100 |
|
|
=cut
|
| 101 |
|
|
|
| 102 |
|
|
1;
|