|
FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc. |
|
Thread Tools |
22 Jan 2023, 03:16 AM | #1 |
Essential Contributor
Join Date: Jan 2008
Posts: 377
|
[Help needed] A few sieve scripts for review
Hey guys,
I need some help with a couple of sieve scripts I'm trying to create. I'm not a coder so it's a bit more difficult for me to figure out how the syntax works. I tried finding some of the code on the interwebs and here in the forum. Basically, I want to create the following rules/sieve scripts. 1. Discard messages from specific addresses / exact match Code:
if address :is ["X-Mail-from"] ["email1@domain.com","email2@domain.com"] { discard; stop; } 2. Discard messages from specific domains / exact match Code:
if address :domain :is ["X-Mail-from"] ["domain1.com","domain2.com"] { discard; stop; } 3. Rejects specific addresses with a message I do NOT intend to use this for spammers, but for very specific people that I want to know that this address does not exist. I will add further addresses if need be. Code:
if address :is ["X-Mail-from"]["email1@domain.com","email2@domain.com"] { reject "Mailbox does not exist"; stop; } 4. Finding duplicate messages and moving to folder Code:
require ["duplicate", "variables"]; if header :matches "message-id" "*" { if duplicate :uniqueid "${0}" { fileinto “Duplicates”; } } Anyway to have this also search my complete mailbox (all existing folders)? Probably not, right? Once these sieve scripts are working is there a requirement to drag these rules to the top of the button of my other normal FM rules? Last edited by qwertz123456 : 22 Jan 2023 at 03:51 AM. |
22 Jan 2023, 03:39 AM | #2 |
The "e" in e-mail
Join Date: May 2003
Location: mostly in Thailand
Posts: 3,084
|
For combining tests, you need to master anyof and allof. For example
Code:
if anyof ( address :is ["X-Mail-from"] ["email1@domain.com","email2@domain.com"], address :domain :is ["X-Mail-from"] ["domain1.com","domain2.com"] ) { discard; stop; } I suggest you initially have scripts you intend to use to discard messages instead fileinto "todiscard" or something. Especially with complex scripts, things do go wrong, and are easier both to diagnose and recover from if messages still exist! |
22 Jan 2023, 04:51 AM | #3 | |
Essential Contributor
Join Date: Jan 2008
Posts: 377
|
Quote:
And what happens if I don't add the "stop" at each rule. As I have more rules and would want those to be followed as well would it be necessary to add a stop as well and each rule? Or would it stop after that rule and not follow any more? Last edited by qwertz123456 : 22 Jan 2023 at 06:17 AM. |
|
22 Jan 2023, 04:31 PM | #4 | |
The "e" in e-mail
Join Date: May 2003
Location: mostly in Thailand
Posts: 3,084
|
Quote:
Basically, after any action that affects a message (discard, fileinto etc.) you should decide whether your processing of that particular message is over. If so, use "stop". Failing to do so can lead to very surprising results as the message is examined by later tests. |
|
22 Jan 2023, 04:45 PM | #5 | |
The "e" in e-mail
Join Date: May 2003
Location: mostly in Thailand
Posts: 3,084
|
Quote:
If you do need the test, use fileinto "duplicates" (or similar) to verify a duplicate was received and the test worked. Generate the duplicate by sending a message to two recipients (your regular account, and another that simply forwards the message to your regular account) |
|
22 Jan 2023, 08:23 PM | #6 |
Essential Contributor
Join Date: May 2018
Posts: 474
|
I think you should be testing the "From" header, not the "X-mail-from" header. The bracket around these is optional since you are only testing a single kind of header.
FWIW, a folder's advanced settings has a "discard duplicates" settings. Discard cancels the implict "keep" but it doesn't stop any actions that follow from executing. So add the stop after the discard if that's all you want to do. And as mentioned in a preceding post it's not a good idea to just quietly drop messages on the floor. As suggested create a distinct "discard" folder to capture these. You can always set the keep amount for that folder to allow FM to auto-delete them after a desired period of time. |
23 Jan 2023, 12:03 AM | #7 | |
Essential Contributor
Join Date: Jan 2008
Posts: 377
|
Quote:
If so, then I've learned something, thanks |
|
23 Jan 2023, 12:04 AM | #8 |
Essential Contributor
Join Date: Jan 2008
Posts: 377
|
|
Thread Tools | |
|
|