On Tuesday 12 March 2002 08:21 am, Matt Sergeant wrote:
> On Tue, 12 Mar 2002, Charlie Watts wrote:

> > Does anybody get legit mail with no body?

> Yep, and I send a lot too (just mailing each other files in the office
> would be one example, and my mail hits the smtp server due to the way it's
> setup here (I refuse to use Outlook)).

I wrote a few eval rules to deal with stuff like that:

-----------

full     ONLY_ATTACHMENTS       eval:check_for_only_attachments()
describe ONLY_ATTACHMENTS       Only attachmnets, no text

full      GOOD_ATTACHMENTS      eval:check_for_non_spamish_attachments()
describe  GOOD_ATTACHMENTS      Compensate for ONLY_ATTACHMENTS

score    ONLY_ATTACHMENTS       4.0
score    GOOD_ATTACHMENTS      -4.0

------------

sub check_for_only_attachments {
  my ($self, $body) = @_;

  my $ctype = $self->{msg}->get_header ('Content-Type');
  $ctype ||=  '';

  my $multipart_boundary;
  if ($ctype =~ /boundary=["']?(.*?)["']?(;|$)/) {
    $multipart_boundary = "--" . quotemeta($1);
  }
  else {
    # Not a multipart, no attachments
    return 0;
  }

  my $i = 0;

  while($i < @{$body}) {
    last if $body->[$i++] =~ /^$multipart_boundary/;
  }

  while($i < @{$body}) {
    last if $body->[$i++] =~ /^$/;
  }

  # OK, now we're in the body of the first MIME part, where the
  # non-attachment message goes.  If we find a non-blank line before
  # the next MIME part, then there's something besides an attachment
  # in this mail

  for (; $i < @$body; $i++) {
    return 1 if ($body->[$i] =~ /^$multipart_boundary/);
    return 0 if ($body->[$i] !~ /^$/);
  }

  # Should we ever even get here?
  return 0;
}


sub check_for_non_spamish_attachments {
  my ($self, $body) = @_;

  my $ctype = $self->{msg}->get_header ('Content-Type');
  $ctype ||=  '';

  if ($ctype !~ /boundary=".*"/) {
    # Not multipart, so no attachments
    return 0;
  }

  my @ctypes = grep(/^Content-Type:/i, @$body);

  # Are there any content types other than "text/*" or
  # "application/octet-stream"?
  @ctypes = grep(!/^Content-Type: (text\/|application\/octet-stream)/,
                 @ctypes);

  return (@ctypes > 0);
}

---------

-- 
Visit http://dmoz.org, the world's   | Give a man a match, and he'll be warm
largest human edited web directory.  | for a minute, but set him on fire, and
                                     | he'll be warm for the rest of his life.
[EMAIL PROTECTED]  ICQ: 132152059 |

_______________________________________________
Spamassassin-talk mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/spamassassin-talk

Reply via email to