使用 sieve 腳本的 Dovecot 範例:

使用 sieve 腳本的 Dovecot 範例:

如何將多個自訂「壞」單字新增至 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

您能幫我解決這個問題並將垃圾郵件移入垃圾郵件資料夾嗎?

答案1

在 SpamAssassin 中,您可以建立規則,在觸發後將 N 分數附加到垃圾郵件分類標頭。

您可以自行設定何時將其分類為垃圾郵件的閾值以及如何處理它(刪除、移至資料夾、轉送?等)。

如果您想將可疑的垃圾郵件移至特定資料夾,我懷疑您將其掛接到 POP3/IMAP 伺服器(例如:dovecot)或 POP3/IMAP 用戶端使用(例如:fetchmail + procmail)。

使用 sieve 腳本的 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

我希望這對您有所幫助。

答案2

使用 SpamAssassin,您只能重寫偵測為垃圾郵件的郵件,但無法刪除它。 Postfix 或 cpanel 使用 SpamAssassin 來偵測垃圾郵件而不是處理它。但是您可以在 cpanel 中建立規則(例如),用於刪除由 SpamAssassin 重寫標題的電子郵件。在我看來,這是一個壞主意,你可能會錯過誤報。只需將其放在具有基本規則的特定資料夾中即可。

答案3

行動郵件與 Spamassassin 無關,完全取決於您的 LDA 或 MUA(本地投遞代理商或郵件用戶代理)。您的郵件是否有傳送到 POP3 帳號、IMAP 帳號?您的伺服器使用 Dovecot 或 Cyrus 還是其他?

太多的問題和變量,而這裡不是討論這些問題的地方。

相關內容