Page 2 of 2

Re: HOW TO: RSPAMD integration

Posted: Fri Feb 07, 2020 4:48 pm
by compiz
dreiggy wrote:
Thu Feb 06, 2020 8:31 pm
compiz wrote:
Wed Nov 13, 2019 5:58 pm
Does this work for all domains in the server or just for the domain name of the server?
Thank you very much for the guide :)
Yes, it works globally for all domains.
Thanks! It took me a while to train it to block all spam but now it blocks all incoming emails

Re: HOW TO: RSPAMD integration

Posted: Tue Apr 14, 2020 10:18 am
by plutocrat
Thought I'd give this a go on a non-critical server. I'm on Ubuntu 18, rather than Centos, but the idea is the same. Followed your config, making adjustments for platform, and rspamd, redis and exim are all running happily. The only trouble is that rspamd doesn't seem to be chewing on any emails. I can send and receive as normal, but the web stats interface of rspamd shows zero mails passing through. I added a test spam to the web interface, and that registered, but its the only mail I can see.

Nothing in particular in the exim or rspamd logs that gives me a clue. Has anyone else been through this on Ubuntu?

Spam assassin is happily disabled. I can roll back the config pretty easily, but I'm going to leave it going for a day to see if anything suggests itself.

Re: HOW TO: RSPAMD integration

Posted: Wed Apr 15, 2020 8:49 am
by plutocrat
Replaced original email, as it might have been confusing. OK, so on Ubuntu, there is one key change to the original poster's config. In the check_rcpt section, you set a variable acl_m1 depending on whether a file exists for that domain:

Code: Select all

.ifdef RSPAMD
  warn    set acl_m1    = no
  warn    condition     = ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
          set acl_m1    = yes
.endif
Its crucial to note that for Ubuntu, the path is /etc/exim4 rather than /etc/exim which the Centos example used.!

Once you have that set, the conditions for scanning the mail work fine, specifically this one which has now been correctly set:
condition = ${if eq{$acl_m1}{yes}{yes}{no}}

I've been tweaking the exim config. Currently it looks like this:

Code: Select all

.ifdef RSPAMD
  accept hosts = +relay_from_hosts
  accept condition = ${if eq{$interface_port}{587}}
  accept authenticated = *

  # If message size is less than 500k and the domain has antispam enabled, scan the message with rspamd
  # This will set variables as follows: $spam_action, $spam_score, $spam_score_int (spam score x10), $spam_report, $spam_bar
  # So we add these as headers, first removing any existing ones
  warn  condition      = ${if < {$message_size}{500K}}
        condition      = ${if eq{$acl_m1}{yes}{yes}{no}}
        spam = nobody:true
        remove_header = x-spam-bar : x-spam-score : x-spam-report : x-spam-status
        add_header     = X-Spam-Score: $spam_score_int
        add_header     = X-Spam-Report: $spam_report
	add_header     = X-Spam-Action: $spam_action
        set acl_m2     = $spam_score_int

  # add x-spam-bar header if score is positive
  warn  condition = ${if >{$spam_score_int}{0}}
        add_header = X-Spam-Bar: $spam_bar

  # use greylisting if action is soft reject
  defer message    = Please try again later
        condition  = ${if eq{$spam_action}{soft reject}}

  # Hard reject if spam action is reject 
  deny  message    = Message discarded as high-probability spam
        condition  = ${if eq{$spam_action}{reject}}

  # Tag mesage as spam-report header when spam action is "add header" 
    warn
    condition  = ${if eq{$spam_action}{add header}}
    add_header = X-Spam-Status: Yes

  # add x-spam-status header if message action is "rewrite subject"
  warn
    condition  = ${if eq{$spam_action}{rewrite subject}}
    add_header = X-Spam-Status: Yes
.endif

Re: HOW TO: RSPAMD integration

Posted: Tue Apr 21, 2020 11:08 pm
by criptop
Hi,

