Hi.  I need to make SpamAssassin-tagged messages to be by default
 filtered into a spam-folder.  I figured I could do this either by
 a global sieve script, or some default script that was copied in place
 whenever a new user mailbox was created.

  I couldn't find a way to do either, so here's a patch that does the
 makes sieve_find_script() check to see if the script it finds actually
 exist, and if not, falls back on "defaultbc" directly in the sieve dir.
 Works for me, at least - perhaps someone else will find it useful.

  Perhaps this patch (or another which achieves the same thing) be added
 to the Cyrus sources in a future version?  (hint, hint. :-)

Kind regards,
-- 
Tore Anderson
diff -ruN cyrus-imapd-2.2.5/imap/lmtp_sieve.c cyrus-imapd-2.2.5-globalsieve/imap/lmtp_sieve.c
--- cyrus-imapd-2.2.5/imap/lmtp_sieve.c	2004-05-22 05:45:51.000000000 +0200
+++ cyrus-imapd-2.2.5-globalsieve/imap/lmtp_sieve.c	2004-06-18 15:41:56.000000000 +0200
@@ -55,6 +55,7 @@
 #include <time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/stat.h>
 
 #include "append.h"
 #include "auth.h"
@@ -806,6 +807,7 @@
 	/* check ~USERNAME/.sieve */
 	snprintf(fname, size, "%s/%s", pent->pw_dir, ".sieve");
     } else { /* look in sieve_dir */
+	struct stat sbuf;
 	char hash = (char) dir_hash_c(user);
 
 	if (domain) {
@@ -815,6 +817,12 @@
 	} else {
 	    snprintf(fname, size, "%s/%c/%s/defaultbc", sieve_dir, hash, user);
 	}
+	/* does this file exist at all?  if not, fall back on a global one */
+	if (stat(fname, &sbuf) == -1) {
+	    syslog(LOG_DEBUG, "IOERROR: fstating sieve script %s (falling"
+			      "back on system wide default): %m", fname);
+	snprintf(fname, size, "%s/defaultbc", sieve_dir);
+	}
     }
 	
     return 0;

Reply via email to