User Tools

Site Tools


doc:appunti:linux:sa:sieve_filtering_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
doc:appunti:linux:sa:sieve_filtering_examples [2023/03/22 23:25] – [Pipe a message to an external program] niccolodoc:appunti:linux:sa:sieve_filtering_examples [2023/03/24 12:54] – [Filtering with Sieve] niccolo
Line 1: Line 1:
 ====== Filtering with Sieve ====== ====== Filtering with Sieve ======
 +
 +The **Debian 11 Bullseye** GNU/Linux installs the **Dovecot** mail suite version **2.3.13**, including the **Pigeonhole Sieve** extension **v0.5.13** (via the **dovecot-sieve** package).
 +
 +The [[https://doc.dovecot.org/configuration_manual/sieve/pigeonhole_sieve_interpreter/|Pigeonhole Sieve Interpreter]] provides the //pipe//, //filter// and //execute// commands, where the //pipe// was the older one implemented (starting from v0.2). Currently the more modern //execute// command can be used instead of the //pipe// one.
 +
 +The following recipes were tested into a **$HOME/.dovecot.sieve** file, i.e. the users's Sieve filter applied by the Dovecot Local Delivery Agent.
  
 ===== Sender ===== ===== Sender =====
  
-Storing in different folder upon (envelope) sender:+Storing messages in different folder upon (envelope) sender:
  
 <code> <code>
Line 14: Line 20:
 ===== Recipient ===== ===== Recipient =====
  
-Storing in different folder upon destination address:+Storing messages in different folder upon destination address:
  
 <code> <code>
Line 25: Line 31:
 ===== Forward and keep a local copy ===== ===== Forward and keep a local copy =====
  
-The **redirect** built-in //action// can be modified by the **:copy** //tag// (which is a built-in extension, but it must enabled using the **require** statement). The '':copy'' means that the message is not completed by the ''redirect'' action; eventually the ''keep'' action will be finally executed.+The **redirect** built-in //action// can be modified by the **:copy** //tag// (which is a built-in extension, but it must enabled using the **require** statement). The '':copy'' tag means that the message is not completed by the ''redirect'' action; eventually the ''keep'' action will be finally executed.
  
 <code> <code>
Line 55: Line 61:
  
 ===== Pipe a message to an external program ===== ===== Pipe a message to an external program =====
 +
 +To enable the **execute** Sieve command using **Debian 11** you have to edit some configuration files contained into the **/etc/dovecot/conf.d/** directory. Set the **sieve_extension** option editing the file **90-sieve.conf**; in this example both the //filter// and //execute// extensions are loaded:
 +
 +<file>
 +plugin {
 +   ...
 +   sieve_extensions = +vnd.dovecot.filter +vnd.dovecot.execute
 +   ...
 +}
 +</file>
 +
 +Then you have to edit the **90-sieve-extprograms.conf** configuration file and define the **sieve_execute_socket_dir** and **sieve_execute_bin_dir** options:
 +
 +<file>
 +plugin {
 +  ...
 +  sieve_execute_socket_dir = sieve-execute
 +  sieve_execute_bin_dir = /usr/local/lib/dovecot/sieve-execute
 +  ...
 +}
 +</file>
 +
 +Only the executables contained into //sieve_execute_bin_dir// can be used as //execute// commands in sieve scripts.
 +
 +The following example is used to pipe a received message to an external program, which acts as a gateway from the mail system to the SMS mobile network. Only messages originating from some addresses and containing a properly formatted subject are piped to the external program:
  
 <code> <code>
 require ["vnd.dovecot.execute"]; require ["vnd.dovecot.execute"];
- 
 # Specially crafted messages are piped to an SMS gateway. # Specially crafted messages are piped to an SMS gateway.
 if allof ( if allof (
Line 69: Line 99:
 </code> </code>
  
-The **execute** command is not considered a final action (which "consumes" the message), so the **keep** action is eventually taken.+Here the **execute** //command// is called with the **:pipe** //tag//, this causes the execution of the external program much like the older ''pipe'' command. 
 + 
 +The **execute** command is not considered a final action (which "consumes" the message), so the **keep** action is eventually taken, saving the message into the INBOX.
  
   * **[[https://doc.dovecot.org/configuration_manual/sieve/plugins/extprograms/|Pigeonhole Sieve: Extprograms Plugin]]**   * **[[https://doc.dovecot.org/configuration_manual/sieve/plugins/extprograms/|Pigeonhole Sieve: Extprograms Plugin]]**
   * **[[https://mailutils.org/manual/html_chapter/Sieve-Language.html|GNU Mailutils Sieve]]**   * **[[https://mailutils.org/manual/html_chapter/Sieve-Language.html|GNU Mailutils Sieve]]**
  
doc/appunti/linux/sa/sieve_filtering_examples.txt · Last modified: 2023/03/24 12:59 by niccolo