]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_sieve.c
Remove the SieveRules room. Keep sieve config in My Citadel Config
[citadel.git] / citadel / serv_sieve.c
index d478c4af7ffecaaafdc1f1a43e83a2709649c2e2..5a80cba1918351ceff4848187446c76b811df008 100644 (file)
@@ -290,12 +290,20 @@ int ctdl_vacation(sieve2_context_t *s, void *my)
        int days = 1;
        const char *message;
        char *vacamsg_text = NULL;
+       char vacamsg_subject[1024];
 
        lprintf(CTDL_DEBUG, "Action is VACATION\n");
 
        message = sieve2_getvalue_string(s, "message");
        if (message == NULL) return SIEVE2_ERROR_BADARGS;
 
+       if (sieve2_getvalue_string(s, "subject") != NULL) {
+               safestrncpy(vacamsg_subject, sieve2_getvalue_string(s, "subject"), sizeof vacamsg_subject);
+       }
+       else {
+               snprintf(vacamsg_subject, sizeof vacamsg_subject, "Re: %s", cs->subject);
+       }
+
        days = sieve2_getvalue_int(s, "days");
        if (days < 1) days = 1;
        if (days > MAX_VACATION) days = MAX_VACATION;
@@ -331,7 +339,7 @@ int ctdl_vacation(sieve2_context_t *s, void *my)
                NULL,
                vacamsg_text,
                FMT_RFC822,
-               "Delivery status notification"
+               vacamsg_subject
        );
 
        free(vacamsg_text);
@@ -587,7 +595,7 @@ void sieve_do_msg(long msgnum, void *userdata) {
  */
 void parse_sieve_config(char *conf, struct sdm_userdata *u) {
        char *ptr;
-       char *c;
+       char *c, *vacrec;
        char keyword[256];
        struct sdm_script *sptr;
        struct sdm_vacation *vptr;
@@ -616,11 +624,20 @@ void parse_sieve_config(char *conf, struct sdm_userdata *u) {
                }
 
                else if (!strcasecmp(keyword, "vacation")) {
-                       vptr = malloc(sizeof(struct sdm_vacation));
-                       vptr->timestamp = extract_long(c, 1);
-                       extract_token(vptr->fromaddr, c, 2, '|', sizeof vptr->fromaddr);
-                       vptr->next = u->first_vacation;
-                       u->first_vacation = vptr;
+
+                       if (c != NULL) while (vacrec=c, c=strchr(c, '\n'), (c != NULL)) {
+
+                               *c = 0;
+                               ++c;
+
+                               if (strncasecmp(vacrec, "vacation|", 9)) {
+                                       vptr = malloc(sizeof(struct sdm_vacation));
+                                       extract_token(vptr->fromaddr, vacrec, 0, '|', sizeof vptr->fromaddr);
+                                       vptr->timestamp = extract_long(vacrec, 1);
+                                       vptr->next = u->first_vacation;
+                                       u->first_vacation = vptr;
+                               }
+                       }
                }
 
                /* ignore unknown keywords */
@@ -688,17 +705,27 @@ void rewrite_ctdl_sieve_config(struct sdm_userdata *u) {
                free(sptr);
        }
 
-       while (u->first_vacation != NULL) {
-               if ( (time(NULL) - u->first_vacation->timestamp) < MAX_VACATION) {
-                       text = realloc(text, strlen(text) + strlen(u->first_vacation->fromaddr) + 256);
-                       sprintf(&text[strlen(text)], "vacation|%ld|%s" CTDLSIEVECONFIGSEPARATOR,
-                               u->first_vacation->timestamp,
-                               u->first_vacation->fromaddr
-                       );
+       if (u->first_vacation != NULL) {
+
+               size_t realloc_len = strlen(text) + 256;
+               for (vptr = u->first_vacation; vptr != NULL; vptr = vptr->next) {
+                       realloc_len += strlen(vptr->fromaddr + 32);
+               }
+               text = realloc(text, realloc_len);
+
+               sprintf(&text[strlen(text)], "vacation|\n");
+               while (u->first_vacation != NULL) {
+                       if ( (time(NULL) - u->first_vacation->timestamp) < (MAX_VACATION * 86400)) {
+                               sprintf(&text[strlen(text)], "%s|%ld\n",
+                                       u->first_vacation->fromaddr,
+                                       u->first_vacation->timestamp
+                               );
+                       }
+                       vptr = u->first_vacation;
+                       u->first_vacation = u->first_vacation->next;
+                       free(vptr);
                }
-               vptr = u->first_vacation;
-               u->first_vacation = u->first_vacation->next;
-               free(vptr);
+               sprintf(&text[strlen(text)], CTDLSIEVECONFIGSEPARATOR);
        }
 
        /* Save the config */
@@ -760,7 +787,7 @@ void sieve_do_room(char *roomname) {
        /* See if the user who owns this 'mailbox' has any Sieve scripts that
         * require execution.
         */
-       snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), SIEVERULES);
+       snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), USERCONFIGROOM);
        if (getroom(&CC->room, u.config_roomname) != 0) {
                lprintf(CTDL_DEBUG, "<%s> does not exist.  No processing is required.\n", u.config_roomname);
                return;
@@ -871,7 +898,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, SIEVERULES) == 0) {
+       if (getroom(&CC->room, USERCONFIGROOM) == 0) {
        
                u->config_msgnum = (-1);
                strcpy(u->config_roomname, CC->room.QRname);
@@ -1077,7 +1104,7 @@ void cmd_msiv(char *argbuf) {
                extract_token(script_name, argbuf, 1, '|', sizeof script_name);
                script_content = msiv_getscript(&u, script_name);
                if (script_content != NULL) {
-                       cprintf("%d Script:\n", SEND_LISTING);
+                       cprintf("%d Script:\n", LISTING_FOLLOWS);
                        cprintf("%s000\n", script_content);
                }
                else {