Blog.

Sieve filters are mail filtering rules executed by the mail server

Cover Image for Sieve filters are mail filtering rules executed by the mail server
Photo of  Kurtis Lowe
Kurtis Lowe

Sieve filters are mail filtering rules executed by the mail server (NB: not all of them offer it). In my opinion, this is the cleanest option for filtering emails: whatever my software for consulting my emails (webmail, graphical or textual client on computer, client on smartphone, etc. ) , the filtering will always be the same, without need to copy the rules.

To edit these rules, there are several solutions. The Blue mind groupware solution, which I use personally and professionally, provides a graphic editor on webmail, but it is too limited for my use: I can only combine rules and not mix them, create sub-rules, etc An example of a sub-rule: if I want the mails coming from the address to foo@example.orgbe stored in a folder foo, and if, among these mails, the subject contains bar, the mail is marked as read, I can write in Sieve:

if allof (address :contains "from" ["foo@example.org"] ) {

    if allof ( header :contains "Subject" "bar" ) {

        setflag "\\Seen";

    }

    fileinto "foo";

    stop;

}

But Bluemind does not allow this, the rules will be more basic (ah, GUI limitations!). Thunderbird can use an extension, Sieve to manage Sieve filters, but I'm not sure what it's worth anymore, I haven't used Thunderbird for a long time. Kmail , the KDE mail client that I use, allows you to (natively) manage Sieve filters graphically but pushed or… to write them directly. That's great! Ah but… it's not open in Vim . Too bad, I have my little habits and I hate using another text editor.

The command line: sieve-connect

So personally, I use Vim to write my Sieve scripts and sieve-connect to send them to my mail server. Example:

sieve-connect -s serveur.example.org -p 2000 -u luc@example.org \

 --localsieve /home/luc/filter.siv --upload --remotesieve mes_regles.sieve

Explanation of options:

  • -s serveur.example.org : the server address ;

  • -p 2000 : the port used by the server for the Sieve filter management interface;

  • -u luc@example.org : my login;

  • --localsieve /home/luc/filter.siv : the address of the file to push;

  • --upload : the action to be taken, therefore the sending to the server;

  • --remotesieve mes_regles.sieve : the name of the remote file in which I will push my rules. You can indeed have several rules files, but only one will be active. Convenient to have special rules for the holidays: just activate the file that contains them and go 🙂

Thereupon, sieve-connect will ask me for my password and presto, it's pushed!

Sieve-connect allows sending rules, retrieving them, listing rules files, enabling one or the other. So handy!

And the password?

To avoid having to give my password every time without putting it in a script, I'm going to take advantage of KWallet , the KDE password manager already contains the password for my mail account, since I uses Kmail. So just ask him!

I can request access to the password wallet via D-Bus  :

qdbus org.kde. kwalletd5 /modules/kwalletd5 open kdewallet imap "Sieve push"

The string "Sieve push"is the name I declare for my "application". Kwallet will ask me if I allow the "Sieve push" application to access the wallet. This command will return me one handlethat I will use in my subsequent requests. Looking in the graphical Kwallet management application, KWalletManager, I see that the password for my email account is akonadi_imap_resource_1rcfrom the imap. So to ask for the password, I do:

qdbus org.kde.kwalletd5 / https://www.seo25.com/product-category/website-traffic-packages/modules/kwalletd5 readPassword le_handle_obtenu_avant \

 imap akonadi_imap_resource_1rc "Sieve push"

NB: note that I repeat the name of my application, "Sieve push", in the command. It's necessary.

Just give the password to sieve-connect. To simplify, I combine all this in a function that I will put in my ~/.zshrc :

sievepush() {

    ID=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 open kdewallet imap "Sieve push")

    echo $(qdbus org.kde.kwalletd5 /modules/kwalletd5 readPassword $ID imap akonadi_imap_resource_1rc "Sieve push") | sieve-connect -s serveur.example.org -p 2000 -u luc@example.org --localsieve /home/luc/filter.siv --upload --remotesieve mes_regles.sieve

}

And There you go ! Just run sievepushfrom my terminal and it will send my filters file to my mail server. If my KWallet wallet is open, it will go directly, if not, it will ask me for the password of the wallet.

 


More Stories

Learn more: Targeting Visitors to Your Website: How to Retarget Them Again

Photo of  Kurtis Lowe
Kurtis Lowe

Why Mobile Users Matter to Online Businesses - What You Need To Know - Get Serious Traffic and Increase Your Blog's Traffic

Photo of  Kurtis Lowe
Kurtis Lowe