diff options
| author | fukachan <fukachan> | 2001-02-12 14:48:10 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-02-12 14:48:10 +0000 |
| commit | cc3c5801ca3b1ecaa57d75d9dcb070e7a6e4b176 (patch) | |
| tree | 6e2e634185907ab61255500bc9a508f3853b2486 | |
| parent | 1bae97a38f1fcdff7c8c5c0d4ca940802470dec1 (diff) | |
| download | fml8-cc3c5801ca3b1ecaa57d75d9dcb070e7a6e4b176.tar.gz fml8-cc3c5801ca3b1ecaa57d75d9dcb070e7a6e4b176.tar.bz2 fml8-cc3c5801ca3b1ecaa57d75d9dcb070e7a6e4b176.zip | |
MailingList::Messages
clean up documentations
fix get_content_type()
check more whether $self is defined or not
| -rw-r--r-- | fml/lib/MailingList/Messages.pm | 57 | ||||
| -rw-r--r-- | regress/base/multipart_io.pl | 35 |
2 files changed, 68 insertions, 24 deletions
diff --git a/fml/lib/MailingList/Messages.pm b/fml/lib/MailingList/Messages.pm index 559ef100..1469972e 100644 --- a/fml/lib/MailingList/Messages.pm +++ b/fml/lib/MailingList/Messages.pm @@ -730,17 +730,25 @@ return the message size. return this message has empty content or not. -=head2 C<set_log_function()> - -internal use. set CODE REFERENCE to the log function - =cut + my $total = 0; sub size { my ($self) = @_; - my $c = $self->{ content }; - length($$c); + my $rc = $self->{ content }; + my $pb = $self->{ offset_begin }; + my $pe = $self->{ offset_end }; + + if ((defined $pe) && (defined $pb)) { + if ($pe - $pb > 0) { + $total += ($pe - $pb); + return ($pe - $pb); + } + } + else { + defined $rc ? length($$rc) : 0; + } } @@ -748,11 +756,11 @@ sub is_empty { my ($self) = @_; my $size = $self->size; - my $c = $self->{ content }; + my $rc = $self->{ content }; if ($size == 0) { return 1;} if ($size <= 8) { - if ($$c =~ /^\s*$/) { return 1;} + if ($$rc =~ /^\s*$/) { return 1;} } # false @@ -760,13 +768,6 @@ sub is_empty } -sub set_log_function -{ - my ($self, $fp) = @_; - $self->{ _log_function } = $fp; # log function pointer -} - - sub get_content_type { my ($self) = @_; @@ -799,11 +800,7 @@ where $body is the mail body (string). sub get_content_header { my ($self, $size) = @_; - my $content = $self->{ content }; - my $pos = index($$content, "\n\n", $self->{ offset_begin }); - my $len = $pos - $self->{ offset_begin }; - - substr($$content, $self->{ offset_begin }, $len); + return defined $self->{ header } ? $self->{ header } : undef; } @@ -814,9 +811,11 @@ sub get_content_body my $base_content_type = $self->{ base_content_type }; my ($pos, $pos_begin, $msglen); + # if the content is undef, do nothing. + return undef unless $content; + if ($base_content_type =~ /multipart/i) { - $pos = index($$content, "\n\n", $self->{ offset_begin }); - $pos_begin = $pos + 2; + $pos_begin = $self->{ offset_begin }; $msglen = $self->{ offset_end } - $pos_begin; } else { @@ -871,6 +870,20 @@ For example, C<get_content_reference()> returns the reference to the content of the message. +=head2 C<set_log_function()> + +internal use. set CODE REFERENCE to the log function + +=cut + +sub set_log_function +{ + my ($self, $fp) = @_; + $self->{ _log_function } = $fp; # log function pointer +} + + + =head1 APPENDIX (RFC2046 Appendix A) Appendix A -- Collected Grammar diff --git a/regress/base/multipart_io.pl b/regress/base/multipart_io.pl index 2de2f50a..379b5632 100644 --- a/regress/base/multipart_io.pl +++ b/regress/base/multipart_io.pl @@ -1,11 +1,14 @@ use strict; use File::Basename; +use vars qw(%opts); -my $dir = dirname($0); +use Getopt::Std; +getopts('d', \%opts); +my $dir = dirname($0); $| = 1; -my $msg = shift || "$dir/msg_mp"; +my $msg = shift @ARGV || "$dir/msg_mp"; use FileHandle; my $fh = new FileHandle $msg; @@ -15,6 +18,8 @@ my $boundary; my $body; while (<$fh>) { + s/\r\n$/\n/; + if (1 .. /^$/) { $header .= $_; if (/boundary=\"(.*)\"/) { @@ -26,6 +31,8 @@ while (<$fh>) { } } +my $original_length = length($body); + use MailingList::Messages; my $m = new MailingList::Messages { content_type => 'multipart/mixed', @@ -36,4 +43,28 @@ my $m = new MailingList::Messages { $m->print; +if ($opts{ d }) { debug( $m );} + exit 0; + + +sub debug +{ + my ($m) = @_; + + my $p; + my $total=0; + for ($p = $m; defined $p ; $p = $p->{ next }) { + my $size = $p->size; + my $h = $p->get_content_header; + $size += length($h) if defined $h; + + $total += $size; + print STDERR "type: ", $p->get_content_type, "\n"; + print STDERR " hdr:{", $h, "}\n"; + print STDERR "body:{", $p->get_content_body, "}\n"; + print STDERR "size: ", $size, " / $total (<= $original_length)\n"; + print STDERR "\n"; + sleep 3; + } +} |
