thsmi / sieve

Sieve Script Editor
GNU Affero General Public License v3.0
735 stars 56 forks source link

how to combine 'if' and 'if not'? #872

Closed xpseudonym closed 1 year ago

xpseudonym commented 1 year ago

Prerequisites

Is your feature request related to a problem?

Hmm, may be - it's more a question... Why can't I add a 'not' test as described here: https://support.tigertech.net/sieve#sieve-example-rules-jmp ?

(Also - or, should I start another issue - what's the difference between an 'envelope-to' and an 'address bcc' test?)

Describe the solution you'd like

I'd like to be able to combine 'is' and 'is not' operators

thsmi commented 1 year ago

well it would help if you would be way more verbose, describe at least your intentions and provide an example. This saves your as well as my time and avoids unnecessary communication loops.

As crystal balls are not on stock all I can do is to do an educated guess. Thus I would say you have added a test in the Graphical Editor and want to negate this test.

If this is true then all you need to do is drag the "not" operator onto your test you want to negate.

If you question is about combining two or more tests via an anyof or allof operator. Then the answer is equally simple. Just drag the "anyof" operator onto a test which should be wrapped into a testlist.

To avoid confusion keep in mind a "not" is in sieve grammar an operator which can only be placed before a test. It is not possible to place it before a match type (:is or :contains).

Concerning you other question. Please don't spam an issue tracker with trivial questions you can easily answer in less than 5 second yourself by just using google or even Wikipedia:

An Internet email consists of an envelope and content; the content consists of a header and a body.

Furthermore it is described in the help tab inside the envelope test: image

xpseudonym commented 1 year ago

Thank you @thsmi First off, big apologies. Second, I'll go away and think about what you've said and try to come back having learnt how to better express myself - it was a bit off the cuff and no doubt I should have done a bit more thinking. But, before I slink away with my tail between my legs:- Re the BCC and envelope-to question, it seemed to me that they were logically the same - if an SMTP server strips the BBC headers only to leave the envelope, then it seems that a filter on a BCC (to) address must be the same as a filter on an envelope-to address because by the time the message gets to the filter it's had all the headers removed to leave only the envelope? It was the logical similarity that intrigued me and I guess I didn't express myself well.

thsmi commented 1 year ago

I guess you misconception is that you assume mail headers and the envelope is the same.

They are two distinct things. Just look at the SMTP Protocol Example at Wikipedia: https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol#SMTP_transport_example

Whenever a mail is received. The SMTP client has to tell from whom the mail (MAIL FROM) is and who is/are the recipient.(RCPT TO). After doing so the server normally verifies if the client is trustworthy e.g. via DKIM or similar methods. If so it signals the client that it can transfer the content. Which is the mail, made from headers as well as a body.

The SMTP receiver does not care about the actual mail content (means both headers and body). It is for him just a fully transparent blob of data. It neither knows any thing about TO, CC nor a BCC. Only a "RCPT TO" is for him of interest and thus it normally does not strip any headers.

After an envelope is received, the SMTP Receiver tells the MTA the "RCPT TO" and "MAIL FROM" Information as well as the mail content. The MTA uses then the RCPT TO address find which mailbox should receive the message. It also does not care about the (optional) TO, BCC, CC or whatever header resided inside a mail.

Sieve runs after the MTA identified which user mailbox but before the message is delivered to the mailbox. At this stage you have access to all of the envelope information, which is RCPT TO, MAIL FROM as well as the mail content with headers and a body .

Faking a envelope's "RCPT TO" or "MAIL FROM" is difficult on a hardened server. Faking headers is extremely easy. So the Envelope should be always the weapon of choice. The only issue with the Envelope information is that is is lost as soon as the message is delivered into the user's mailbox on the server. This makes writing and debugging sieve filters for a normal user really hard (unless you have direct access to the server). Because a user can only guess what the original MAIL FROM or RCPT TO was. Thus some admins configure their servers to add headers containing the envelope data to the mail's headers or even fix mails without a "TO" or "FROM" (They fill the information with envelope information). But the issue is that this is not standardized and you have no chance to see if the MAIL FROM or RCPT TO is fake or not. Because headers are normally only added but not removed or overwritten.

So to sum it up SMTP Envelope information is extremely reliable but hard to use. While E-Mail Headers are completely unreliable but very easy to use.

xpseudonym commented 1 year ago

Yes, and thank you again.

I hadn't appreciated the distinction between 'header' (part of content) and 'envelope' (not part of content).

If so it signals the client that it can transfer the content. Which is the mail, made from headers as well as a body.

Even to the extent that they're transmitted separately.

Understanding where the filter sits in the process helps to understand better the mechanics of how the tests should be used. Thx