SMTP time SpamAssassin checking


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » Email » Spam

SMTP time SpamAssassin checkingLast Modified: Apr 2, 2011, 4:45 pm
This guide is obsolete. If you want smtp-time checking, use EasySpamFigher in combination with SpamBlocker 4.x:
https://help.directadmin.com/item.php?id=576



This guide is considered to be in ALPHA testing.  High likelihood of issues.  Use at your own risk.

This assumes that you've already enabled SpamAssassin on your system.   With the smtp-time scanning, step 3 of the SA install guide is not needed: you can leave the spamcheck_director commented out.

/etc/exim.conf changes


1) Find this code

daemon_smtp_ports = 25 : 587

right after it, add:

spamd_address = 127.0.0.1 783


2) Find this code

# ACL that is used after the RCPT command
check_recipient:

and right after it, add:

    # Set variable for user to be used by spamassassin
    # This will create a colon separated list for each recipient, padding the new value to the same variable.
    warn   set acl_m3 = ${lookup{$domain}lsearch{/etc/virtual/domainowners}{$value}}:$acl_m3


3) Find this code:

# ACL that is used after the DATA command
check_message:
    accept

and replace it with this:

# ACL that is used after the DATA command
check_message:

          #allow large files though.
          accept  condition = ${if >={$message_size}{500k}{yes}{no}}

          # Set variable for user to be used by spamassassin
          warn    set acl_m1 = ${perl{get_spam_user}}
                    set acl_m2 = ${perl{get_spam_threshold}}

          warn    spam = $acl_m1:true
                    add_header = X-Spam-Score: $spam_score ($spam_bar)
                    add_header = X-Spam-Report: $spam_report
                    condition = ${if >{$spam_score_int}{0}{true}{false}}
          warn    message = X-Spam-Status: Yes, score=$spam_score\nX-Spam-Flag: YES\nSubject: *****SPAM***** $h_Subject:
                    spam = $acl_m1:true
                    condition = ${if >{$spam_score_int}{$acl_m2}{true}{false}}
          deny    message = This message has be flagged as spam ($spam_score_int/$acl_m2).
                    spam = $acl_m1:true
                    condition = ${if >{$spam_score_int}{70}{true}{false}}

          accept



/etc/exim.pl changes



Add this code to the bottom of the /etc/exim.pl:

sub get_spam_user
{
          #this code can be updated to check for user_prefs files to see which should be used
          my $user_list = Exim::expand_string('$acl_m3');
          @users = split(/:/, $user_list);

          my $last="";
          foreach $user (@users)
          {
                    if ($user ne "") { $last = $user; }
                    #log_str("user found: $user from $user_list\n");
          }

          return $last;
}

sub is_integer
{
          return $_[0] =~ /^\d+$/
}
sub is_float
{
          return $_[0] =~ /^\d+\.?\d*$/
}

sub get_spam_threshold
{
          my $user = Exim::expand_string('$acl_m1');
          #edit this User's user_prefs and find the value:
          #required_score 3.0
          #required_hits 3.0
          #if we can't find it, default to 5.

          my $threshold = "50";

          if (open (USER_PREFS, "/home/$user/.spamassassin/user_prefs"))
          {
                    while ($line = <USER_PREFS>)
                    {
                              if ($line =~ m/^required_score/ || m/^required_hits/)
                              {
                                        #get rid of any middle spaces or tabs, replace with 1 space
                                        $line =~ s/\s+/ /;

                                        #and grab the threshold
                                        my $dthresh = $threshold / 10;
                                        ($dontcare,$dthresh) = split(/ /, $line);


                                        if (is_integer($dthresh) || is_float($dthresh))
                                        {
                                                  $threshold = $dthresh * 10;
                                        }

                                        break;
                              }

                    }
                    close(USER_PREFS);
          }

          return $threshold;
}

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST