summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-03-26 03:33:41 +0000
committerfukachan <fukachan>2001-03-26 03:33:41 +0000
commit617fb21dfdeb5a53b421376358e6babdef2ccd59 (patch)
treeaf7803857a85aad5cee66488992de21751ac218c
parente9d844f09e6a4ca2294e30bb0bd6f7bb0ade542c (diff)
downloadfml8-617fb21dfdeb5a53b421376358e6babdef2ccd59.tar.gz
fml8-617fb21dfdeb5a53b421376358e6babdef2ccd59.tar.bz2
fml8-617fb21dfdeb5a53b421376358e6babdef2ccd59.zip
implement MailingList::Messages::num_paragram() and make test tools for it.
it return the number of paragraph in the message ($self). modify MailingList::Messages::get_content_type() which removes ";" for convenience.
-rw-r--r--fml/lib/MailingList/Messages.pm64
-rwxr-xr-xregress/base/get_paragraph_info.pl89
-rwxr-xr-xregress/base/mime.pl4
-rw-r--r--regress/testmails/text=plain226
4 files changed, 181 insertions, 2 deletions
diff --git a/fml/lib/MailingList/Messages.pm b/fml/lib/MailingList/Messages.pm
index 9b5ddde7..0fe60af9 100644
--- a/fml/lib/MailingList/Messages.pm
+++ b/fml/lib/MailingList/Messages.pm
@@ -766,7 +766,69 @@ sub is_empty
sub get_content_type
{
my ($self) = @_;
- $self->{ content_type };
+ my $type = $self->{ content_type };
+ $type =~ s/;//;
+ $type;
+}
+
+
+=head2 C<num_paragraph()>
+
+return the number of paragraphs in the message ($self).
+
+=cut
+
+sub num_paragraph
+{
+ my ($self) = @_;
+
+ # exit ASAP if the message is empty.
+ return 0 if $self->is_empty();
+
+ my $pb = $self->{ offset_begin };
+ my $pe = $self->{ offset_end };
+ my $bodylen = $self->size;
+ my $content = $self->{ content };
+
+ my $i = 0; # the number of paragraphs
+ my $p = $pb;
+ my $pp = $p;
+
+ # skip "\n" in the first and end of the buffer
+ while (substr($$content, $p, 1) eq "\n") { $p++;}
+ while (substr($$content, $pe -1, 1) eq "\n") { $pe--;}
+
+ my (@pmap) = ($pb);
+ LINE:
+ while ($p < $pe) {
+ $pp = index($$content, "\n\n", $p);
+ if ($pp < $p || # not found
+ $pp >= $pe ) { # over the end of buffer boundary
+
+ push(@pmap, $pe); # the end of the last paragraph
+ last LINE;
+ }
+ else {
+ # skip trailing "\n" after "\n\n"
+ while (substr($$content, $pp, 1) eq "\n") { $pp++;}
+
+ push(@pmap, $pp) if $pp > 0;
+
+ $p = $pp;
+ }
+ }
+
+ # XXX debug
+ if (0) {
+ for (my $i = 0; $i < $#pmap; $i++ ) {
+ my $p = $pmap[ $i ];
+ my $pp = $pmap[ $i + 1 ];
+ print STDERR "($p,$pp)<", substr($$content, $p, $pp - $p) , ">\n";
+ }
+ print STDERR "( @pmap )\n";
+ }
+
+ $#pmap;
}
diff --git a/regress/base/get_paragraph_info.pl b/regress/base/get_paragraph_info.pl
new file mode 100755
index 00000000..a78ac5d4
--- /dev/null
+++ b/regress/base/get_paragraph_info.pl
@@ -0,0 +1,89 @@
+use strict;
+use File::Basename;
+use vars qw(%opts);
+
+use Getopt::Std;
+getopts('d', \%opts);
+
+my $dir = dirname($0);
+$| = 1;
+
+my $msg = shift @ARGV || "$dir/msg_mp";
+
+use FileHandle;
+my $fh = new FileHandle $msg;
+
+my $header;
+my $boundary;
+my $content_type;
+my $body;
+
+while (<$fh>) {
+ s/\r\n$/\n/;
+
+ if (1 .. /^$/) {
+ $header .= $_;
+ if (/boundary=\"(.*)\"/) {
+ $boundary = $1;
+ }
+ if (/Content-Type: (\S+\/\S+\w)/) {
+ $content_type = $1;
+ }
+ }
+ else {
+ $body .= $_;
+ }
+}
+
+my $original_length = length($body);
+
+use MailingList::Messages;
+my $m = new MailingList::Messages {
+ content_type => ($content_type || 'multipart/mixed'),
+ boundary => $boundary,
+ content => \$body,
+ debug => 1,
+};
+
+$m->print;
+my $mp = $m->get_first_plaintext_message ;
+print "// first plain/text message\n";
+$mp->print;
+print "//\n";
+debug( $mp );
+
+exit 0;
+
+
+sub debug
+{
+ my ($m) = @_;
+
+ unless (defined $m) {
+ use Carp;
+ croak("debug gets non-object\n");
+ }
+
+ my $p;
+ my $total=0;
+ my $i = 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;
+
+ $i++;
+ print STDERR "--------- $i ---------\n";
+ print STDERR "num_p:", $p->num_paragraph, "\n\n";
+ next;
+
+ 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;
+ }
+}
diff --git a/regress/base/mime.pl b/regress/base/mime.pl
index 995ec64c..5add052c 100755
--- a/regress/base/mime.pl
+++ b/regress/base/mime.pl
@@ -14,16 +14,18 @@ use MIME::QuotedPrint;
&try_mime(" ");
&try_mime(" ");
&try_mime("\n");
+&try_mime(" ", 3);
exit 0;
sub try_mime
{
- my ($separator) = @_;
+ my ($separator, $xbuf) = @_;
my $buf = "\n";
my $orig_str = "うじゃ". $separator ."あじゃじゃ";
+ $orig_str = "うじゃ". $separator . $xbuf . "あじゃじゃ" if $xbuf;
my $in_str_b64 = encode_mime_string($orig_str);
my $in_str_qp = encode_mime_string($orig_str, { encode => 'qp' });
diff --git a/regress/testmails/text=plain2 b/regress/testmails/text=plain2
new file mode 100644
index 00000000..aa0d7773
--- /dev/null
+++ b/regress/testmails/text=plain2
@@ -0,0 +1,26 @@
+From owner-elena@elena.sapporo.iij.ad.jp Fri Jan 26 00:11:07 2001
+Return-Path: <fukachan@fml.org>
+Received: from hikari.fml.org (hikari.fml.org [192.168.1.6])
+ by elena.fml.org (Postfix) with ESMTP id C995C1D8C9
+ for <mailbox@elena.fml.org>; Tue, 2 Jan 2001 17:08:05 +0900 (JST)
+Received: by hikari.fml.org (8.9.3/3.4W6+Hikari-2.1) with ESMTP id RAA17788 for <caesar@fml.org>; Tue, 2 Jan 2001 17:08:04 +0900 (JST)
+Received: by iris.fml.org (Postfix, from userid 0)
+ id 1BCBE15024; Tue, 2 Jan 2001 17:08:03 +0900 (JST)
+From: fukachan@sapporo.iij.ad.jp (Ken'ichi Fukamachi)
+To: elena@nuinui.net
+Reply-To: rudo@nuinui.net
+Subject: [elena:00300] test 01
+ appended_mesg
+Message-Id: <20010102080803.1BCBE15024@iris.fml.org>
+Date: Tue, 2 Jan 2001 17:08:03 +0900 (JST)
+Mime-Version: 1.0
+Content-Type: text/plain; charset=ISO-2022-JP
+Content-Transfer-Encoding: 7bit
+
+test message
+
+
+
+
+-- rudo's mabuachi
+