I have sieve working for incoming messages. I would also love to run sieve for delivered messages that are being moved between mailboxes on the server (for the same account).

For example. I have mail history spanning a decade or two. Many mail clients have troubles with mailboxes of that size. I want to split it into years/months. I know Thunderbird can do that automatically but many other clients can not. Specifically, I'm not aware of any iOS mail client that can do that. Anyway, I'd like to move any message that enters Archives mailbox to be further filtered into Arthives// mailbox.

I use Dovecot 2 as my IMAP server. How can I do that?

  • @anx As far as I can tell it has to be ran manually. I was looking for a way to run sieve on each message entering my Archive mailbox to further divert it to, say, Archive/<year>/<month> mailbox. – Pointless One Jun 24 '19 at 13:08

Triggering actions on IMAP commands is one of the main applications of the IMAPSieve extension, as proposed in RFC6785 and implemented in Dovecot 2.2.24+. What you have to do is roughly this:

  1. add imap_sieve to your dovecot mail_plugins
  2. add sieve_imapsieve to your dovecot sieve_plugins
  3. add your filter to imapsieve_mailbox1_before and filter IMAP actions in imapsieve_mailbox1_causes (COPY)
  4. add a filter by mailbox, so you only redirect messages from specific folders (my guess: all folders which have per-date-range subfolders)
  5. use fileinto in your IMAP-triggered script to move the message to a different folder than the one the user moved/copied to

Special cases / additional consideration required:

  • is the archive folder splitting logic shared between incoming mails and manually moved mails? it IS possible to share the script, but doing so might not be worth the additional script complexity
  • I know about this feature. I use it for spam training. However, there's a complication. It seem this is applicable to all users on the server. Is it possible to scope it only to some users? Preferably by opt-in from the users themselves. – Pointless One Jun 25 '19 at 20:08
  • @PointlessOne You can accomplish 4. with mailboxexists. Any user that creates a folder like Archive/2019-05 (unfortunately, I did no figure out how to use :regex there) opts in to have all his new messages in Archive moved into automatically created folders of that scheme. – anx Jun 25 '19 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.