]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/sieve/serv_sieve.c
libical, expat, and libsieve are now *required*.
[citadel.git] / citadel / modules / sieve / serv_sieve.c
index 226b4825562344c30a3fcd988e10f01d8c7c669a..726d58d504fafd552fbee56178e427a91782993e 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
-#include "tools.h"
-
-
 #include "ctdl_module.h"
-
-
-#ifdef HAVE_LIBSIEVE
-
 #include "serv_sieve.h"
 
 struct RoomProcList *sieve_list = NULL;
@@ -104,7 +98,7 @@ int ctdl_redirect(sieve2_context_t *s, void *my)
 
        lprintf(CTDL_DEBUG, "Action is REDIRECT, recipient <%s>\n", recp);
 
-       valid = validate_recipients(recp);
+       valid = validate_recipients(recp, NULL, 0);
        if (valid == NULL) {
                lprintf(CTDL_WARNING, "REDIRECT failed: bad recipient <%s>\n", recp);
                return SIEVE2_ERROR_BADARGS;
@@ -386,7 +380,8 @@ int ctdl_getenvelope(sieve2_context_t *s, void *my)
 {
        struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
 
-       lprintf(CTDL_DEBUG, "Action is GETENVELOPE\n");
+       lprintf(CTDL_DEBUG, "Action is GETENVELOPE\nEnvFrom: %s\n  EnvTo: %s\n",
+               cs->envelope_from, cs->envelope_to);
 
        if (cs->envelope_from != NULL) {
                if ((cs->envelope_from[0] != '@')&&(cs->envelope_from[strlen(cs->envelope_from)-1] != '@')) {
@@ -505,7 +500,7 @@ void sieve_queue_room(struct ctdlroom *which_room) {
  */
 void sieve_do_msg(long msgnum, void *userdata) {
        struct sdm_userdata *u = (struct sdm_userdata *) userdata;
-       sieve2_context_t *sieve2_context = u->sieve2_context;
+       sieve2_context_t *sieve2_context;
        struct ctdl_sieve my;
        int res;
        struct CtdlMessage *msg;
@@ -513,6 +508,14 @@ void sieve_do_msg(long msgnum, void *userdata) {
        size_t headers_len = 0;
        int len = 0;
 
+       if (userdata == NULL)
+       {
+               lprintf(CTDL_EMERG, "Cant process Message <%ld>without Userdata!\n", msgnum);
+               return;
+       }
+
+       sieve2_context = u->sieve2_context;
+
        lprintf(CTDL_DEBUG, "Performing sieve processing on msg <%ld>\n", msgnum);
 
        msg = CtdlFetchMessage(msgnum, 0);
@@ -576,9 +579,11 @@ void sieve_do_msg(long msgnum, void *userdata) {
        /* Keep track of the envelope-from address (use body-from if not found) */
        if (msg->cm_fields['P'] != NULL) {
                safestrncpy(my.envelope_from, msg->cm_fields['P'], sizeof my.envelope_from);
+               stripallbut(my.envelope_from, '<', '>');
        }
        else if (msg->cm_fields['F'] != NULL) {
                safestrncpy(my.envelope_from, msg->cm_fields['F'], sizeof my.envelope_from);
+               stripallbut(my.envelope_from, '<', '>');
        }
        else {
                strcpy(my.envelope_from, "");
@@ -596,6 +601,7 @@ void sieve_do_msg(long msgnum, void *userdata) {
        /* Keep track of the envelope-to address (use body-to if not found) */
        if (msg->cm_fields['V'] != NULL) {
                safestrncpy(my.envelope_to, msg->cm_fields['V'], sizeof my.envelope_to);
+               stripallbut(my.envelope_to, '<', '>');
        }
        else if (msg->cm_fields['R'] != NULL) {
                safestrncpy(my.envelope_to, msg->cm_fields['R'], sizeof my.envelope_to);
@@ -603,6 +609,7 @@ void sieve_do_msg(long msgnum, void *userdata) {
                        strcat(my.envelope_to, "@");
                        strcat(my.envelope_to, msg->cm_fields['D']);
                }
+               stripallbut(my.envelope_to, '<', '>');
        }
        else {
                strcpy(my.envelope_to, "");
@@ -1277,26 +1284,17 @@ int serv_sieve_room(struct ctdlroom *room)
        return 0;
 }
 
-#endif /* HAVE_LIBSIEVE */
-
 CTDL_MODULE_INIT(sieve)
 {
+       if (!threading)
+       {
 
-#ifdef HAVE_LIBSIEVE
-
-       ctdl_sieve_init();
-       CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
-
-        CtdlRegisterRoomHook(serv_sieve_room);
-
-        CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE);
-
-#else  /* HAVE_LIBSIEVE */
-
-       lprintf(CTDL_INFO, "This server is missing libsieve.  Mailbox filtering will be disabled.\n");
-
-#endif /* HAVE_LIBSIEVE */
-
+               ctdl_sieve_init();
+               CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
+               CtdlRegisterRoomHook(serv_sieve_room);
+               CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE);
+       }
+       
         /* return our Subversion id for the Log */
        return "$Id$";
 }