Citadel API clean up.
[citadel.git] / citadel / modules / sieve / serv_sieve.c
index 473a8dcf9cc7e8860f54f48b548cb3db46473298..960393d96dfcde2065b05959f794f63284996ec3 100644 (file)
@@ -4,7 +4,21 @@
  * This module glues libSieve to the Citadel server in order to implement
  * the Sieve mailbox filtering language (RFC 3028).
  *
- * This code is released under the terms of the GNU General Public License. 
+ * Copyright (c) 2007-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "sysdep.h"
@@ -37,7 +51,6 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
@@ -164,12 +177,12 @@ int ctdl_fileinto(sieve2_context_t *s, void *my)
 
        /* First try a mailbox name match (check personal mail folders first) */
        snprintf(foldername, sizeof foldername, "%010ld.%s", cs->usernum, dest_folder);
-       c = getroom(&CC->room, foldername);
+       c = CtdlGetRoom(&CC->room, foldername);
 
        /* Then a regular room name match (public and private rooms) */
        if (c != 0) {
                safestrncpy(foldername, dest_folder, sizeof foldername);
-               c = getroom(&CC->room, foldername);
+               c = CtdlGetRoom(&CC->room, foldername);
        }
 
        if (c != 0) {
@@ -178,13 +191,13 @@ int ctdl_fileinto(sieve2_context_t *s, void *my)
        }
 
        /* Yes, we actually have to go there */
-       usergoto(NULL, 0, 0, NULL, NULL);
+       CtdlUserGoto(NULL, 0, 0, NULL, NULL);
 
        c = CtdlSaveMsgPointersInRoom(NULL, &cs->msgnum, 1, 0, NULL);
 
        /* Go back to the room we came from */
        if (strcasecmp(original_room_name, CC->room.QRname)) {
-               usergoto(original_room_name, 0, 0, NULL, NULL);
+               CtdlUserGoto(original_room_name, 0, 0, NULL, NULL);
        }
 
        if (c == 0) {
@@ -518,7 +531,10 @@ void sieve_do_msg(long msgnum, void *userdata) {
 
        CtdlLogPrintf(CTDL_DEBUG, "Performing sieve processing on msg <%ld>\n", msgnum);
 
-       msg = CtdlFetchMessage(msgnum, 0);
+       /*
+        * Make sure you include message body so you can get those second-level headers ;)
+        */
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
 
        /*
@@ -535,12 +551,6 @@ void sieve_do_msg(long msgnum, void *userdata) {
        CC->redirect_len = 0;
        CC->redirect_alloc = 0;
 
-       if (u == NULL)
-       {
-               CtdlLogPrintf(CTDL_EMERG, "userdata got clobbz0red!  aaaaaaaaghhh!!!!\n");
-               abort();
-       }
-
        /*
         * libSieve clobbers the stack if it encounters badly formed
         * headers.  Sanitize our headers by stripping nonprintable
@@ -633,35 +643,14 @@ void sieve_do_msg(long msgnum, void *userdata) {
 
        CtdlFreeMessage(msg);
 
-       if (u == NULL)
-       {
-               CtdlLogPrintf(CTDL_EMERG, "userdata got clobbz0red!  aaaaaaaaghhh!!!!\n");
-               abort();
-       }
-
-
-       CtdlLogPrintf(CTDL_DEBUG, "HEADERS-------\n\e[31m%s\e[0m\n", my.rfc822headers);
-
        sieve2_setvalue_string(sieve2_context, "allheaders", my.rfc822headers);
        
-       if (u == NULL)
-       {
-               CtdlLogPrintf(CTDL_EMERG, "userdata got clobbz0red!  aaaaaaaaghhh!!!!\n");
-               abort();
-       }
-
        CtdlLogPrintf(CTDL_DEBUG, "Calling sieve2_execute()\n");
        res = sieve2_execute(sieve2_context, &my);
        if (res != SIEVE2_OK) {
                CtdlLogPrintf(CTDL_CRIT, "sieve2_execute() returned %d: %s\n", res, sieve2_errstr(res));
        }
 
-       if (u == NULL)
-       {
-               CtdlLogPrintf(CTDL_EMERG, "userdata got clobbz0red!  aaaaaaaaghhh!!!!\n");
-               abort();
-       }
-
        free(my.rfc822headers);
        my.rfc822headers = NULL;
 
@@ -674,12 +663,6 @@ void sieve_do_msg(long msgnum, void *userdata) {
                CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "");
        }
 
-       if (u == NULL)
-       {
-               CtdlLogPrintf(CTDL_EMERG, "userdata got clobbz0red!  aaaaaaaaghhh!!!!\n");
-               abort();
-       }
-
        CtdlLogPrintf(CTDL_DEBUG, "Completed sieve processing on msg <%ld>\n", msgnum);
        u->lastproc = msgnum;
 
@@ -899,7 +882,7 @@ void sieve_do_room(char *roomname) {
         * require execution.
         */
        snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), USERCONFIGROOM);
-       if (getroom(&CC->room, u.config_roomname) != 0) {
+       if (CtdlGetRoom(&CC->room, u.config_roomname) != 0) {
                CtdlLogPrintf(CTDL_DEBUG, "<%s> does not exist.  No processing is required.\n", u.config_roomname);
                return;
        }
@@ -918,7 +901,7 @@ void sieve_do_room(char *roomname) {
 
        CtdlLogPrintf(CTDL_DEBUG, "Rules found.  Performing Sieve processing for <%s>\n", roomname);
 
-       if (getroom(&CC->room, roomname) != 0) {
+       if (CtdlGetRoom(&CC->room, roomname) != 0) {
                CtdlLogPrintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", roomname);
                return;
        }
@@ -1007,7 +990,7 @@ void msiv_load(struct sdm_userdata *u) {
        strcpy(hold_rm, CC->room.QRname);       /* save current room */
 
        /* Take a spin through the user's personal address book */
-       if (getroom(&CC->room, USERCONFIGROOM) == 0) {
+       if (CtdlGetRoom(&CC->room, USERCONFIGROOM) == 0) {
        
                u->config_msgnum = (-1);
                strcpy(u->config_roomname, CC->room.QRname);
@@ -1017,7 +1000,7 @@ void msiv_load(struct sdm_userdata *u) {
        }
 
        if (strcmp(CC->room.QRname, hold_rm)) {
-               getroom(&CC->room, hold_rm);    /* return to saved room */
+               CtdlGetRoom(&CC->room, hold_rm);    /* return to saved room */
        }
 }