diff options
| author | fukachan <fukachan> | 2001-04-09 14:07:01 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-04-09 14:07:01 +0000 |
| commit | 17a1a55b6848a10fe19172eeb643ee06a7f8f2b3 (patch) | |
| tree | d5c33e2dc08790930d2d16b515e3d7832ba8fde1 /fml | |
| parent | 9f8b235be0dc1a046c422c9f79857d3e551b7ac0 (diff) | |
| download | fml8-17a1a55b6848a10fe19172eeb643ee06a7f8f2b3.tar.gz fml8-17a1a55b6848a10fe19172eeb643ee06a7f8f2b3.tar.bz2 fml8-17a1a55b6848a10fe19172eeb643ee06a7f8f2b3.zip | |
define nth_paragraph()
Diffstat (limited to 'fml')
| -rw-r--r-- | fml/lib/Mail/Message.pm | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/fml/lib/Mail/Message.pm b/fml/lib/Mail/Message.pm index 21938f1e..dc7d44af 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.10 2001/04/08 14:29:47 fukachan Exp $ +# $FML: Message.pm,v 1.11 2001/04/08 16:15:45 fukachan Exp $ # package Mail::Message; @@ -1299,6 +1299,12 @@ sub get_data_type return the number of paragraphs in the message ($self). +=head2 C<nth_paragraph($n)> + +return the string of C<$n>-th paragraph. +For example, C<nth_paragraph(1)> returns the 1st paragraph. +The syntax is usual not C language flabour. + =cut @@ -1313,6 +1319,29 @@ sub num_paragraph # exit ASAP if the message is empty. return 0 if $self->is_empty(); + my $pmap = $self->_evaluate_pmap(); + + # number of paratrah == the max element + $#$pmap; +} + + +sub nth_paragraph +{ + my ($self, $i) = @_; + my $data = $self->{ data }; + my $pmap = $self->_evaluate_pmap(); + + $i--; # shift $i: 1 => 0, 2 =>1, et. al. + my ($pb, $pe) = ($pmap->[ $i ], $pmap->[ $i + 1 ]); + return substr($$data, $pb, $pe - $pb); +} + + +sub _evaluate_pmap +{ + my ($self) = @_; + my $pb = $self->{ offset_begin }; my $pe = $self->{ offset_end }; my $bodylen = $self->size; @@ -1356,7 +1385,7 @@ sub num_paragraph print STDERR "( @pmap )\n"; } - $#pmap; + return \@pmap; } |
