EmailDiscussions.com  

Go Back   EmailDiscussions.com > Email Service Provider-specific Forums > FastMail Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Stay in touch wirelessly

FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc.

Reply
 
Thread Tools
Old 2 Jan 2025, 11:25 AM   #1
marc1
Essential Contributor
 
Join Date: Sep 2002
Posts: 345
Question Apply rule before spam?

I have some rules setup but the emails often go to spam and thus it seems the rules never get applied. My understanding is that to fix this I would have to edit the Sieve script?

Once I start editing the Sieve, can I still use the web interface to add/edit rules? I am not much of a coder and prefer the web interface to manage my rules rather than having to edit a text file each time.

Any suggestions for the best way to you about this?

(Btw, the rule I am trying to create is for emails with a specific TO/CC/BCC address to go straight to the trash.)
marc1 is offline   Reply With Quote

Old 3 Jan 2025, 06:14 PM   #2
xyzzy
Essential Contributor
 
Join Date: May 2018
Posts: 486
Short answer: Your mail rules specified in the UI are always handled after the spam threshold tests.

Long answer:

Open your "Mail rules" page and click "Edit custom Sieve code" to see your sieve script.

In the sieve script you will see the code for the rules you created in the UI (starting with the comment "### Calculate rule actions") are located after the section that starts with "### Sieve generated for save-on-SMTP identities {{{". You will see that the "Spam Protection" value tests are done before the mail rules.

Before the "### Sieve generated for save-on-SMTP identities {{{" section (and after it too) you will see a blank area where you can add your own code.

So in you specific case add the sieve code in the blank area before the "### Sieve generated for save-on-SMTP identities {{{" section. That way it will always be done no matter what the spam score is.

If you don't know how to code sieve then create a rule in your UI like a normal rule as a example just to see what sieve code is generated for the tests. All you need do is the same tests and for the true part add,

fileinto "\\Trash";
stop;

So those emails that satisfy the tests will file those messages into the trash and stop the script so it never executes the stuff that follows.

Last edited by xyzzy : 3 Jan 2025 at 08:03 PM.
xyzzy is offline   Reply With Quote
Old 6 Jan 2025, 09:05 AM   #3
marc1
Essential Contributor
 
Join Date: Sep 2002
Posts: 345
Thank you xyzzy!
marc1 is offline   Reply With Quote
Old 7 Jan 2025, 10:07 AM   #4
marc1
Essential Contributor
 
Join Date: Sep 2002
Posts: 345
hmm, I thought it was working but it is not -- emails are still ending up in spam, rather than the trash.

Originally I was using

Code:
if address :is ["to", "cc", "bcc"]
but when that was not working, I switched to "X-Delivered-To" header, so my code looks like this:

Code:
require ["fileinto"];

if header :is "X-Delivered-To" "abc@xyz.com" {
    fileinto "\\Trash";
} elsif header :is "X-Delivered-To" "def@xyz.com" {
    fileinto "\\Trash";
stop;
}
and this code is placed in the first Sieve input box, above "Sieve generated for save-on-SMTP identities"

When I paste my code and a raw message with one of those email addresses into the tester, it says "filing message into '\Trash'"

But again, these message are ending up in Spam not trash.
marc1 is offline   Reply With Quote
Old 7 Jan 2025, 07:46 PM   #5
xyzzy
Essential Contributor
 
Join Date: May 2018
Posts: 486
I'll ignore that if address construct since I'm not sure where you were going with that one. As for the one that uses the X-Delivered-to's it should work if X-Delivered-to is def@xyz.com but as written it will not stop for abc@xyz.com so execution will reach the later spam score checking which is what I think you are seeing.

The way you indented that stop command I assume you intended it to apply to all the individual address tests when they match but you only have it in the true block of the def@xyz.com (2nd) test. That's correct but you need a stop for each individual test when true. So properly indented it should look something like:

Code:
require ["fileinto"];

if header :is "X-Delivered-To" "abc@xyz.com" {
    fileinto "\\Trash";
    stop;
} elsif header :is "X-Delivered-To" "def@xyz.com" {
    fileinto "\\Trash";
    stop;
}
A shorter way to write this would be,

Code:
require ["fileinto"];

if header :is "X-Delivered-To" ["abc@xyz.com", "def@xyz.com"] {
    fileinto "\\Trash";
    stop;
}
And if you have a lot of these addresses you can "pretty" it up a little by formatting the list of addresses on one per line as follows (switched to a mono font here since this forum's # formatting screws up the illustration - wish Sieve Tester would use a mono font like its shown in the actual Sieve script but I digress):

Code:
require ["fileinto"];

if header :is "X-Delivered-To" ["abc@xyz.com",
                                "def@xyz.com"] {
    fileinto "\\Trash";
    stop;
}
IMO it makes them easier to add or delete list entries. Just remember the end of the list doesn't have a comma!

Last edited by xyzzy : 7 Jan 2025 at 08:06 PM.
xyzzy is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 11:53 PM.

 

Copyright EmailDiscussions.com 1998-2022. All Rights Reserved. Privacy Policy