체 스크립트를 사용한 Dovecot 예:

체 스크립트를 사용한 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)에 연결했을 것으로 의심됩니다.

체 스크립트를 사용한 Dovecot 예:

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

참조:https://wiki2.dovecot.org/Pigeonhole/Sieve/Examples#Direct_filtering_using_message_header

스팸을 SPAM 폴더(~/.procmailrc)로 필터링하는 Procmail 규칙

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

참조:https://www.cs.rutgers.edu/~watrous/procmail-spam.html

이것이 도움이 되기를 바랍니다.

답변2

SpamAssassin을 사용하면 스팸으로 감지된 메일을 다시 작성할 수 있지만 삭제할 수는 없습니다. Postfix 또는 cpanel은 스팸을 처리하기 위해 스팸을 감지하기 위해 SpamAssassin을 사용합니다. 그러나 SpamAssassin이 다시 작성한 제목이 포함된 이메일 삭제에 대한 규칙을 cpanel에서 생성할 수 있습니다(예를 들어). 제 생각에는 그것은 나쁜 생각입니다. 거짓 긍정을 놓칠 수 있습니다. 기본 규칙에 따라 특정 폴더에 넣으면 됩니다.

답변3

메시지 이동은 Spamassassin과 아무 관련이 없으며 LDA 또는 MUA(로컬 배달 에이전트 또는 메일 사용자 에이전트)에 전적으로 의존합니다. 메일이 POP3 계정, IMAP 계정으로 전달되나요? 귀하의 서버가 Dovecot이나 Cyrus 또는 다른 것을 사용하고 있습니까?

질문과 변수가 너무 많아서 이곳은 그러한 질문을 위한 장소가 아닙니다.

관련 정보