This is the support site for Andrews & Arnold Ltd, a UK Internet provider. Information on these pages is generally for our customers but may be useful to others, enjoy!

Back up to the sieve page

Difference between revisions of "Sieve-Example:Move email to a suffix folder"

From AAISP Support Site
Jump to navigation Jump to search
[checked revision][checked revision]
(fix syntax)
 
(7 intermediate revisions by 2 users not shown)
Line 8: Line 8:
 
me-amazon@example.com
 
me-amazon@example.com
 
me-ebay@example.com
 
me-ebay@example.com
  +
...
  +
me-ANYTHING@example.com
  +
  +
or the other way around, if you preferred:
  +
ebay-me@example.com
  +
amazon-me@example.com
  +
...
  +
ANYTHING-me@example.com
  +
  +
You also want this to be flexible and work as a 'catch-all' for any addresses you have as your suffix or prefix - you don't want to have to log in to the control page each time you want to create a new prefix/suffix.
  +
  +
(you can also use a '''+''' instead of a '''-''' if you wanted to - just alter the settings appropriately below)
   
 
This is all possible with two things:
 
This is all possible with two things:
*An alias - set on the Control Pages
+
#An alias - set on the Control Pages to - direct these extra addresses to your mailbox
*(optionally) A sieve filter
+
#(optionally) A sieve filter - to magically sort these messages in to their own IMAP folder
   
 
==Alias==
 
==Alias==
Line 28: Line 40:
 
## Move messages sent to an address with a suffix eg, me-amazon@example.com in to a folder called Filtered/amazon, if it exists.
 
## Move messages sent to an address with a suffix eg, me-amazon@example.com in to a folder called Filtered/amazon, if it exists.
 
if exists "X-Delivered-To" {
 
if exists "X-Delivered-To" {
 
 
if header :regex "X-Delivered-To" "-([A-z0-9]+)@" {
 
if header :regex "X-Delivered-To" "-([A-z0-9]+)@" {
 
set "suffix" "${1}";
 
set "suffix" "${1}";
 
fileinto "INBOX.Filtered.${suffix}";
 
fileinto "INBOX.Filtered.${suffix}";
 
stop;
 
}
 
}
  +
}
stop;}
 
 
</syntaxhighlight>
 
</syntaxhighlight>
   
Line 42: Line 54:
 
===Variations===
 
===Variations===
 
You can create the folders automatically if you wanted add :create, - but some mail clients won't refresh their folder list until they are restarted. We also title case the new folder name - eg it will be called Amazon (capital A).
 
You can create the folders automatically if you wanted add :create, - but some mail clients won't refresh their folder list until they are restarted. We also title case the new folder name - eg it will be called Amazon (capital A).
  +
<syntaxhighlight lang="sieve">
 
set :upperfirst "suffix" "${1}";
 
set :upperfirst "suffix" "${1}";
 
fileinto :create "INBOX.Filtered.${suffix}";
 
fileinto :create "INBOX.Filtered.${suffix}";
  +
</syntaxhighlight>
  +
If you're using a + rather than a - to separate the suffix, then adjust the regex in the sieve filter above to be like:
  +
<syntaxhighlight lang="sieve">
  +
if header :regex "X-Delivered-To" "\\+([A-z0-9]+)@" {
  +
</syntaxhighlight>
   
 
== Create the folders ==
 
== Create the folders ==
Line 52: Line 70:
   
 
[[File:Email folders.png|thumb|none|100|Folder layout in your email client]]
 
[[File:Email folders.png|thumb|none|100|Folder layout in your email client]]
  +
  +
[[Category:Sieve]]

Latest revision as of 08:54, 8 September 2022


Description

Say you have a single mailbox:

me@example.com

And you want to give out 'unique' addresses to companies so that you can control who has your address and helps you track and filter your email. You may want to give out addresses such as:

me-amazon@example.com
me-ebay@example.com
...
me-ANYTHING@example.com

or the other way around, if you preferred:

ebay-me@example.com
amazon-me@example.com
...
ANYTHING-me@example.com

You also want this to be flexible and work as a 'catch-all' for any addresses you have as your suffix or prefix - you don't want to have to log in to the control page each time you want to create a new prefix/suffix.

(you can also use a + instead of a - if you wanted to - just alter the settings appropriately below)

This is all possible with two things:

  1. An alias - set on the Control Pages to - direct these extra addresses to your mailbox
  2. (optionally) A sieve filter - to magically sort these messages in to their own IMAP folder

Alias

On the control pages, in the email setup, under aliases create an alias such as:

Alias

This sends messages addressed to me-ANYTHING@example.com to the me Mailbox

Sieve filter

Optionally, you can magically move these messages in folders...

Once messages are being sent to your Inbox with the alias above, you can create a sieve filter to automatically move messages to their folder, if you've made the folder already.

require ["fileinto","imap4flags","variables","regex","mailbox"];

## Move messages sent to an address with a suffix eg, me-amazon@example.com in to a folder called Filtered/amazon, if it exists.
if exists "X-Delivered-To" {
         if header :regex "X-Delivered-To" "-([A-z0-9]+)@" {
                set "suffix" "${1}";
                fileinto "INBOX.Filtered.${suffix}";
                stop;
        } 
}
  • This filter uses the 'X-Delivered-To' header which is added by the A&A mail servers - even if you are BCC'd then the filtering will work. The X-Delivered-To is the 'envelope-to' header, which is the address the email was actually sent to by the sender (in lowercase).
  • You'll need to add this sieve filter - eg by using the (latest) Thunderbird Sieve extension, see Sieve_Server_Settings for info in the 'Creating Sieve Filters' section
  • This won't be able to be added via Roundcube, as you can't paste in raw sieve code there.

Variations

You can create the folders automatically if you wanted add :create, - but some mail clients won't refresh their folder list until they are restarted. We also title case the new folder name - eg it will be called Amazon (capital A).

                set :upperfirst "suffix" "${1}";
                fileinto :create "INBOX.Filtered.${suffix}";

If you're using a + rather than a - to separate the suffix, then adjust the regex in the sieve filter above to be like:

          if header :regex "X-Delivered-To" "\\+([A-z0-9]+)@" {

Create the folders

The sieve filter puts email in to a folder called Filtered/XXX, and as long as XXX matches the suffix in the email address, the messages will get moved to there. So in your email program:

  1. Create a folder called: Filtered
  2. Create folders within Filtered for the suffix you want filtered there
Folder layout in your email client