]> code.citadel.org Git - citadel.git/blobdiff - webcit/sieve.c
Call LoadExpirePolicy() unconditionally, this fixes the apparent snap back to old...
[citadel.git] / webcit / sieve.c
index 15412e0f8d5a760e78ed2a6e5f5afd4f05ba0c48..d93fdcc6c0c3964702c99e589f2c022adea3c674 100644 (file)
@@ -8,6 +8,8 @@
  * 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.
+ *
+ * FIXME: add logic to exclude the webcit-generated script from the manual script selection
  */
 
 #include "webcit.h"
@@ -418,6 +420,14 @@ void save_sieve(void) {
 }
 
 
+void display_sieve_add_or_delete(void) {
+       output_headers(1, 1, 2, 0, 0, 0);
+       do_template("sieve_add");
+       wDumpContent(1);
+}
+
+
+
 /*
  * create a new script
  * take the web environment script name and create it on the citadel server
@@ -427,27 +437,22 @@ void create_script(void) {
 
        serv_printf("MSIV getscript|%s", bstr("script_name"));
        serv_getln(buf, sizeof buf);
-       if (buf[0] == '1') {
+       if (buf[0] == '1') {            // does script exist already?
                while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
-                       /* flush */
+                                       // yes -- flush the output
                }
-               return;
        }
-       
-       serv_printf("MSIV putscript|%s", bstr("script_name"));
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '4') {
-               serv_puts("keep;");
-               serv_puts("000");
-       output_headers(1, 1, 2, 0, 0, 0);
-       do_template("sieve_add");
-       wDumpContent(1);
-               return;
+       else {
+                                       // no -- safe to create a new one by this name
+               serv_printf("MSIV putscript|%s", bstr("script_name"));
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '4') {
+                       serv_puts("keep;");
+                       serv_puts("000");
+               }
        }
 
-       output_headers(1, 1, 2, 0, 0, 0);
-       do_template("sieve_add");
-       wDumpContent(1);
+       display_sieve_add_or_delete();
 }
 
 
@@ -459,9 +464,7 @@ void delete_script(void) {
 
        serv_printf("MSIV deletescript|%s", bstr("script_name"));
        serv_getln(buf, sizeof buf);
-       output_headers(1, 1, 2, 0, 0, 0);
-       do_template("sieve_add");
-       wDumpContent(1);
+       display_sieve_add_or_delete();
 }
 
 
@@ -470,7 +473,7 @@ void delete_script(void) {
  */
 void display_no_sieve(void) {
 
-       output_headers(1, 1, 2, 0, 0, 0);
+       output_headers(1, 1, 1, 0, 0, 0);
        do_template("sieve_none");
        wDumpContent(1);
 }
@@ -564,8 +567,10 @@ HashList *GetSieveScriptListing(StrBuf *Target, WCTemplputParams *TP)
                                ++num_scripts;
                        }
        }
-       if ((num_scripts > 0) && (rules_script_active == 0))
+
+       if ((num_scripts > 0) && (rules_script_active == 0)) {
                PutBstr(HKEY("__SIEVE:EXTERNAL_SCRIPT"), NewStrBufPlain(HKEY("1")));
+       }
 
        if (num_scripts > have_rules_script)
        {
@@ -584,19 +589,12 @@ HashList *GetSieveScriptListing(StrBuf *Target, WCTemplputParams *TP)
                       (vRuleset != NULL))
                {
                        Ruleset = (SieveListing *) vRuleset;
-
-                       /*
-                        * its the webcit rule? we don't need to load that here.
-                        */
-                       if (Ruleset->IsRulesScript)
-                               continue;
-
-                       if (!serv_printf("MSIV getscript|%s", ChrPtr(Ruleset->Name)))
-                               break;
+                       serv_printf("MSIV getscript|%s", ChrPtr(Ruleset->Name));
                        StrBuf_ServGetln(Line);
                        if (GetServerStatus(Line, NULL) == 1) 
                        {
                                Ruleset->Content = NewStrBuf();
+                               Done = 0;
                                while(!Done && (rc = StrBuf_ServGetln(Line), rc >= 0) )
                                        if ( (StrLength(Line)==3) && 
                                             !strcmp(ChrPtr(Line), "000")) 
@@ -958,4 +956,5 @@ InitModule_SIEVE
        WebcitAddUrlHandler(HKEY("save_sieve"), "", 0, save_sieve, 0);
        WebcitAddUrlHandler(HKEY("create_script"), "", 0, create_script, 0);
        WebcitAddUrlHandler(HKEY("delete_script"), "", 0, delete_script, 0);
+       WebcitAddUrlHandler(HKEY("display_sieve_add_or_delete"), "", 0, display_sieve_add_or_delete, 0);
 }