diff options
| author | fukachan <fukachan> | 2005-08-31 11:13:03 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2005-08-31 11:13:03 +0000 |
| commit | 6ff2b62ebd1c4099ec369c675731b5c383b0efd1 (patch) | |
| tree | ececd049b1fbc78eebb09aa37fff80920f361cad /fml/lib/Mail/Message.pm | |
| parent | 029213179edf2294c6b472a091dd268686055a54 (diff) | |
| download | fml8-6ff2b62ebd1c4099ec369c675731b5c383b0efd1.tar.gz fml8-6ff2b62ebd1c4099ec369c675731b5c383b0efd1.tar.bz2 fml8-6ff2b62ebd1c4099ec369c675731b5c383b0efd1.zip | |
implement new method prepend(), append() and whole_message_body_tail().
fix charset() logic to handle plural header field lines.
Diffstat (limited to 'fml/lib/Mail/Message.pm')
| -rw-r--r-- | fml/lib/Mail/Message.pm | 110 |
1 files changed, 103 insertions, 7 deletions
diff --git a/fml/lib/Mail/Message.pm b/fml/lib/Mail/Message.pm index 30609c60..d0e7dd1d 100644 --- a/fml/lib/Mail/Message.pm +++ b/fml/lib/Mail/Message.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: Message.pm,v 1.97 2004/07/26 06:39:16 fukachan Exp $ +# $FML: Message.pm,v 1.98 2004/12/08 10:07:44 fukachan Exp $ # package Mail::Message; @@ -655,6 +655,87 @@ sub _build_body_object } +=head2 prepend($data) + +prepend the message to the object chain. + +=head2 append($data) + +append the message to the object chain. + +=cut + + +# Descriptions: prepend the message to the object chain. +# Arguments: OBJ($self) HASH_REF($data) +# Side Effects: update the chain of objects. +# Return Value: none +sub prepend +{ + my ($self, $data) = @_; + my $dp = $self->__build_message($data); + + # cut and paste a new chain. + my $orig_prev = $self->{ prev }; + _prev_message_is($self, $dp); + _prev_message_is($dp, $orig_prev); + + _next_message_is($dp, $self); + _next_message_is($orig_prev, $dp); +} + + +# Descriptions: append the message to the object chain. +# Arguments: OBJ($self) HASH_REF($data) +# Side Effects: update the chain of objects. +# Return Value: none +sub append +{ + my ($self, $data) = @_; + my $dp = $self->__build_message($data); + + # cut and paste a new chain. + my $orig_next = $self->{ next }; + _next_message_is($self, $dp); + _next_message_is($dp, $orig_next); + _prev_message_is($dp, $self); + _prev_message_is($orig_next, $dp); +} + + +# Descriptions: build a Mail::Message object. +# Arguments: OBJ($self) HASH_REF($data) +# Side Effects: none +# Return Value: OBJ +sub __build_message +{ + my ($self, $data) = @_; + my $dp = undef; + + if (ref($data) eq 'Mail::Message') { + return $data; + } + else { + my $my_charset = $self->charset(); + my $charset = $data->{ charset } || 'unknown'; + my $type = $data->{ type } || 'unknown'; + my $buf = $data->{ data } || ''; + + if ($type eq 'text/plain' && $my_charset eq $charset) { + return new Mail::Message { + data_type => $type, + data => \$buf, + }; + } + else { + carp("append: unknown type"); + } + } + + return undef; +} + + =head2 whole_message_header() return Mail::Header object corresponding to the header part for the @@ -712,6 +793,18 @@ sub whole_message_body_head } +# Descriptions: get the last OBJ of body part in the chain. +# header -> body1 (HERE) -> body2 -> ... -> body_last +# Arguments: OBJ($self) +# Side Effects: none +# Return Value: OBJ(Mail::Message) +sub whole_message_body_tail +{ + my ($self) = @_; + return $self->__last_message(); +} + + # Descriptions: get the head OBJ of body part in the chain. # header -> body1 (HERE) -> body2 -> ... # Arguments: OBJ($self) @@ -2289,12 +2382,15 @@ sub charset return $self->{ charset }; } # content-type: text/plain; charset=ISO-2022-JP - elsif (defined($buf) && - ($buf =~ /Content-Type:.*charset=\"(\S+)\"/i || - $buf =~ /Content-Type:.*charset=(\S+)/i)) { - my $charset = $1; - $charset =~ tr/A-Z/a-z/; - return $charset; + elsif (defined($buf) && $buf) { + my $_buf = $buf; + $_buf =~ s/\s*//gm; + if ($_buf =~ /Content-Type:.*charset=\"(\S+)\"/i || + $_buf =~ /Content-Type:.*charset=(\S+)/i) { + my $charset = $1; + $charset =~ tr/A-Z/a-z/; + return $charset; + } } else { return undef; |
