如何在SpamAssassin中编辑坏词过滤器?


10

如何在SpamAssassin中添加几个自定义的“坏”字,以便将包含该字的电子邮件标记为垃圾邮件?

更新

关键之一是编辑文件/ etc / mail / spamassassin,并按如下所述添加死字过滤器

http://linuxguruz.wordpress.com/2008/09/16/spamassassin-example/

但是,在这种情况下,邮件仅被标记为垃圾邮件,它仍然进入我的收件箱...

我该怎么办才能完全不接收包含不良单词的电子邮件?

更新2

如果电子邮件被归类为垃圾邮件,我的SpamAssassin确实会更改主题,并且现在可以正常工作。文件/etc/mail/spamassassin/local.cf如下所示:

ok_locales all
skip_rbl_checks 0

required_score 5
report_safe 1
rewrite_header Subject ***SPAM***

use_pyzor 1
use_razor2 1

use_auto_whitelist 0


use_bayes 1
use_bayes_rules 1
bayes_auto_learn 1
blacklist_from *@kupiizaradi.cjb.net
blacklist_from *@hallmark.com
whitelist_from *@*hrgworldwide.com
whitelist_from *@bluehost.com
#blacklist_from *@greekajob.com

header CONTAINS_VIG Subject =~ /viagra, Cialix Pills, sex, xxx, penis, pussy, greekajob, greekajobs, pera
zdera/
body CONTAINS_PEN /viagra, sex, xxx, penis, puss, greekajob, greekajobs, perazdera/
score CONTAINS_VIG 1.5
score CONTAINS_PEN 1.5
describe CONTAINS_VIG Bad Word
describe CONTAINS_PEN Bad Word

所以,现在我需要帮助如何:

  1. 将这些电子邮件移至“垃圾邮件”文件夹
  2. 为服务器上添加的每个新邮件帐户自动创建垃圾邮件文件夹

文件/ etc / mail / mailfilter看起来像这样:

SHELL="/bin/sh"
import EXT
import HOST
VHOME=`pwd`
TIMESTAMP=`date "+%b %d %H:%M:%S"`
#VERBOSE=9

logfile "/var/log/maildrop/maildrop.log"
log "$TIMESTAMP - BEGIN maildrop processing for $EXT@$HOST ==="

`test -r $VHOME/.mailfilter`
if($RETURNCODE == 0)
{
    log "including $VHOME/.mailfilter"
    exception {
        include $VHOME/.mailfilter
    }
}


# does maildirsize exist?
`test -e $VHOME/Maildir/maildirsize`

# if maildirsize doesn't exist
if($RETURNCODE == 1)
{ 

    # does vuserinfo exist?
    `test -x /home/vpopmail/bin/vuserinfo` 

    # if vuserinfo exists
    if($RETURNCODE == 0)
    { 
        # does the user exist?
        `/home/vpopmail/bin/vuserinfo $EXT@$HOST`
        if($RETURNCODE == 0)
        {

            # find out what the user's quota is
            $QUOTA=`/home/vpopmail/bin/vuserinfo -Q $EXT@$HOST`
            log "QUOTA = $QUOTA"

            # does maildirmake exists?
            `test -x /usr/bin/maildirmake`

            # if maildirmake exists
            if($RETURNCODE == 0)
            {

                # does Maildir exist?
                `test -d $VHOME/Maildir`

                # if Maildir exists
                if($RETURNCODE == 0)
                {

                    # make the maildirsize file
                    `/usr/bin/maildirmake -q $QUOTA $VHOME/Maildir`
                    `test -s "$VHOME/Maildir/maildirsize"`

                    # if maildirsize exists
                    if($RETURNCODE == 0)
                    {
                        `/bin/chown vpopmail:vchkpw $VHOME/Maildir/maildirsize`
                        `/bin/chmod 640 $VHOME/Maildir/maildirsize`

                    # else 
                    }
                    else
                    {
                        log "Problem making 'maildirsize' for $VHOME"
                    }

                    # end if maildirsize exists
                }
                else
                {
                    log "Maildir does not exist for $VHOME"
                }

                # end if Maildir exists
            }
            else
            {
                log "maildirmake does not exist"

            # end if maildirmake exists
            }
        }
        else
        {
            log "user $EXT@HOST does not exist"

        # end if user exists
        }
    }
    else
    {
        log "vuserinfo does not exist"

    # end if vuserinfo exists
    }
}
# does maildirsize exist?
`test -e $VHOME/Maildir/maildirsize`
if($RETURNCODE == 0)
{
    MAILDIRQUOTA=`/usr/bin/head -n1 $VHOME/Maildir/maildirsize`
    log "MAILDIRQUOTA = $MAILDIRQUOTA"
}


