Getmail: Spam subject is not rewritten with rspamd

pop3connector
mail2

(Mark Verlinde) #21

IMHO if , as @AndreLinux just confirmed, mails with the header addition X-getmail-filter-classifier: Action: rewrite subject are spam,
it is enough to simply move them to the Junk folder with a adoption in the before.sieve without actually rewiring the subject.

@AndreLinux what do you think?


(Stéphane de Labrusse) #22

yes but nothing will be done if the checkbox move to junk is disabled :frowning:


(Andrea) #23

The subject is not actually rewritten, it remains unaltered. It is only the header that changes.


(Mark Verlinde) #24

Is this different behavior as with ‘X-SPAM-FLAG’ ‘YES’ ?


(Mark Verlinde) #25

But would it be good enough for you if the mails are moved to the Junk folder without rewriting the subject?

Rewriting the subject does not seem to be a simple task in our setup.


(Andrea) #26

would be fine


(Thorsten) #27

Today I got an E-Mail from Univention which I tried before Nethserver. I am still on the mailing list. It was send to one of the domains I handle using Nethserver (my old myname.dyndns.org adress): The subject was replaces to anounce its spam status and it was moved to junk - at least this part seems to work …


(Stéphane de Labrusse) #28

this is the postfix milter job, this is the normal way to handle email :slight_smile:


(Stéphane de Labrusse) #29

this could be just another sieve script in before.sieve provided by nethserver-mail2-getmail


(Thorsten) #30

Yes, that is my expectation, too. Just from this discussion, I was not sure if it works on my system at all :slight_smile:


(Stéphane de Labrusse) #31

Just a first workaround, replace the file with the content below

nano /etc/e-smith/templates/var/lib/nethserver/sieve-scripts/before.sieve/10junkmail

#
# 10junkmail 
#
{
return '# -- disabled (Spam is delivered to INBOX)' if ( ! $dovecot{SpamFolder});

$OUT .= qq(
# -- enabled (move marked SPAM messages into junkmail folder)
require ["fileinto", "mailbox","regex"];
if header :contains "X-Spam-Flag" "YES" {
    fileinto :create "$dovecot{SpamFolder}";
    stop;
}

# -- enabled (move spam subject to junkmail folder)
if header :regex ["X-getmail-filter-classifier"] ["add header"] {
    fileinto :create "Junk";
    stop;
}
);

$OUT .= qq(
# -- enabled (move spam subject to junkmail folder)
if header :contains "subject" "$rspamd{SpamSubjectPrefixString}" {
   fileinto :create "$dovecot{SpamFolder}";
   stop;
}

# -- enabled (move spam subject to junkmail folder)
if header :regex ["X-getmail-filter-classifier"] ["rewrite subject"] {
    fileinto :create "Junk";
    stop;
}
) if (($rspamd{SpamSubjectPrefixString}) && ($rspamd{SpamSubjectPrefixStatus} eq 'enabled'));
}

it is not supposed to rewrite the subject, only to move to junk when the header add header or rewrite subject is found


(Stéphane de Labrusse) #32

Maybe we could have a solution to change the header subject with sieve

reading this it could be possible to delete a header and to make it again with a new value : https://tools.ietf.org/html/rfc5293

not tested yet, a bit tricky with the risk to delete an important header and break the email :frowning:


(Stéphane de Labrusse) #33

ok we could rewrite the subject with dovecot/sieve

in /etc/dovecot/dovecot.conf

-       sieve_extensions = +imapflags
+       sieve_extensions = +imapflags, +editheader

restart dovecot

in /var/lib/nethserver/sieve-scripts/before.sieve

-   require ["fileinto", "mailbox"];
+    require ["fileinto", "mailbox","editheader","variables","regex"];

+    if header :matches "Subject" "*" {
+            set "subjwas" ": ${1}";
+    }

+    if header :regex ["X-getmail-filter-classifier"] ["rewrite subject"] {
+   deleteheader :index 1 "subject";
+    addheader :last "subject" "***SPAM*** ${subjwas}";
+    }

    if header :contains "X-Spam-Flag" "YES" {
        fileinto :create "Junk";
        stop;
    }

no need to install an extra rpm or service

@dev_team what do you think

  • create a sieve script to rename the subject if matches rewrite subject (our ***spam*** sieve rule should put it after to junk)
    or
  • create a sieve script to move to junk if matches rewrite subject or add header (if MoveToJunk is enabled’)

(Thorsten) #34

WOW - I am impressed :-:muscle::ok_hand::+1:
However I implemented “just move to junk” at the moment.


(Thorsten) #35

What is the correct module to apply changes for?
Is it

signal-event nethserver-mail-filter-save


(Thorsten) #36

WORKS! Spam mail collecte via Getmail ist placed in the corresponding spam folders!


(Stéphane de Labrusse) #37

Issue opened


(Andrea) #38

I confirm that it works!

Thanks @stephdl


(Stéphane de Labrusse) #39

what is working please ?


(Andrea) #40

emails colleted by getmail and considered as spam by rspamd are correctly moved to the junk folder with the modified object.