You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2005/12/05 05:17:57 UTC

svn commit: r353982 - /spamassassin/rules/trunk/sandbox/felicity/sandbox-felicity.pm

Author: felicity
Date: Sun Dec  4 20:17:52 2005
New Revision: 353982

URL: http://svn.apache.org/viewcvs?rev=353982&view=rev
Log:
to put code in a plugin, one ought to put the plugin in svn ...

Added:
    spamassassin/rules/trunk/sandbox/felicity/sandbox-felicity.pm

Added: spamassassin/rules/trunk/sandbox/felicity/sandbox-felicity.pm
URL: http://svn.apache.org/viewcvs/spamassassin/rules/trunk/sandbox/felicity/sandbox-felicity.pm?rev=353982&view=auto
==============================================================================
--- spamassassin/rules/trunk/sandbox/felicity/sandbox-felicity.pm (added)
+++ spamassassin/rules/trunk/sandbox/felicity/sandbox-felicity.pm Sun Dec  4 20:17:52 2005
@@ -0,0 +1,95 @@
+# <@LICENSE>
+# Copyright 2004 Apache Software Foundation
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# </...@LICENSE>
+
+package Mail::SpamAssassin::Plugin::Sandbox::felicity;
+
+use Mail::SpamAssassin::Plugin;
+use strict;
+use warnings;
+use bytes;
+
+use vars qw(@ISA);
+@ISA = qw(Mail::SpamAssassin::Plugin);
+
+# constructor: register the eval rule
+sub new {
+  my $class = shift;
+  my $mailsaobject = shift;
+
+  # some boilerplate...
+  $class = ref($class) || $class;
+  my $self = $class->SUPER::new($mailsaobject);
+  bless ($self, $class);
+
+  # the important bit!
+  $self->register_eval_rule("check_iframe_src");
+  $self->register_eval_rule("check_from_format");
+  $self->register_eval_rule("subject_length");
+  $self->register_eval_rule("check_html_uri_only");
+
+  return $self;
+}
+
+sub check_iframe_src {
+  my ($self) = @_;
+
+  while (my($k,$v) = each %{$self->{html}->{uri_detail}}) {
+    return 1 if $v->{types}->{iframe};
+  }
+
+  return 0;
+}
+
+sub check_from_format {
+  my ($self) = @_;
+
+  my $name = $self->get('From:name') || return;
+  return if ($name !~ m/^[A-Z][a-z]+\.[A-Z][a-z]+\@/);
+
+  my $addr = $self->get('From:addr') || return;
+  return if ($addr !~ m/^[A-Z][a-z]+\.[A-Z][a-z]+\@/);
+
+  return if ($name eq $addr);
+  return 1;
+}
+
+sub subject_length {
+  my ($self, $min, $max) = @_;
+  my $len = length($self->get('Subject'));
+  return($len < $max && $len >= $min);
+}
+
+sub check_html_uri_only {
+  my ($self) = @_;
+
+  # Find out if there are any  multipart/alternative parts in the message
+  my @ma = $self->{msg}->find_parts(qr@^multipart/alternative\b@i);
+
+  # If there are no multipart/alternative sections, skip this test.
+  return if (!@ma);
+
+  # At this point, we're not actually checking the alternates, just the entire
+  # message.
+  my $return = 0;
+  while (my($k,$v) = each %{$self->{html}->{uri_detail}}) {
+    $return = 1; # make sure there's at least 1 URI
+    return 0 if ($v->{types}->{parsed});
+  }
+
+  return $return;
+}
+
+1;