#--------------------------------------------------------
# Filter spam - scores >= SPAMLIMIT is not delivered
#
# If you DO NOT want to send mail that is over the spam limit
# to spamassassin autolearn, comment: 'cc "|sa-learn -spam"'
#--------------------------------------------------------

##########################################################################
# Below is where I found some of the main problem, i.e apparently the
# regex logic changed, do a diff against this one and the old one,
# the old one was delimited with the '!' (bang) and grouped as a whole.
# it failed the match always.  By using standard regex grouping, I was able
# to get the filter working. By grouping the score accordingly, it
# breaks it into a number and precision, e.g. MATCH1 and MATCH2
##########################################################################

if(/^X-Spam-Status: Yes, score=([0-9]+)\.([0-9]+)/:h)
{
    if($MATCH1 >= 5)
    {
        cc "|sa-learn --spam"
    }

    # if the user doesnt' have a Spam folder
    `test -d $VHOME/Maildir/.Spam`
    if($RETURNCODE == 1)
    {
        `test -x /usr/bin/maildirmake`
        if($RETURNCODE == 0)
        {
            `/usr/bin/maildirmake -f Spam $VHOME/Maildir`
            `test -x /usr/bin/subscribeIMAP.sh`
            if($RETURNCODE == 0)
            {
                `/usr/bin/subscribeIMAP.sh Spam $VHOME`
            }
        }
    }

    # make sure the deliverquota binary exists and is executable
    `test -x /usr/bin/deliverquota`
    if($RETURNCODE == 1)
    {
        exception {
            to "$VHOME/Maildir/.Spam"
        }
    }
    else
    {
        cc "|/usr/bin/deliverquota -w 90 $VHOME/Maildir/.Spam"
        if($RETURNCODE == 0)
        {
            log "=== END ===  $EXT@$HOST  success (quota)"
            EXITCODE=0
            exit
        }
        else
        {
            if($RETURNCODE == 77)
            {
                log "$TIMESTAMP - $EXT@$HOST  bounced (quota)"
                to "|/var/qmail/bin/bouncesaying '$EXT@$HOST is over quota'"
            }
            else
            {
                log \
                 "$TIMESTAMP - $EXT@$HOST failure (unknown deliverquota error)"
                to "$VHOME/Maildir/.Spam"
            }
        }
    }
}

##########################################################################
# Same as above
##########################################################################
if(/^X-Spam-Status: No, score=([\-]*[0-9]+)\.([0-9]+) /:h)
{
    log "   message is clean ($MATCH1.$MATCH2)"
}


#--------------------------------------------------------
# Include any user rules 
#--------------------------------------------------------

`test -r $VHOME/Maildir/.mailfilter`
if($RETURNCODE == 0)
{
    log "   including $VHOME/Maildir/.mailfilter"
    exception {
        include $VHOME/Maildir/.mailfilter
    }
}

