rspamd and roundcube's markasjunk2 plugin

509 views
Skip to first unread message

David Mehler

unread,
Apr 9, 2018, 8:52:30 PM4/9/18
to rspamd
Hello,

Any users of rspamd and roundcube with the markasjunk2 plugin? If so,
do you have a configuration where the markasjunk2 plugin and rspamd
are talking to each other so users just have to select spam or not
spam on a message to train rspamd?

Thanks.
Dave.

Владислав Ясюкевич

unread,
Apr 10, 2018, 1:36:53 AM4/10/18
to rspamd
Hello. It's easy to do.

Server side roundcube:
In /var/www/roundcube/plugins/markasjunk2/config.inc.php, add:
$config ['markasjunk2_spam_cmd'] = 'sudo /usr/local/bin/learn_spam %f %u';
$config
['markasjunk2_ham_cmd'] = 'sudo /usr/local/bin/learn_ham %f %u';

Where:
%u  -->  info@example.com
%l  -->  info
%d  -->  example.com
%i  -->  info@example.com
%f  -->  /var/www/roundcubemail-1.0.5markasjunk/temp/rcmSALearny62d3F

Script /usr/local/bin/learn_spam
#!/bin/bash -eu

declare
-r FILE="$1"
declare
-r MAIL="$2"

declare
-r SERVER='*****'
declare
-r DIR='/home/learn/mail'
declare
-r MSGHASH="$(cat $FILE | md5sum | awk '{ print $1 }')"


ssh learn@$
{SERVER} "rm -f ${DIR}/HAM/${MAIL}.${MSGHASH}"
rsync
-a --chmod=u+rw,g+rw,o+rw $FILE learn@${SERVER}:${DIR}/SPAM/${MAIL}.${MSGHASH}

Script /usr/local/bin/learn_ham
#!/bin/bash -eu

declare
-r FILE="$1"
declare
-r MAIL="$2"

declare
-r SERVER='*****'
declare
-r DIR='/home/learn/mail'
declare
-r MSGHASH="$(cat $FILE | md5sum | awk '{ print $1 }')"


ssh learn@$
{SERVER} "rm -f ${DIR}/SPAM/${MAIL}.${MSGHASH}"
rsync
-a --chmod=u+rw,g+rw,o+rw $FILE learn@${SERVER}:${DIR}/HAM/${MAIL}.${MSGHASH}

Server side rspamd:
In /etc/cron.d/learn
*/5 * * * *     root    /usr/local/bin/learn > /dev/null

Script /usr/local/bin/learn
#!/bin/bash -eu

declare
-r HAMDIR='/home/learn/mail/HAM'
declare
-r SPAMDIR='/home/learn/mail/SPAM'


[[ -d "$HAMDIR" ]] || {
    mkdir
-p "$HAMDIR"
    chown
-R learn: "$HAMDIR"
}

[[ -d "$SPAMDIR" ]] || {
    mkdir
-p "$SPAMDIR"
    chown
-R learn: "$SPAMDIR"
}


for HAMFILE in $(find "$HAMDIR" -type f); do
    HAMFILE_X
="${HAMFILE%.*}"
    MAILNAME
="${HAMFILE_X##*/}"
   
[[ -n "${MAILNAME}" ]] && {
        rspamc
-t 60 learn_ham --classifier=bayes_local-r "$MAILNAME" "$HAMFILE"
    }
    rm
-f "$HAMFILE"
done


for SPAMFILE in $(find "$SPAMDIR" -type f); do
    SPAMFILE_X
="${SPAMFILE%.*}"
    MAILNAME
="${SPAMFILE_X##*/}"
   
[[ -n "${MAILNAME}" ]] && {
        rspamc
-t 60 learn_spam --classifier=bayes_local -r "$MAILNAME" "$SPAMFILE"
   
}
    rm
-f "$SPAMFILE"
done

For this template, you can make a different learning logic.


вторник, 10 апреля 2018 г., 5:52:30 UTC+5 пользователь David Mehler написал:

Dedé Alves

unread,
Apr 10, 2018, 7:26:23 PM4/10/18
to rspamd
I'm using it.

Check this page:

There are some scripts to use with dovecot.
If you use IMAP, these scripts will be auto executed.

Regads,

Reply all
Reply to author
Forward
0 new messages