0

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?

  • The sieve-filter is neither particularly fast nor without limitations, but it can absolutely re-filter already received mails. READ THE MANUAL before running it on production, you can easily duplicate/delete your mail. – anx Jun 22 at 21:28
  • @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 at 13:08
  • I suspect you will need both: 1) Split up older folders as a one-time-job, this is what sieve-filter does 2) Ensure that newly arriving (or copied/moved there) mail is split up into subfolders. – anx Jun 24 at 16:54
1

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:

  • IMAP APPEND
  • 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 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 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.