Heho,
The documentation for sieve is here:
https://doc.dovecot.org/configuration_manual/sieve/configuration/
Sieve is its own script language for mail filtering. Once you
configured it, you can either use pidgeonhole/managesieve to edit the
sieverc, or just write one to the right path on your server.
You are looking for a sieve script like this (does what you asked for
for my mail account for a couple of years now.):
"""
require ["variables", "envelope", "fileinto", "subaddress"];
if envelope :matches :detail "to" "*" {
set :lower "name" "${1}";
}
if string :is "${name}" "" {
fileinto "INBOX";
stop;
} else {
fileinto "delimiters.${name}";
stop;
}
"""
With best regards,
Tobias
On Sun, 2023-04-09 at 22:21 +0200, Benjamin Stürz wrote:
> Hello Michael,
>
> Thanks for helping me!
>
> I too use dovecot, but I'm not really familiar with it.
> That's why I took most of my config from a tutorial.
>
> As far as I can tell, I have to put something like this into my
> config:
> > protocol lmtp {
> > mail_plugins = $mail_plugins sieve
> > }
> But how do I connect it with my script?
>
> I'm thinking of using a script like this:
> > #!/bin/sh
> >
> > # Usage: $0 user[+tag]@domain.tld
> >
> > # user[+tag]
> > user_tag=$(echo "$1" | cut -d@ -f1)
> >
> > # domain.tld
> > domain=$(echo "$1" | cut -d@ -f2)
> >
> > # user
> > user=$(echo "${user_tag}" | cut -d+ -f1)
> >
> > # [tag]
> > tag=$(echo "${user_tag}" | cut -d+ -f2)
> >
> > prefix="/var/vmail/${domain}/${user}"
> >
> > [ "$tag" ] && echo "${prefix}/${tag}" || echo "${prefix}/Inbox"
>
>
> My current /etc/dovecot/local.conf:
> > auth_mechanisms = plain login
> > first_valid_uid = 2000
> > first_valid_gid = 2000
> > mail_plugin_dir = /usr/local/lib/dovecot
> > managesieve_notify_capability = mailto
> > managesieve_sieve_capability = 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
> > imapsieve vnd.dovecot.imapsieve
> > mbox_write_locks = fcntl
> > mmap_disable = yes
> >
> > passdb {
> > args = scheme=CRYPT username_format=%u
> > /etc/mail/credentials.dovecot
> > driver = passwd-file
> > name =
> > }
> >
> > mail_location =
> > maildir:/var/vmail/%d/%n:INBOX=/var/vmail/%d/%n/Inbox:LAYOUT=fs
> > namespace inbox {
> > inbox = yes
> > mailbox Drafts {
> > auto = subscribe
> > special_use = \Drafts
> > }
> > mailbox Junk {
> > auto = subscribe
> > special_use = \Junk
> > autoexpunge = 30d
> > }
> > mailbox Sent {
> > auto = subscribe
> > special_use = \Sent
> > }
> > mailbox Trash {
> > auto = subscribe
> > special_use = \Trash
> > }
> > mailbox Archive {
> > auto = subscribe
> > special_use = \Archive
> > }
> > }
> >
> > plugin {
> > imapsieve_mailbox1_before =
> > file:/usr/local/lib/dovecot/sieve/report-spam.sieve
> > imapsieve_mailbox1_causes = COPY
> > imapsieve_mailbox1_name = Junk
> > imapsieve_mailbox2_before =
> > file:/usr/local/lib/dovecot/sieve/report-ham.sieve
> > imapsieve_mailbox2_causes = COPY
> > imapsieve_mailbox2_from = Junk
> > imapsieve_mailbox2_name = *
> > sieve = file:~/sieve;active=~/.dovecot.sieve
> > sieve_global_extensions = +vnd.dovecot.pipe
> > +vnd.dovecot.environment
> > sieve_pipe_bin_dir = /usr/local/lib/dovecot/sieve
> > sieve_plugins = sieve_imapsieve sieve_extprograms
> > }
> >
> > protocols = imap sieve
> >
> > service imap-login {
> > inet_listener imap {
> > port = 0
> > }
> > }
> >
> > service managesieve-login {
> > inet_listener sieve {
> > port = 4190
> > }
> >
> > inet_listener sieve_deprecated {
> > port = 2000
> > }
> > }
> >
> > ssl_cert = </etc/ssl/mixdown.me.crt
> > ssl_key = </etc/ssl/private/mixdown.me.key
> >
> > userdb {
> > args = username_format=%u /etc/mail/credentials.dovecot
> > driver = passwd-file
> > name =
> > }
> >
> > protocol imap {
> > mail_plugins = " imap_sieve"
> > }
>
>
> On 09.04.23 22:00, Michael Breuer wrote:
> > Hello Benjamin,
> >
> > what mda do you use? I use dovecot and a sieve script to process
> > incoming mail.
> >
> > Instead of saving mail directly to maildir, I transfer it to the
> > mda via lmtp. The required changes on the smtpd site would look
> > like this:
> >
> > > On 9. Apr 2023, at 16:04, Benjamin Stürz
> > > <[email protected]> wrote:
> > >
> > > I think this line has to be changed:
> > > action "domain_mail" maildir
> > > "/var/vmail/%{dest.domain:lowercase}/%{dest.user:lowercase|strip}
> > > /Inbox" virtual <virtuals>
> >
> > action "domain_mail" lmtp "/var/dovecot/lmtp" virtual <virtuals>
> >
> > In dovecot, you need to activate&configure the sieve plugin and a
> > script for your user account.
> >
> >
>
--
Dr.-Ing. Tobias Fiebig
T +31 616 80 98 99
M [email protected]