[Dovecot] Moving email between folders outside of IMAP context
I'd like to run a script from cron that will scan certain mailboxes and move selected mail from one folder (usually INBOX) to another folder. The basic idea is to move previously detected spam based on headers prepended to the mail. Since I am not able to figure out how to get Postfix to invoke deliver with the -m option in these cases, and not in others, this is one idea I have come up with to deal with it. The big (hopefully obvious) complication seems to be getting the indexes updated. Is there a way to move mail this way AND then have the indexes updated to reflect that move (maybe even if regenerating the entire index all over again)?
-- sHiFt HaPpEnS!
On 21/12/10 22:33, Phil Howard wrote:
I'd like to run a script from cron that will scan certain mailboxes and move selected mail from one folder (usually INBOX) to another folder. The basic idea is to move previously detected spam based on headers prepended to the mail. Since I am not able to figure out how to get Postfix to invoke deliver with the -m option in these cases, and not in others, this is one idea I have come up with to deal with it. The big (hopefully obvious) complication seems to be getting the indexes updated. Is there a way to move mail this way AND then have the indexes updated to reflect that move (maybe even if regenerating the entire index all over again)?
Hi Phil,
Do not use an external script, but add a global sieve script that sorts messages into some directory, based on your preferred header.
-- Regards, Tom
On Tue, Dec 21, 2010 at 16:41, Tom Hendrikx tom@whyscream.net wrote:
Do not use an external script, but add a global sieve script that sorts messages into some directory, based on your preferred header.
How does that get executed. I take it I can't do it via cron. Does it run at deliver time for each mail message? Is it doable in version 1.1.11 (that's what's in my version of Ubuntu)? Do you know which Ubuntu 9.10 package to install (we're stuck on 9.10 until the new server arrives around February).
-- sHiFt HaPpEnS!
On 21/12/10 22:58, Phil Howard wrote:
On Tue, Dec 21, 2010 at 16:41, Tom Hendrikx tom@whyscream.net wrote:
Do not use an external script, but add a global sieve script that sorts messages into some directory, based on your preferred header.
How does that get executed. I take it I can't do it via cron. Does it run at deliver time for each mail message? Is it doable in version 1.1.11 (that's what's in my version of Ubuntu)? Do you know which Ubuntu 9.10 package to install (we're stuck on 9.10 until the new server arrives around February).
Sieve is a plugin of the dovecot delivery agent, and gets executed upon delivery. It does exactly what you want to implement with "deliver -m" in Postfix, which sounds cumbersome indeed. Read http://wiki.dovecot.org/LDA/Sieve/CMU for info.
I am not familiar with Ubuntu specifics, but iirc Stephan Bosch (creator of sieve plugin) has a repo with debian builds of dovecot+sieve.
-- Regards, Tom
On Tue, Dec 21, 2010 at 17:09, Tom Hendrikx tom@whyscream.net wrote:
I am not familiar with Ubuntu specifics, but iirc Stephan Bosch (creator of sieve plugin) has a repo with debian builds of dovecot+sieve.
I would need something that is sieve only, as Dovecot is already installed, configured, and running.
I'm also considering writing a program to be run by Postfix in place of "deliver", which will read the mail to determine how to run "deliver". As long as mail comes in on stdin and is written on stdout, it should be relatively easy (pipe(), fork(), maybe setsid(), execve() in child, read() and write() in parent). But this would take some thorough testing to be sure it is safe.
On 21/12/10 23:18, Phil Howard wrote:
On Tue, Dec 21, 2010 at 17:09, Tom Hendrikx tom@whyscream.net wrote:
I am not familiar with Ubuntu specifics, but iirc Stephan Bosch (creator of sieve plugin) has a repo with debian builds of dovecot+sieve.
I would need something that is sieve only, as Dovecot is already installed, configured, and running.
I'm also considering writing a program to be run by Postfix in place of "deliver", which will read the mail to determine how to run "deliver". As long as mail comes in on stdin and is written on stdout, it should be relatively easy (pipe(), fork(), maybe setsid(), execve() in child, read() and write() in parent). But this would take some thorough testing to be sure it is safe.
That software is already written and tested, it is the sieve plugin. If you're willing to write, test and run a complete new piece of software, you might as well replace dovecot with a sieve enabled version of the same package you're running now, and putting your current configuration in place.
Anyhow, maybe sieve is already available in your current package. I'm not familiar with (contents of) ubuntu packages, so maybe someone more knowledgeable in this area can step up?
-- Regards, Tom
Tom Hendrikx wrote:
Anyhow, maybe sieve is already available in your current package. I'm not familiar with (contents of) ubuntu packages, so maybe someone more knowledgeable in this area can step up?
Found this which lists the files included with Dovecot for Ubuntu 9.10: http://packages.ubuntu.com/karmic/amd64/dovecot-common/filelist
I do see the following files: /usr/lib/dovecot/managesieve /usr/lib/dovecot/managesieve-login /usr/lib/dovecot/sievec /usr/lib/dovecot/sieved
Is that all that would be needed to fix Phil's problem?
On Tue, Dec 21, 2010 at 17:41, Tom Hendrikx tom@whyscream.net wrote:
That software is already written and tested, it is the sieve plugin. If you're willing to write, test and run a complete new piece of software, you might as well replace dovecot with a sieve enabled version of the same package you're running now, and putting your current configuration in place.
I would not be willing to take the risk of uninstalling and re-installing Dovecot or Postfix.
Anyhow, maybe sieve is already available in your current package. I'm not familiar with (contents of) ubuntu packages, so maybe someone more knowledgeable in this area can step up?
Ah ... apparently so. These files exist, so I'll go do reading on CMU sieve.
meitner/root/x0 /root 299# ( dpkg -l | fgrep dovecot | awk '{print $2;}' | while read n ; do dpkg -L ${n} | fgrep -i sieve | prefix "package ${n} has " ; done ) package dovecot-common has /usr/share/doc/dovecot-common/wiki/LDA.Sieve.txt.gz package dovecot-common has /usr/share/doc/dovecot-common/wiki/ManageSieve.txt.gz package dovecot-common has /usr/share/doc/dovecot-common/managesieve.README.gz package dovecot-common has /usr/lib/dovecot/modules/lda/lib90_cmusieve_plugin.so package dovecot-common has /usr/lib/dovecot/modules/lda/lib90_cmusieve_plugin.la package dovecot-common has /usr/lib/dovecot/modules/lda/lib90_cmusieve_plugin.a package dovecot-common has /usr/lib/dovecot/sievec package dovecot-common has /usr/lib/dovecot/sieved package dovecot-common has /usr/lib/dovecot/managesieve package dovecot-common has /usr/lib/dovecot/managesieve-login meitner/root/x0 /root 300#
-- sHiFt HaPpEnS!
participants (3)
-
Phil Howard
-
Tom Hendrikx
-
Willie Gillespie