summaryrefslogtreecommitdiff
path: root/fml
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-08-19 14:59:07 +0000
committerfukachan <fukachan>2001-08-19 14:59:07 +0000
commit5de99962255113ec5cdddf10ac2c8e78e2576285 (patch)
tree9fde3b8ac7a0877d43f10acfb915eefaf19e3755 /fml
parent3308cfd1487f7f5b8b722910ed810cfd5680259f (diff)
downloadfml8-5de99962255113ec5cdddf10ac2c8e78e2576285.tar.gz
fml8-5de99962255113ec5cdddf10ac2c8e78e2576285.tar.bz2
fml8-5de99962255113ec5cdddf10ac2c8e78e2576285.zip
implement need_one_line_check() and sub functions:
_check_this_paragraph(), is_citation(), is_signature(). It analyzes the message by paragraph to detect the number of paragraphs, paragraph content type e.g. citation, signature et. al.
Diffstat (limited to 'fml')
-rw-r--r--fml/lib/FML/Filter/BodyCheck.pm101
-rw-r--r--fml/lib/FML/Filter/Utils.pm59
2 files changed, 96 insertions, 64 deletions
diff --git a/fml/lib/FML/Filter/BodyCheck.pm b/fml/lib/FML/Filter/BodyCheck.pm
index 81575ecb..ff386cd2 100644
--- a/fml/lib/FML/Filter/BodyCheck.pm
+++ b/fml/lib/FML/Filter/BodyCheck.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: BodyCheck.pm,v 1.2 2001/03/30 09:18:43 fukachan Exp $
+# $FML: BodyCheck.pm,v 1.3 2001/08/05 14:35:50 fukachan Exp $
#
package FML::Filter::BodyCheck;
@@ -31,6 +31,8 @@ usual constructor.
=cut
+my $debug = $ENV{'debug'} ? 1 : 0;
+
sub new
{
@@ -80,8 +82,8 @@ sub body_check
# XXX for small enough buffer. The information comes from @pmap, but
# XXX we should implement methods for them within $m message object.
# get useful information for the message object.
- my $num_paragraph = $m->num_paragraph();
- my $is_one_line = $self->is_one_line_message($m);
+ my $num_paragraph = $m->num_paragraph();
+ my $need_one_line_check = $self->need_one_line_check($m);
## 5. preparation for main rules.
$self->clean_up_buffer($m);
@@ -218,18 +220,103 @@ sub clean_up_buffer
sub is_empty
{
- my $m;
+ my ($self, $m) = @_;
$m->is_empty();
}
-# XXX fml 4.0: If it has @ or ://, it must be a paragraph
-sub is_one_line_message
+
+sub need_one_line_check
{
- ;
+ my ($self, $m) = @_;
+ my $np = $m->num_paragraph;
+
+ if ($np == 1) {
+ return 1;
+ }
+ elsif ($np == 2) {
+ # if the seconda paragraph looks signature,
+ # this message has only one effective message (paragraph).
+ if ($self->is_signature($m->nth_paragraph(2))) {
+ return 1;
+ }
+ }
+ elsif ($np == 3) {
+ # case 1: data + citation + signature
+ # case 2: citation + data + signature
+ if ($self->is_signature($m->nth_paragraph(3))) {
+ if ($self->is_citation($m->nth_paragraph(1)) ||
+ $self->is_citation($m->nth_paragraph(2))) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
}
+# XXX fml 4.0 assumes:
+# XXX If the paragraph has @ or ://, it must be signature.
+sub _check_this_paragraph
+{
+ my ($self, $m) = @_;
+ my $np = $m->num_paragraph;
+ my $data = '';
+
+ for (my $i = 1; $i <= $np; $i++) { # XXX: 1 .. n (not 0 .. n-1)
+ if ($debug) { print STDERR "($i){", $data, "}\n";}
+ }
+}
+
+
+sub is_citation
+{
+ my ($self, $data) = @_;
+ my $trap_pat = ''; # keyword to trap citation at the head of the line
+
+ if ($data =~ /(\n.)/) { $trap_pat = quotemeta($1);}
+
+ # > a i u e o ...
+ # > ka ki ku ke ko ...
+ if ($data =~ /\n>/) { return 1;}
+ if ($trap_pat) { if ($data =~ /$trap_pat.*$trap_pat/) { return 1;}}
+
+ return 0;
+}
+
+
+# trap special keyword like tel:011-123-456789 ...
+sub is_signature
+{
+ my ($self, $data) = @_;
+
+ if ($data =~ /\@/ ||
+ $data =~ /TEL:/i ||
+ $data =~ /FAX:/i ||
+ $data =~ /:\/\// ) {
+ return 1;
+ }
+
+ # -- fukachan ( usenet style signature ? )
+ # // fukachan ( signature derived from what ? )
+ if ($data =~ /^--/ || $data =~ /^\/\//) {
+ return 1;
+ }
+
+ use FML::Language::ISO2022JP qw(STR2EUC);
+ $data = STR2EUC( $data );
+
+ # "2-byte @"domain where "@" is a 2-byte "@" character.
+ if ($data =~ /[-A-Za-z0-9]\241\367[-A-Za-z0-9]/) {
+ return 1;
+ }
+
+ return 0;
+}
+
+
+
=head1 AUTHOR
Ken'ichi Fukamachi
diff --git a/fml/lib/FML/Filter/Utils.pm b/fml/lib/FML/Filter/Utils.pm
index 6149a778..59ad045b 100644
--- a/fml/lib/FML/Filter/Utils.pm
+++ b/fml/lib/FML/Filter/Utils.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: Utils.pm,v 1.1.1.1 2001/03/28 15:13:31 fukachan Exp $
+# $FML: Utils.pm,v 1.2 2001/03/30 09:18:44 fukachan Exp $
#
package FML::Filter::Utils;
@@ -61,61 +61,6 @@ sub clean_up_buffer
}
-=head2 C<is_one_line($args)>
-
-=cut
-
-
-sub is_one_line
-{
- my ($self, $buf) = @_;
-
- local(*e, *pmap, $lparbuf) = @_;
- my($one_line_check_p) = 0;
- my($n_paragraph) = $#pmap;
-
- &Log("OneLineCheckP: n_paragraph=$n_paragraph") if $main::debug;
-
- if ($n_paragraph == 1) { $one_line_check_p = 1;}
- if ($n_paragraph == 2) {
- my($buf) = &main::STR2EUC($lparbuf);
- my($pat);
- if ($buf =~ /(\n.)/) { $pat = $1;}
-
- # basic citation ?
- if ($buf =~ /\n>/) {
- &Log("/^>/ lines! must be citation") if $main::debug;
- &Log("2 paragraphs but accept mail as citation");
- }
- # more functional citation ?:)
- # Oops ;-) This mail body is also a citation ;-) in this logic;)
- # Kenken
- # Kaisha
- #
- elsif ($pat && ($buf =~ /$pat.*$pat/)) {
- my ($p) = $pat;
- $p =~ s/\n//;
- &Log("plural /^$p/ lines! must be citation") if $main::debug;
- &Log("2 paragraphs but accept mail as citation");
- }
- elsif ($lparbuf =~ /\@/ ||
- $lparbuf =~ /TEL:/i ||
- $lparbuf =~ /FAX:/i ||
- $lparbuf =~ /:\/\// ) {
- &Log("2 paragraphs and 2nd one may be the signature");
- $one_line_check_p = 1;
- }
- # account"2-byte @"domain where "@" is a 2-byte "@" character.
- elsif ($buf =~ /[-A-Za-z0-9]\241\367[-A-Za-z0-9]/) {
- &Log("2 paragraphs and 2nd one may be the signature (2-byte \@)");
- $one_line_check_p = 1;
- }
- }
-
- $one_line_check_p;
-}
-
-
# XXX fml 4.0: EUCCompare($buf, $pat)
# XXX where $pat should be $& (matched pattern)
sub euc_compare
@@ -133,7 +78,7 @@ sub euc_compare
# always true if given buffer is not EUC.
if ($a !~ /($re_euc_c|$re_euc_kana|$re_euc_0212)/) {
- &Log("EUCCompare: do nothing for non EUC strings") if $debug;
+ &Log("EUCCompare: do nothing for non EUC strings");# if $debug;
return 1;
}