Outils pour utilisateurs

Outils du site


ateliers:serveurmail:rspamd

Rspamd

rspamd est un système de filtrage de spam open-source.

Ressources

Site officiel de rspamd Setup de dashie pour le script d'antispam

Installation

Ajout repository non-officiel :

Le repository officiel de debian n'est plus maintenu, il fautd onc utiliser la version upstream.

Le fichier /etc/apt/sources.lists.d/rspamd.list a été ajouté pour gérer le logiciel. Il faut ensuite ajouter la clef du repository pour pouvoir installer rspamd :

  $ wget -O- https://rspamd.com/apt-stable/gpg.key | sudo apt-key add -
/etc/apt/sources.list.d/rspamd.list
deb http://rspamd.com/apt-stable/ stretch main 

Upgrade : apt-get upgrade

Installation : apt-get install rspamd

Administration

FIXME: A écrire

/usr/local/bin/rspamd.py
#!/usr/bin/env python3
# Python 3.5+ required
# Script by https://sitedethib.com/
# Source adapted to 3.5 from dashie version https://dev.sigpipe.me/dashie/setup_mail/src/master/rspamd.py
 
import sys
import smtplib
import subprocess
import syslog
import time
 
t_start = time.time()
 
SMTP_HOST   = '127.0.0.1'
SMTP_PORT   = 10025
RSPAMC_BIN  = '/usr/bin/rspamc'
RSPAMC_ADDR = '127.0.0.1:11333'
 
mail_from     = sys.argv[1]
rcpt_to       = sys.argv[2]
 
def size(size, decimal_places):
    for unit in ['','KB','MB','GB','TB']:
        if size < 1024.0:
            break
        size /= 1024.0
    return "{size:.{decimal_places}f}{unit}".format(size=size, decimal_places=decimal_places, unit=unit)
 
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
 
# Pipe stdin to rspamc, and get the processed mail back
#XXX: this means the processed mail stays in RAM, which may not be what we want?
completed_process = subprocess.run([RSPAMC_BIN, '--mime', '-h', RSPAMC_ADDR, '-P', 'saucisse'],
                                   stdin=sys.stdin, stdout=subprocess.PIPE,
                                   check=True)
 
# Remove 'Delivered-To' header from rspamc's output
mail_contents = completed_process.stdout
mail_contents = b'\n'.join(l for l in mail_contents.split(b'\n') if not l.startswith(b'Delivered-To'))
 
with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as smtp:
    smtp.sendmail(mail_from, rcpt_to, mail_contents)
 
t_end = time.time()
 
syslog.syslog("rspamd-bridge processed {} mail in {}".format(size(len(mail_contents), 1), t_end - t_start))
ateliers/serveurmail/rspamd.txt · Dernière modification: 2018/01/28 14:01 par okhin