0

I'm wondering if it's possible to setup filter in sieve to catch the FROM domain and match that with the TO recipient mailbox name.

Usage is to filter unwanted emails when companies sell/share my personal information.

ex.

This should be accepted:

FROM: no-reply@some-company.com
TO: some-company@mydomain.com

This should be rejected:

FROM: no-reply@other-company.com
TO: some-company@mydomain.com
plejon
  • 1
  • 1

1 Answers1

0

Probably you need "allof" operator, which is boolean "and" for several tests. Something like this:

require ["fileinto", "mailbox"];
if allof
    (
        address "To" "some-company@mydomain.com",
        address "From" "no-reply@other-company.com"
    )
{
     fileinto "INBOX.Trash";
}

Notice, it is bad idea to reject on this stage, because it will generate a bounce and this is often not desired. The mail is already accepted by the time it is given to Sieve, so you can move it to spam or to trash, discard (silently delete) and so on, but don't reject.

Also notice that "To" and "From" headers from the mail can easily be forged. I'll be able to circumvent this filter by setting correct envelope address and faking the "To" header inside the mail to something other. It is envelope address (specified in the SMTP "RCPT To" command rather than the message header) controls which mailbox the mail gets delivered into. To test against envelope addresses, use the word "envelope" instead of "address" in the test, and also require "envelope" Sieve module.

See for example here for details.

Nikita Kipriyanov
  • 10,947
  • 2
  • 24
  • 45
  • Alright cool, thanks for the reponse! do you know if it's possible to actually catch/split the origin sender domain into a variable to be used to match the destination mailbox name? meaning, to have it more dynamic and not static. – plejon May 29 '22 at 20:01
  • Did you try any research [by yourself](https://bfy.tw/T8th)? – Nikita Kipriyanov May 30 '22 at 05:02