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 22 Jan 2023, 03:16 AM   #1
qwertz123456
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;
}
Can I combine these two scripts (1 & 2) and what would that look like? Is there any parameter I need to add to combine these into one sieve script?

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;
}
Is there a way to remove the automatically added "Your message was automatically rejected by Sieve, a mail filtering language." and have the rejected message just say "Mailbox does not exist"?


4. Finding duplicate messages and moving to folder

Code:
require ["duplicate", "variables"];
if header :matches "message-id" "*" {
  if duplicate :uniqueid "${0}" {
    fileinto “Duplicates”;
  }
}
The duplicate folder will be in the root folder of my account. And I assume if I used the message-id that that would be the most strict or exact form of duplicate identification and not have any similar email be moved here. Or is my understanding wrong?

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.
qwertz123456 is offline   Reply With Quote

Old 22 Jan 2023, 03:39 AM   #2
BritTim
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;
}
Hope I have that syntax correct. It has been a while since I wrote sieve scripts.

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!
BritTim is offline   Reply With Quote
Old 22 Jan 2023, 04:51 AM   #3
qwertz123456
Essential Contributor
 
Join Date: Jan 2008
Posts: 377
Quote:
Originally Posted by BritTim View Post

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!
Thanks, that's a good idea. I'm having trouble with the duplicate rule as that seems much more complex. Any ideas if that code is correct? Not sure how I would test it though.

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.
qwertz123456 is offline   Reply With Quote
Old 22 Jan 2023, 04:31 PM   #4
BritTim
The "e" in e-mail
 
Join Date: May 2003
Location: mostly in Thailand
Posts: 3,084
Quote:
Originally Posted by qwertz123456 View Post
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?
In almost all cases where you want a message discarded, you do not want any further tests applied to that message. "stop" informs the system of that. It has no effect on any other message.

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.
BritTim is offline   Reply With Quote
Old 22 Jan 2023, 04:45 PM   #5
BritTim
The "e" in e-mail
 
Join Date: May 2003
Location: mostly in Thailand
Posts: 3,084
Quote:
Originally Posted by qwertz123456 View Post
I'm having trouble with the duplicate rule as that seems much more complex. Any ideas if that code is correct? Not sure how I would test it though.
My advice on the duplicates test is not to bother until you find you need to. Fastmail usually resolves the problem for you. If delivering both messages to the same folder, Fastmail recognises the duplication, and does duplicate message suppression automatically on your behalf.

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)
BritTim is offline   Reply With Quote
Old 22 Jan 2023, 08:23 PM   #6
xyzzy
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.
xyzzy is offline   Reply With Quote
Old 23 Jan 2023, 12:03 AM   #7
qwertz123456
Essential Contributor
 
Join Date: Jan 2008
Posts: 377
Quote:
Originally Posted by BritTim View Post
In almost all cases where you want a message discarded, you do not want any further tests applied to that message. "stop" informs the system of that. It has no effect on any other message.

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.
OK, now I think I understand. So if the IF-statement hold true and the script does something that's generally where the users wants to stop (unless the message should be processed further). If the IF-statement does not hold true, then the "stop" function has no effect and it move onto the next rule, right?

If so, then I've learned something, thanks
qwertz123456 is offline   Reply With Quote
Old 23 Jan 2023, 12:04 AM   #8
qwertz123456
Essential Contributor
 
Join Date: Jan 2008
Posts: 377
Quote:
Originally Posted by xyzzy View Post
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.
Ah, thanks. I'll change that as well.
qwertz123456 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 10:44 PM.

 

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