Create date-based folders with sieve

dovecotsieve

I'd like to archive messages by year, perhaps month.
I can create a new rule each month, but I'd rather do it automatically.

Move all messages to a folder called ARCHIVE/%y/%m or something like it.

I'd prefer to use the webinterface to sieve provided by roundcube, but I can access the server if needed.

Best Answer

I don't expect you can do this through Roundcube's web interface, but here's a solution for manually writing Sieve scripts. Moving into date-based folders is possible by combining several sieve extensions: fileinto, date and mailbox.

require ["fileinto", "date", "mailbox"]

Put the current date into variables:

if currentdate :matches "year" "*" { set "year" "${1}"; }
if currentdate :matches "month" "*" { set "month" "${1}"; }

And to file the message, run:

fileinto :create "Archive.${year}.${month}"

Depending on your IMAP path settings, you might require / instead of .. :create enables creation of folders if they do not exist yet.