3

I'm quite new to Dovecot but it has worked out for me pretty good so far for me. I run dovecot with postfix and amavis and spamassassin and it works out all fine, mails get tagged as junk, sending, receiving, all fine.

Now I wanted to add the sieve plugin so mails get moved on the server and that does not work out. I wanted to start with a general script moving the junk to the junk folder but that is not happening.

So I searched the web and found the troubleshooting, which said, that sieve is propably not running. I did not manage to find any log entries made by sieve so this could be the problem. Here I found that you have to put sieve to the protocols, I guess in dovecot.conf.

I tried and dovecot didnt start anymore posting unkown protocol: sieve. I added lmtp to the protocols as I want to use it and it was posted in another thread but I got the error: service(lmtp) accces failed: no such file or directory.

Some system infos:
OS: Debian 7
Dovecot Version: 2.1.7

Config Files: dovecot.conf (reduced on changed/added)

protocols = imap pop3

plugin {
    sieve_before = /var/vmail/sieve/spam-global.sieve
    sieve_dir = /var/vmail/%d/%n/sieve/scripts/
    sieve = /var/vmail/%d/%n/sieve/active-script.sieve
}

conf.d/20-lmtp.conf (created it)

protocol lmtp {  
    # Space separated list of plugins to load (default is global mail_plugins).  
    mail_plugins = $mail_plugins sieve  
}  

spam-global.sieve

require "fileinto";  
if header :contains "X-Spam-Flag" "YES" {  
    fileinto "Spam";  
}  

How can I check, wether sieve is running?

Afaik Postfix needs to be configured to work with sieve. I'm not sure I did that so far but as long as sieve wont run, that wont solve the problem right?

Thanks for any help Invalid

invalid
  • 31
  • 2
  • You are missing the Postfix configuration, Postfix needs deliver via dovecot, as postfix can't handle sieve. See [Dovecot LDA with Postfix](http://wiki2.dovecot.org/LDA/Postfix) – sebix Aug 21 '15 at 19:06

1 Answers1

2

You say you had to create the file?

Sounds like you never installed the protocol plugin under dovecot.

  1. First, DO NOT edit (or create) the installed conf files when avoidable. Make your own. Create a /etc/dovecot/local.cf OR /etc/dovecot/conf.d/99-custom.conf (for example).

  2. In newer Dovecot distro versions, the LDA (15-lda.conf) plugin is installed by default, but not the LMTP plugin (20-lmtp.conf). You can use the LDA plugin. (Local Delivery Agent).

  3. If you still wish to use LMTP, you need to install the plugin: sudo apt install dovecot-lmtpd. If you had done that, you wouldn't need to create the .conf file for it.

The pertinent Sieve areas of my /etc/dovecot/local.cf:

protocol imap {

  mail_plugins = autocreate
}
plugin {
   autocreate = Spam
   autosubscribe = Spam
}

# SIEVE STUFF
# Include already included protocols and sieve:
protocols = $protocols sieve

# Allow sieve to be run out of LDA plugin/protocol:
protocol lda {
  mail_plugins = $mail_plugins sieve
}

# Sieve plugin settings
plugin {
   sieve = file:~/sieve;active=~/.dovecot.sieve
   sieve_default = /usr/local/lib/dovecot/sieve/default.sieve
   sieve_global = /usr/local/lib/dovecot/sieve/
}

# May not need this, but it doesn't hurt:
service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
}

The pertinent Sieve areas of my /etc/postfix/main.cf (using dovecot lda/deliver):

mailbox_command = /usr/lib/dovecot/dovecot-lda -f "$SENDER" -a "$RECIPIENT"
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1

My default.sieve:

require ["envelope", "fileinto", "mailbox", "subaddress"];

if header :contains "X-Spam-Flag" "YES" {
        fileinto :create "Spam";
}
if header :contains "X-Amavis-Alert" "BAD HEADER SECTION" {
        fileinto :create "Spam";
}
if address :domain "From" "mydomain.net" {
   if not envelope :domain "From" "mydomain.net" {
      fileinto "Spam";
      stop;
   }
}
if address :domain "From" "mydomain.com" {
   if not envelope :domain "From" "mydomain.com" {
      fileinto "Spam";
      stop;
   }
}

Pertinent area of /etc/amavis/conf.d/50-user (or make your own: 99-custom) :

@local_domains_acl  = ( [ ".$mydomain", '.mydomain.net', '.mydomain.com' ] );
@local_domains_maps = ( [ ".$mydomain", '.mydomain.net', '.mydomain.com' ] );
# Do not quarantine or trash emails - hand off to LDA instead
$final_spam_destiny=D_PASS;
$final_virus_destiny=D_PASS;
$final_bad_header_destiny=D_PASS;
@addr_extension_spam_maps=('Spam');

Restart Dovecot and test port:

# sudo systemctl restart dovecot
# telnet 10.10.10.100 4190
Trying 10.10.10.100...
Connected to 10.10.10.100.
Escape character is '^]'.
"IMPLEMENTATION" "Dovecot (Ubuntu) Pigeonhole"
"SIEVE" "fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext"
"NOTIFY" "mailto"
"SASL" "PLAIN"
"STARTTLS"
"VERSION" "1.0"
OK "Dovecot (Ubuntu) ready."

Dovecot debug output - can see it working:

2019-05-16 15:29:49 lda(emailuser1): Debug: Loading modules from directory: /usr/lib/dovecot/modules
2019-05-16 15:29:49 lda(emailuser1): Debug: Module loaded: /usr/lib/dovecot/modules/lib90_sieve_plugin.so
2019-05-16 15:29:49 lda(emailuser1): Debug: Effective uid=1000, gid=1000, home=/home/emailuser1
2019-05-16 15:29:49 lda(emailuser1): Debug: Namespace inbox: type=private, prefix=, sep=, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:/home/emailuser1/Maildir
2019-05-16 15:29:49 lda(emailuser1): Debug: maildir++: root=/home/emailuser1/Maildir, index=, indexpvt=, control=, inbox=/home/emailuser1/Maildir, alt=
2019-05-16 15:29:49 lda(emailuser1): Debug: userdb lookup skipped, username taken from USER environment
2019-05-16 15:29:49 lda(emailuser1): Debug: none: root=, index=, indexpvt=, control=, inbox=, alt=
2019-05-16 15:29:49 lda(emailuser1): Debug: Destination address: emailuser1@mydomain.net (source: -a parameter)
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: Pigeonhole version 0.4.21 (92477967) initializing
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: file storage: Storage path `/home/emailuser1/sieve' not found
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: file storage: Storage path `/home/emailuser1/.dovecot.sieve' not found
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: storage: Trying default script location `/usr/local/lib/dovecot/sieve/default.sieve'
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: file storage: Using Sieve script path: /usr/local/lib/dovecot/sieve/default.sieve
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: file script: Opened script `default' from `/usr/local/lib/dovecot/sieve/default.sieve'
2019-05-16 15:29:49 lda(emailuser1): Debug: sieve: Using the following location for user's Sieve script: /usr/local/lib/dovecot/sieve/default.sieve

Sieve now runs. Your question answered.

As far as anything I may have missed - each setup can vary. Please review some articles if you are still stuck. My sieve global rules store quarantine stuff in per-user 'Spam' folders (users are non-virtual). As pointed out, you probably need to edit your postfix main.cf (and master.cf if virtual users/vmail) as noted here to use Dovecot LDA. You also probably need to edit your content-filter (amavis-new for instance) as noted. There are articles out there for this.

B. Shea
  • 959
  • 10
  • 22