Can sieve-script run when saving mail in Sent folder?
Hi everyone,
Would it be possible to run a sieve-script when the mail-client sends a mail (no because smtp) on the action where the mail-client stores a copy in the Sent folder over imap?
I was expecting through imapsieve_mailboxXXX_* but can find a combination of parameters are correct. Does anybody have this working? and how?
- Kees
On 11-17-2021 5:43 pm, Kees van Vloten wrote:
Would it be possible to run a sieve-script when the mail-client sends a mail (no because smtp) on the action where the mail-client stores a copy in the Sent folder over imap?
That would be nice, to auto sort mail into different sent folders like work vs personal. However i do not think it is possible as https://doc.dovecot.org/configuration_manual/sieve/troubleshooting/ says...
" Sieve scripts are executed by the Dovecot LDA (Local Delivery Agent) and/or the Dovecot LMTP service. That is why you first need to check whether LDA or LMTP are actually being used. At least one of these is supposed to be called/accessed from your MTA, e.g. Exim or Postfix, for local message delivery. "
On 18-11-2021 01:01, Gedalya wrote:
On 11/18/21 06:43, Kees van Vloten wrote:
I was expecting through imapsieve_mailboxXXX_* but can find a combination of parameters are correct. Does anybody have this working? and how?
plugin {
sieve_plugins = sieve_imapsieve
imapsieve_mailbox1_name = Sent imapsieve_mailbox1_causes = APPEND COPY imapsieve_mailbox1_before = file:~/sieve/IMAP-Sent.sieve
}
protocol imap { mail_plugins = $mail_plugins imap_sieve }
This works fine. What exactly is your issue?
I use Thunderbird 78.14.0 (on Debian Bullseye) as the mail-client to test with. After sending a message the copy is stored in Sent but not moved to Sent/example.com.
There is no trace in the logs that it did try to run the sieve-script (can I enable specific debug logging for this?)
I ran the script manually with sieve-filter (after removing requirements "copy" and "imapsieve") it worked properly and moved the messages.
vmail@server:~$ ls -l /var/lib/dovecot/sieve/imap/sent_mail_per_domain.sieve -rw------- 1 vmail vmail 140 Nov 17 21:00 /var/lib/dovecot/sieve/imap/sent_mail_per_domain.sieve
vmail@server:~$ cat /var/lib/dovecot/sieve/imap/sent_mail_per_domain.sieve require ["fileinto", "variables", "mailbox", "copy", "imapsieve"];
if header :matches "From" "*@*>?" { fileinto :create "Sent~${2}"; }
Note that tilde (~) is the defined separator in "namespace inbox".
dovecot -n
# 2.3.13 (89f716dc2): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.5.13 (cdd19fe3)
# OS: Linux 5.10.0-9-amd64 x86_64 Debian 11.1
# Hostname: server.example.com
auth_default_realm = EXAMPLE.COM
auth_gssapi_hostname = server.example.com
auth_krb5_keytab = /etc/keytab/dovecot.keytab
auth_master_user_separator = *
auth_mechanisms = gssapi gss-spnego plain
auth_realms = EXAMPLE.COM
disable_plaintext_auth = no
first_valid_gid = 986
first_valid_uid = 990
imap_client_workarounds = tb-extra-mailbox-sep
login_greeting = Dovecot ready.
mail_debug = yes
mail_gid = 986
mail_location =
maildir:%h/%d/%n/store:LAYOUT=fs:FULLDIRNAME=0_FolderContent:UTF-8:INDEX=%h/%d/%n/index:CONTROL=%h/%d/%n/control:VOLATILEDIR=%h/%d/%n/volatile
mail_plugins = zlib notify push_notification listescape acl fts fts_xapian
mail_shared_explicit_inbox = yes
mail_uid = 990
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 vacation-seconds spamtest imapflags notify imapsieve
vnd.dovecot.imapsieve
namespace inbox {
inbox = yes
list = yes
location =
mailbox Drafts {
auto = subscribe
special_use = \Drafts
}
mailbox Inbox {
auto = subscribe
}
mailbox Junk {
auto = subscribe
special_use = \Junk
}
mailbox Sent {
auto = subscribe
special_use = \Sent
}
mailbox Trash {
auto = subscribe
special_use = \Trash
}
prefix =
separator = ~
subscriptions = yes
type = private
}
passdb {
args = username_format=%u /etc/dovecot/master-users
driver = passwd-file
master = yes
}
passdb {
args = /etc/dovecot/ldap_user_to_principal.conf.ext
driver = ldap
pass = yes
}
passdb {
driver = pam
}
plugin {
acl = vfile:/var/lib/dovecot/global-acls:cache_secs=1
acl_shared_dict = file:/var/lib/dovecot/shared-mailboxes
autocreate = Trash
autocreate2 = Drafts
autocreate3 = Sent
autosubscribe = Trash
autosubscribe2 = Drafts
autosubscribe3 = Sent
fts = xapian
fts_autoindex = yes
fts_autoindex_exclude = \Trash
fts_decoder = decode2text
fts_enforced = yes
fts_xapian = partial=3 full=20
imapsieve_mailbox1_before =
file:/var/lib/dovecot/sieve/imap/learn-spam.sieve
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_name = Junk
imapsieve_mailbox2_before =
file:/var/lib/dovecot/sieve/imap/learn-ham.sieve
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_from = Junk
imapsieve_mailbox2_name = *
imapsieve_mailbox3_before =
file:/var/lib/dovecot/sieve/imap/sent_mail_per_domain.sieve
imapsieve_mailbox3_causes = APPEND COPY
imapsieve_mailbox3_name = Sent
listescape_char =
sieve = file:%h/%d/%n/sieve/sieve;active=%h/%d/%n/sieve/active.sieve
sieve_after = /var/lib/dovecot/sieve/after
sieve_before = /var/lib/dovecot/sieve/before
sieve_default = /var/lib/dovecot/sieve/default.sieve
sieve_extensions = +vacation-seconds +reject +notify +imapflags +spamtest
sieve_global = /var/lib/dovecot/sieve/global_include
sieve_global_extensions = +vnd.dovecot.pipe
sieve_pipe_bin_dir = /var/lib/dovecot/sieve/bin
sieve_plugins = sieve_imapsieve sieve_extprograms
sieve_vacation_default_period = 1d
sieve_vacation_max_period = 1d
sieve_vacation_min_period = 10s
sieve_vacation_use_original_recipient = yes
}
postmaster_address = sysadmin@example.com
protocols = " imap lmtp sieve submission"
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
}
service decode2text {
executable = script /usr/local/sbin/decode2text.sh
unix_listener decode2text {
mode = 0666
}
user = dovecot
}
service imap-login {
inet_listener imap {
port = 0
}
inet_listener imaps {
port = 993
ssl = yes
}
process_min_avail = 1
}
service imap-postlogin {
executable = script-login -d rawlog
}
service imap {
executable = imap
}
service indexer-worker {
vsz_limit = 2 G
}
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
group = postfix
mode = 0600
user = postfix
}
}
service submission-login {
inet_listener submission {
port = 465
ssl = yes
}
}
ssl = required
ssl_cert =
On 11/18/21 19:25, Kees van Vloten wrote:
There is no trace in the logs that it did try to run the sieve-script (can I enable specific debug logging for this?)
metric sieve { filter = category=sieve exporter = log } event_exporter log { format = json format_args = time-rfc3339 transport = log }
Lines from syslog, formatted with jq and redacted:
(the last event is not emitted if the condition was not met and no action is taken)
{ "event": "sieve_runtime_script_started", "hostname": "mail", "start_time": "2021-11-19T03:34:29.422841Z", "end_time": "2021-11-19T03:34:29.422867Z", "categories": [ "service:imap", "sieve-execute", "sieve", "imap", "sieve-runtime" ], "fields": { "user": "gedalya@gedalya.net", "local_ip": "x.x.x.x", "local_port": 143, "remote_ip": "x.x.x.x", "remote_port": 10460, "session": "DVTs6BvR3CjAqAkK", "duration": 13, "message_id": "xxxxxxxxx@xxx.gedalya.net", "mail_from": "", "rcpt_to": "", "script_name": "imap-sent", "script_location": "/usr/local/lib/imapsieve/imap-sent.sieve", "binary_path": "/usr/local/lib/imapsieve/imap-sent.svbin" } }
{ "event": "sieve_runtime_script_finished", "hostname": "mail", "start_time": "2021-11-19T03:34:29.422841Z", "end_time": "2021-11-19T03:34:29.423052Z", "categories": [ "service:imap", "sieve-execute", "sieve", "imap", "sieve-runtime" ], "fields": { "user": "gedalya@gedalya.net", "local_ip": "x.x.x.x", "local_port": 143, "remote_ip": "x.x.x.x", "remote_port": 10460, "session": "DVTs6BvR3CjAqAkK", "duration": 197, "message_id": "xxxxxxxxx@xxx.gedalya.net", "mail_from": "", "rcpt_to": "", "script_name": "imap-sent", "script_location": "/usr/local/lib/imapsieve/imap-sent.sieve", "binary_path": "/usr/local/lib/imapsieve/imap-sent.svbin" } }
{ "event": "sieve_action_finished", "hostname": "mail", "start_time": "2021-11-19T03:34:29.423031Z", "end_time": "2021-11-19T03:34:29.426343Z", "categories": [ "service:imap", "sieve-execute", "sieve", "imap", "sieve-action" ], "fields": { "user": "gedalya@gedalya.net", "local_ip": "x.x.x.x", "local_port": 143, "remote_ip": "x.x.x.x", "remote_port": 10460, "session": "DVTs6BvR3CjAqAkK", "duration": 3297, "fileinto_mailbox_name": "INBOX/test", "fileinto_mailbox": "'INBOX/test'", "message_id": "xxxxxxxxx@xxx.gedalya.net", "mail_from": "", "rcpt_to": "", "action_name": "fileinto", "script_location": "imap-sent: line 4" } }
participants (3)
-
dovecot@ptld.com
-
Gedalya
-
Kees van Vloten