question should be changed condition = ${if eq{$acl_m1}{yes}{yes}{no}} from ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}} ??

Regards

Ruben
plutocrat wrote:
Wed Apr 15, 2020 8:49 am
Replaced original email, as it might have been confusing. OK, so on Ubuntu, there is one key change to the original poster's config. In the check_rcpt section, you set a variable acl_m1 depending on whether a file exists for that domain:

Code: Select all

.ifdef RSPAMD
  warn    set acl_m1    = no
  warn    condition     = ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
          set acl_m1    = yes
.endif
Its crucial to note that for Ubuntu, the path is /etc/exim4 rather than /etc/exim which the Centos example used.!

Once you have that set, the conditions for scanning the mail work fine, specifically this one which has now been correctly set:
condition = ${if eq{$acl_m1}{yes}{yes}{no}}

I've been tweaking the exim config. Currently it looks like this:

Code: Select all

.ifdef RSPAMD
  accept hosts = +relay_from_hosts
  accept condition = ${if eq{$interface_port}{587}}
  accept authenticated = *

  # If message size is less than 500k and the domain has antispam enabled, scan the message with rspamd
  # This will set variables as follows: $spam_action, $spam_score, $spam_score_int (spam score x10), $spam_report, $spam_bar
  # So we add these as headers, first removing any existing ones
  warn  condition      = ${if < {$message_size}{500K}}
        condition      = ${if eq{$acl_m1}{yes}{yes}{no}}
        spam = nobody:true
        remove_header = x-spam-bar : x-spam-score : x-spam-report : x-spam-status
        add_header     = X-Spam-Score: $spam_score_int
        add_header     = X-Spam-Report: $spam_report
	add_header     = X-Spam-Action: $spam_action
        set acl_m2     = $spam_score_int

  # add x-spam-bar header if score is positive
  warn  condition = ${if >{$spam_score_int}{0}}
        add_header = X-Spam-Bar: $spam_bar

  # use greylisting if action is soft reject
  defer message    = Please try again later
        condition  = ${if eq{$spam_action}{soft reject}}

  # Hard reject if spam action is reject 
  deny  message    = Message discarded as high-probability spam
        condition  = ${if eq{$spam_action}{reject}}

  # Tag mesage as spam-report header when spam action is "add header" 
    warn
    condition  = ${if eq{$spam_action}{add header}}
    add_header = X-Spam-Status: Yes

  # add x-spam-status header if message action is "rewrite subject"
  warn
    condition  = ${if eq{$spam_action}{rewrite subject}}
    add_header = X-Spam-Status: Yes
.endif

Re: HOW TO: RSPAMD integration

Posted: Wed Apr 22, 2020 3:17 am
by plutocrat
criptop wrote:
Tue Apr 21, 2020 11:08 pm
question should be changed condition = ${if eq{$acl_m1}{yes}{yes}{no}} from ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
I don't understand what you're asking.

The config I posted works. In the first section it uses this condition to look for a file. If the file exists, it sets $acl_m1 to "yes":
${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}

The second condition checks to see if $acl_m1="yes". If it does, it scans the mail with rspamd
${if eq{$acl_m1}{yes}{yes}{no}}

This was just the way it was set up in the original exim config file for vesta. If you understand what you're doing, then there's no reason (as far as I can see), why you can't remove the first section, and just replace
${if eq{$acl_m1}{yes}{yes}{no}}
with
${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
in the second section.

i.e. there doesn't seem to be a need to set the intermediate variable $acl_m1. Is that what you were asking?

Re: HOW TO: RSPAMD integration

Posted: Wed May 27, 2020 8:53 am
by compiz
I think that in my case something doesn't work as it should!
I am receiving every day the same and the same 4-5 emails from various addresses.
The content and the format of the emails is exactly the same.
I don't think that the rspamd learns from me marking emails as spam and moving them to the spam folder nor from when I train it from the GUI.
It will say for example the item is already learned but here it is, 10 minutes later in my inbox. The same item as 1000 before it!