diff options
| author | fukachan <fukachan> | 2004-02-04 15:09:55 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2004-02-04 15:09:55 +0000 |
| commit | d95b392a70d189ea4789cfef93d85060f385b2f1 (patch) | |
| tree | 7b948f0704b62342054467c7896fd168754a4013 /fml | |
| parent | 9b2d3542eb23d230c525044364b89a449b3060fc (diff) | |
| download | fml8-d95b392a70d189ea4789cfef93d85060f385b2f1.tar.gz fml8-d95b392a70d189ea4789cfef93d85060f385b2f1.tar.bz2 fml8-d95b392a70d189ea4789cfef93d85060f385b2f1.zip | |
change in-core internal variables.
implement set(), get(), set_mime_charset(), get_mime_charset and
unfold().
Diffstat (limited to 'fml')
| -rw-r--r-- | fml/lib/Mail/Message/String.pm | 151 |
1 files changed, 135 insertions, 16 deletions
diff --git a/fml/lib/Mail/Message/String.pm b/fml/lib/Mail/Message/String.pm index 0f94c7cf..967c93f3 100644 --- a/fml/lib/Mail/Message/String.pm +++ b/fml/lib/Mail/Message/String.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: @template.pm,v 1.8 2004/01/01 07:29:27 fukachan Exp $ +# $FML: String.pm,v 1.1 2004/01/31 06:32:58 fukachan Exp $ # package Mail::Message::String; @@ -15,10 +15,14 @@ use Carp; =head1 NAME -Mail::Message::String - what is this +Mail::Message::String - base class of string used in message (header). =head1 SYNOPSIS + package Mail::Message::Subject: + use Mail::Message::String; + @ISA = qw(Mail::Message::String); + =head1 DESCRIPTION =head1 METHODS @@ -36,23 +40,55 @@ sub new { my ($self, $str) = @_; my ($type) = ref($self) || $self; - my $me = { - _str => $str, - _orig_str => $str, - }; + my $me = {}; + set($me, $str); + $me->{ _orig_string } = $str; return bless $me, $type; } +=head2 set($str) + +initialize data in this object. + +=head2 get() + +get (converted) data in this object as string (same as as_str()). + +=cut + + +# Descriptions: initialize data in this object. +# Arguments: OBJ($self) STR($str) +# Side Effects: none +# Return Value: OBJ +sub set +{ + my ($self, $str) = @_; + $self->{ _string } = $str; +} + + +# Descriptions: get data in this object as string (same as as_str()). +# Arguments: OBJ($self) +# Side Effects: none +# Return Value: OBJ +sub get +{ + my ($self) = @_; + $self->as_str(); +} + + =head2 as_str() -return String by string. +return data (converted data) by string. =cut -# Descriptions: return String by string. +# Descriptions: return data (converted data) by string. # Arguments: OBJ($self) # Side Effects: none # Return Value: STR @@ -60,16 +96,28 @@ sub as_str { my ($self) = @_; - return( $self->{ _str } || '' ); + return( $self->{ _string } || '' ); } -=head1 MIME ENCODE/DECODE +=head1 MIME related utilities =head2 mime_encode($encode, $out_code, $in_code) +mime encode this object and return the encoded string. + =head2 mime_decode($out_code, $in_code) +mime decode this object and return the decoded string. + +=head2 set_mime_charset($charset) + +dummy now. + +=head2 get_mime_charset() + +return charset information. + =cut @@ -80,7 +128,7 @@ sub as_str sub mime_encode { my ($self, $encode, $out_code, $in_code) = @_; - my $str = $self->{ _str }; + my $str = $self->{ _string }; # base64 encoding by default. $encode ||= 'base64'; @@ -88,7 +136,7 @@ sub mime_encode use Mail::Message::Encode; my $obj = new Mail::Message::Encode; $str = $obj->encode_mime_string($str, $encode, $out_code, $in_code); - $self->{ _str } = $str; + $self->{ _string } = $str; return $str; } @@ -101,14 +149,85 @@ sub mime_encode sub mime_decode { my ($self, $out_code, $in_code) = @_; - my $str = $self->{ _str }; + my $str = $self->{ _string }; use Mail::Message::Encode; my $encode = new Mail::Message::Encode; - my $dec_str = $encode->decode_mime_string($str, $out_code, $in_code); - $self->{ _str } = $dec_str; + my $dec_string = $encode->decode_mime_string($str, $out_code, $in_code); + $self->{ _string } = $dec_string; + + return $dec_string; +} + + +# Descriptions: dummy now. enforce charset to handle. +# Arguments: OBJ($self) STR($charset) +# Side Effects: none +# Return Value: none + +sub set_mime_charset +{ + my ($self, $charset) = @_; + +} + + +# Descriptions: return charset information. +# Arguments: OBJ($self) +# Side Effects: none +# Return Value: STR +sub get_mime_charset +{ + my ($self) = @_; + my $str = $self->{ _string }; + + if ($str =~ /\=\?([-\w\d]+)\?/o) { + my $charset = $1; + $charset =~ tr/A-Z/a-z/; + return $charset; + } + else { + return ''; + } +} + + +=head1 UTILITIES + +=head2 unfold() + +unfold in-core data. - return $dec_str; +=cut + + +# Descriptions: unfold in-core data. +# Arguments: OBJ($self) +# Side Effects: update $self->{ _string } +# Return Value: STR +sub unfold +{ + my ($self) = @_; + my $str = $self->{ _string }; + + $str =~ s/\s*\n/ /g; + $str =~ s/\s+/ /g; + + # save and return it. + $self->{ _string } = $str; + return $str; +} + + + + +# +# debug +# +if ($0 eq __FILE__) { + my $str = '=?ISO-2022-JP?B?GyRCJDckRCRiJHMbKEI=?='; + my $obj = new Mail::Message::String $str; + print $obj->get_mime_charset() ,"\n"; } |
