]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/sieve/serv_sieve.c
Merge branch 'configdb' of ssh://git.citadel.org/appl/gitroot/citadel
[citadel.git] / citadel / modules / sieve / serv_sieve.c
index abce872ce89660de12afaf7d4962db47d354140a..94d8a5fa34a0738a7374df3e718a3088c1e5dfa9 100644 (file)
@@ -2,7 +2,7 @@
  * This module glues libSieve to the Citadel server in order to implement
  * the Sieve mailbox filtering language (RFC 3028).
  *
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2015 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 3.
@@ -106,7 +106,7 @@ int ctdl_redirect(sieve2_context_t *s, void *my)
 {
        struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
        struct CtdlMessage *msg = NULL;
-       struct recptypes *valid = NULL;
+       recptypes *valid = NULL;
        char recp[256];
 
        safestrncpy(recp, sieve2_getvalue_string(s, "address"), sizeof recp);
@@ -124,7 +124,7 @@ int ctdl_redirect(sieve2_context_t *s, void *my)
                return SIEVE2_ERROR_BADARGS;
        }
 
-       msg = CtdlFetchMessage(cs->msgnum, 1);
+       msg = CtdlFetchMessage(cs->msgnum, 1, 1);
        if (msg == NULL) {
                SV_syslog(LOG_WARNING, "REDIRECT failed: unable to fetch msg %ld", cs->msgnum);
                free_recipients(valid);
@@ -134,7 +134,7 @@ int ctdl_redirect(sieve2_context_t *s, void *my)
        CtdlSubmitMsg(msg, valid, NULL, 0);
        cs->cancel_implicit_keep = 1;
        free_recipients(valid);
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
        return SIEVE2_OK;
 }
 
@@ -193,13 +193,13 @@ int ctdl_fileinto(sieve2_context_t *s, void *my)
        }
 
        /* Yes, we actually have to go there */