`test -x /usr/bin/deliverquota`
if ($RETURNCODE == 1)
{
    log "$TIMESTAMP - $EXT@$HOST WARNING: no deliverquota!"
    log "=== END ===  $EXT@$HOST success"
    exception {
        to "$VHOME/Maildir"
    }
}
else
{
    exception {
        log "RETCODE = $RETURNCODE   delivering to $VHOME/Maildir"
        xfilter "/usr/bin/deliverquota -w 90 $VHOME/Maildir"
    }
    #--------------------------------------------------------
    # check to make sure the message was delivered
    # returncode 77 means that out maildir was overquota - bounce mail
    #--------------------------------------------------------
    if($RETURNCODE == 77)
    {
        log "$TIMESTAMP - BOUNCED: bouncesaying '$EXT@$HOST is over quota'"
        log "$TIMESTAMP - $EXT@$HOST  bounced"
        to "|/var/qmail/bin/bouncesaying '$EXT@$HOST is over quota'"
    }
    else
    {
        log "=== END ===  $EXT@$HOST  success (quota)"
        EXITCODE=0
        exit
    }
}

log "$TIMESTAMP - $EXT@$HOST - WARNING: This message should never be printed!"
[root@um-1027 /etc/mail]#

.qmail-default看起来像这样:

|/var/qmail/bin/preline /usr/bin/maildrop /etc/mail/mailfilter

您能帮我解决此问题并将垃圾邮件移到垃圾邮件文件夹吗?


/viagra, sex, xxx, penis, puss, greekajob, greekajobs, perazdera/逻辑或不是逗号。是管子 =“ |”。逗号通常被当作字面逗号和空格。您正在体内搜寻完全像这样的一行:“伟哥,性别,xxx,阴茎,少女,greekajob,greekajobs,perazdera”。试试/(viagra|sex|xxx|penis|puss.|greekajob|greekajobs|perazdera)/i吧?
bshea

Answers:


1

在SpamAssassin中,您可以创建规则,在触发垃圾邮件分类标题后将N分数附加到垃圾邮件分类标题中。

由您自己设置阈值,确定何时将其归类为垃圾邮件,以及如何处理(删除,移至文件夹,转发?等)。

如果要将可疑垃圾邮件移动到特定文件夹,我怀疑您将其挂接到POP3 / IMAP服务器(例如:dovecot)或POP3 / IMAP客户端用法(例如:fetchmail + procmail)。

使用筛子脚本的Dovecot示例:

if header :contains "X-Spam-Level" "**********" { discard; stop; }

参考:https : //wiki2.dovecot.org/Pigeonhole/Sieve/Examples#Direct_filtering_using_message_header

Procmail规则将垃圾邮件过滤到SPAM文件夹(〜/ .procmailrc)

:0: * ^X-Spam-Status: Yes SPAM

参考:https : //www.cs.rutgers.edu/~watrous/procmail-spam.html

我希望这对您有所帮助。


0

使用SpamAssassin,您可以重写检测为垃圾邮件的邮件,但不能删除它。Postfix或cpanel使用SpamAssassin来检测垃圾邮件,而不是对其进行处理。但是,您可以在cpanel中创建规则(例如),以删除由SpamAssassin重写标题的电子邮件。我认为这是一个坏主意,您可能会漏掉误报。只需将其放在具有基本规则的特定文件夹中即可。


您是对的,因为我确实重写了主题(和正文),并将正确的电子邮件标记为垃圾邮件。您能否指出我如何管理自动将这些邮件移到垃圾邮件文件夹中(针对每个电子邮件帐户)?我没有Cpanel,服务器正在维护中。
user48058 2013年

由于我对此问题进行了一些更新,因此我对问题做了一些修改……
user48058 2013年

好像电子邮件不会“到达” / etc / mail / mailfilter脚本(如果它是垃圾邮件)...看起来有些东西在到达之前就将其删除。如果邮件不是垃圾邮件,则一切正常……
user48058 2013年

如果您使用doveco作为pop / imap服务器,则您可以使用筛子将带有垃圾邮件标签的邮件移动到单独的垃圾邮件文件夹,从而绕过收件箱
Tutul,2016年

0

移动邮件与Spamassassin无关,并且完全取决于您的LDA或MUA(本地传递代理或邮件用户代理)。您的邮件是否已传递到POP3帐户(IMAP帐户)?您的服务器使用的是Dovecot还是Cyrus或其他产品?

问题和变量太多,而这不是这些问题的地方。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.