Sieve Mailfilter – filter to folder

As allready wrote, #Sieve Mailfilter and how to have fun, today i show a sniped to filter Mails from whole Domains or single-Sender to a folder.

  1. split the TLD from E-Mail-Address

    #set Domain
    if envelope :domain :matches "from" "*.*" {
    set :lower "domain" "${1}-${2}";
    }
    

    With this Information we are able to the Domain for later use.

  2. split the localuser-Part and replace dots (.) by minus (–)

    #set from, replace . with -
    if envelope :localpart :matches "from" "*.*.*" {
    set :lower "localuser" "${1}-${2}-${3}";
    }
    elsif envelope :localpart :matches "from" "*.*" {
    set :lower "localuser" "${1}-${2}";
    }
    elsif envelope :localpart :matches "from" "*" {
    set :lower "localuser" "${1}";
    }
    

    With this we have a localuser part

  3. at leased we try to find the right directory for the E-Mail to send in

    # domain in INBOX
    if mailboxexists "INBOX.${domain}" {
    fileinto "INBOX.${domain}";
    stop;
    }
    # E-Mail in INBOX
    if mailboxexists "INBOX.${localuser}+${domain}" {
    fileinto "INBOX.${localuser}+${domain}";
    stop;
    }
    

    Notice: a Plus-Sign (+) will be used at At-Sign (@) in the folder-structure.

In this example will all incoming mails sorted in Folder if there is a folder by Domain or fully sender Address in INBOX.

Have fun ;)