-       CtdlUserGoto(NULL, 0, 0, NULL, NULL);
+       CtdlUserGoto(NULL, 0, 0, NULL, NULL, NULL, NULL);
 
        c = CtdlSaveMsgPointersInRoom(NULL, &cs->msgnum, 1, 0, NULL, 0);
 
        /* Go back to the room we came from */
        if (strcasecmp(original_room_name, CC->room.QRname)) {
-               CtdlUserGoto(original_room_name, 0, 0, NULL, NULL);
+               CtdlUserGoto(original_room_name, 0, 0, NULL, NULL, NULL, NULL);
        }
 
        if (c == 0) {
@@ -553,7 +553,7 @@ void sieve_do_msg(long msgnum, void *userdata) {
        /*
         * Make sure you include message body so you can get those second-level headers ;)
         */
-       msg = CtdlFetchMessage(msgnum, 1);
+       msg = CtdlFetchMessage(msgnum, 1, 1);
        if (msg == NULL) return;
 
        /*
@@ -583,37 +583,37 @@ void sieve_do_msg(long msgnum, void *userdata) {
        my.u = u;                               /* Hand off a pointer to the rest of this info */
 
        /* Keep track of the recipient so we can do handling based on it later */
-       process_rfc822_addr(msg->cm_fields['R'], my.recp_user, my.recp_node, my.recp_name);
+       process_rfc822_addr(msg->cm_fields[eRecipient], my.recp_user, my.recp_node, my.recp_name);
 
        /* Keep track of the sender so we can use it for REJECT and VACATION responses */
-       if (msg->cm_fields['F'] != NULL) {
-               safestrncpy(my.sender, msg->cm_fields['F'], sizeof my.sender);
+       if (!CM_IsEmpty(msg, erFc822Addr)) {
+               safestrncpy(my.sender, msg->cm_fields[erFc822Addr], sizeof my.sender);
        }
-       else if ( (msg->cm_fields['A'] != NULL) && (msg->cm_fields['N'] != NULL) ) {
-               snprintf(my.sender, sizeof my.sender, "%s@%s", msg->cm_fields['A'], msg->cm_fields['N']);
+       else if ( (!CM_IsEmpty(msg, eAuthor)) && (!CM_IsEmpty(msg, eNodeName)) ) {
+               snprintf(my.sender, sizeof my.sender, "%s@%s", msg->cm_fields[eAuthor], msg->cm_fields[eNodeName]);
        }
-       else if (msg->cm_fields['A'] != NULL) {
-               safestrncpy(my.sender, msg->cm_fields['A'], sizeof my.sender);
+       else if (!CM_IsEmpty(msg, eAuthor)) {
+               safestrncpy(my.sender, msg->cm_fields[eAuthor], sizeof my.sender);
        }
        else {
                strcpy(my.sender, "");
        }
 
        /* Keep track of the subject so we can use it for VACATION responses */
-       if (msg->cm_fields['U'] != NULL) {
-               safestrncpy(my.subject, msg->cm_fields['U'], sizeof my.subject);
+       if (!CM_IsEmpty(msg, eMsgSubject)) {
+               safestrncpy(my.subject, msg->cm_fields[eMsgSubject], sizeof my.subject);
        }
        else {
                strcpy(my.subject, "");
        }
 
        /* 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);
+       if (!CM_IsEmpty(msg, eMessagePath)) {
+               safestrncpy(my.envelope_from, msg->cm_fields[eMessagePath], 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);
+       else if (!CM_IsEmpty(msg, erFc822Addr)) {
+               safestrncpy(my.envelope_from, msg->cm_fields[erFc822Addr], sizeof my.envelope_from);
                stripallbut(my.envelope_from, '<', '>');
        }
        else {
@@ -626,19 +626,19 @@ void sieve_do_msg(long msgnum, void *userdata) {
        }
        if (haschar(my.envelope_from, '@') == 0) {
                strcat(my.envelope_from, "@");
-               strcat(my.envelope_from, config.c_fqdn);
+               strcat(my.envelope_from, CtdlGetConfigStr("c_fqdn"));
        }
 
        /* 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);
+       if (!CM_IsEmpty(msg, eenVelopeTo)) {
+               safestrncpy(my.envelope_to, msg->cm_fields[eenVelopeTo], 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);
-               if (msg->cm_fields['D'] != NULL) {
+       else if (!CM_IsEmpty(msg, eRecipient)) {
+               safestrncpy(my.envelope_to, msg->cm_fields[eRecipient], sizeof my.envelope_to);
+               if (!CM_IsEmpty(msg, eDestination)) {
                        strcat(my.envelope_to, "@");
-                       strcat(my.envelope_to, msg->cm_fields['D']);
+                       strcat(my.envelope_to, msg->cm_fields[eDestination]);
                }
                stripallbut(my.envelope_to, '<', '>');
        }
@@ -652,10 +652,10 @@ void sieve_do_msg(long msgnum, void *userdata) {
        }
        if (haschar(my.envelope_to, '@') == 0) {
                strcat(my.envelope_to, "@");
-               strcat(my.envelope_to, config.c_fqdn);
+               strcat(my.envelope_to, CtdlGetConfigStr("c_fqdn"));
        }
 
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
        
        SVM_syslog(LOG_DEBUG, "Calling sieve2_execute()");
        res = sieve2_execute(sieve2_context, &my);
@@ -746,17 +746,18 @@ void get_sieve_config_backend(long msgnum, void *userdata) {
        struct sdm_userdata *u = (struct sdm_userdata *) userdata;
        struct CtdlMessage *msg;
        char *conf;
+       long conflen;
 
        u->config_msgnum = msgnum;
-       msg = CtdlFetchMessage(msgnum, 1);
+       msg = CtdlFetchMessage(msgnum, 1, 1);
        if (msg == NULL) {
                u->config_msgnum = (-1) ;
                return;
        }
 
-       conf = msg->cm_fields['M'];
-       msg->cm_fields['M'] = NULL;
-       CtdlFreeMessage(msg);
+       CM_GetAsField(msg, eMesageText, &conf, &conflen);
+
+       CM_Free(msg);
 
        if (conf != NULL) {
                parse_sieve_config(conf, u);
@@ -1184,7 +1185,7 @@ void cmd_msiv(char *argbuf) {
                extract_token(script_name, argbuf, 1, '|', sizeof script_name);
                if (!IsEmptyStr(script_name)) {
                        cprintf("%d Transmit script now\n", SEND_LISTING);
-                       script_content = CtdlReadMessageBody(HKEY("000"), config.c_maxmsglen, NULL, 0, 0);
+                       script_content = CtdlReadMessageBody(HKEY("000"), CtdlGetConfigLong("c_maxmsglen"), NULL, 0, 0);
                        msiv_putscript(&u, script_name, script_content);
                        changes_made = 1;
                }