]> code.citadel.org Git - citadel.git/blobdiff - webcit/sieve.c
sieve editor: continue templating, add 'one' iterator for the default template
[citadel.git] / webcit / sieve.c
index 80142ebeae93ef3c2a16d3b455a07f4dc3b053b0..aaf4b1d7abb000a5abcd41c4a3b90f99414b874d 100644 (file)
@@ -21,8 +21,8 @@
 #define MAX_SCRIPTS    100
 #define MAX_RULES      50
 #define RULES_SCRIPT   "__WebCit_Generated_Script__"
-#define FOO 1
 
+#define FOO 1
 /*
  * Helper function for output_sieve_rule() to output strings with quotes escaped
  */
@@ -569,7 +569,7 @@ void display_sieve(void)
        );
 
        wc_printf("<div id=\"banner\">\n");
-       wc_printf("<img src=\"static/advanpage2_48x.gif\">");
+       wc_printf("<img src=\"static/webcit_icons/essen/32x32/config.png\">");
        wc_printf("<h1>");
        wc_printf(_("View/edit server-side mail filters"));
        wc_printf("</h1>\n");
@@ -699,7 +699,7 @@ void display_add_remove_scripts(char *message)
 
        output_headers(1, 1, 2, 0, 0, 0);
        wc_printf("<div id=\"banner\">\n");
-       wc_printf("<img src=\"static/icons/essen/32x32/config.png\">");
+       wc_printf("<img src=\"static/webcit_icons/essen/32x32/config.png\">");
        wc_printf(_("Add or delete scripts"));
        wc_printf("</h1>\n");
        wc_printf("</div>\n");
@@ -712,9 +712,9 @@ void display_add_remove_scripts(char *message)
 
        wc_printf("<table border=0 cellspacing=10><tr valign=top><td>\n");
 
-       do_template("beginbox_1");
+       do_template("box_begin_1");
        StrBufAppendBufPlain(WC->WBuf, _("Add a new script"), -1, 0);
-       do_template("beginbox_2");
+       do_template("box_begin_2");
 
        wc_printf(_("To create a new script, enter the desired "
                "script name in the box below and click 'Create'."));
@@ -727,21 +727,21 @@ void display_add_remove_scripts(char *message)
                "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
                "</form></center>\n", _("Create"));
 
-       do_template("endbox");
+       do_template("box_end");
 
-       do_template("beginbox_1");
+       do_template("box_begin_1");
        StrBufAppendBufPlain(WC->WBuf, _("Edit scripts"), -1, 0);
-       do_template("beginbox_2");
+       do_template("box_begin_2");
        wc_printf("<br><div align=center><a href=\"display_sieve\">%s</a><br><br>\n",
                _("Return to the script editing screen")
        );
-       do_template("endbox");
+       do_template("box_end");
 
        wc_printf("</td><td>");
 
-       do_template("beginbox_1");
+       do_template("box_begin_1");
        StrBufAppendBufPlain(WC->WBuf, _("Delete scripts"), -1, 0);
-       do_template("beginbox_2");
+       do_template("box_begin_2");
 
        wc_printf(_("To delete an existing script, select the script "
                "name from the list and click 'Delete'."));
@@ -769,7 +769,7 @@ void display_add_remove_scripts(char *message)
         wc_printf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
                "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
         wc_printf("</form></center>\n");
-       do_template("endbox");
+       do_template("box_end");
 
        wc_printf("</td></tr></table>\n");
 
@@ -986,17 +986,17 @@ void display_rules_editor_inner_div(void) {
                wc_printf("</div>");
 
                if (i>0) wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
-                       "<img border=\"0\" src=\"static/icons/up_pointer.gif\" "
+                       "<img border=\"0\" src=\"static/webcit_icons/up_pointer.gif\" "
                        "title=\"%s\"/></a>",
                        i-1, i, _("Move rule up") );
 
                wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
-                       "<img id=\"movedown%d\" border=\"0\" src=\"static/icons/down_pointer.gif\" "
+                       "<img id=\"movedown%d\" border=\"0\" src=\"static/webcit_icons/down_pointer.gif\" "
                        "title=\"%s\"/></a>",
                        i, i+1, i, _("Move rule down") );
 
                wc_printf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
-                       "<img id=\"delete%d\" border=\"0\" src=\"static/icons/delete.gif\" "
+                       "<img id=\"delete%d\" border=\"0\" src=\"static/webcit_icons/delete.gif\" "
                        "title=\"%s\"/></a>",
                        i, i, _("Delete rule") );
 
@@ -1276,7 +1276,7 @@ HashList *GetSieveScriptListing(StrBuf *Target, WCTemplputParams *TP)
 
        if (num_scripts > have_rules_script)
        {
-               long rc;
+               long rc = 0;
                long len;
                const char *Key;
                void *vRuleset;
@@ -1508,6 +1508,11 @@ void tmplput_SieveRule_final(StrBuf *Target, WCTemplputParams *TP)
        StrBufAppendTemplate(Target, TP, Rule->final, 0);
 }
 */
+void tmplput_SieveRule_sizeval(StrBuf *Target, WCTemplputParams *TP) 
+{
+       SieveRule     *Rule = (SieveRule *)CTX;
+       wc_printf("%d", Rule->sizeval);
+}
 void FreeSieveRule(void *vRule)
 {
        SieveRule *Rule = (SieveRule*) Rule;
@@ -1594,6 +1599,23 @@ HashList *GetSieveRules(StrBuf *Target, WCTemplputParams *TP)
        return SieveRules;
 }
 
+
+HashList *GetEmptySieveRule(StrBuf *Target, WCTemplputParams *TP)
+{
+       int n = 0;
+       HashList *OneSieveRule;
+       SieveRule *Rule;
+
+       OneSieveRule = NewHash(1, Flathash);
+
+       /* We just care for our encoded header and skip everything else */
+       Rule = (SieveRule*) malloc(sizeof(SieveRule));
+       memset(Rule, 0, sizeof(SieveRule));
+       Put(OneSieveRule, IKEY(n), Rule, FreeSieveRule);
+
+       return OneSieveRule;
+}
+
 void
 SessionDetachModule_SIEVE
 (wcsession *sess)
@@ -1642,16 +1664,17 @@ InitModule_SIEVE
        RegisterTokenParamDefine(HKEY("continue"), econtinue);
        RegisterTokenParamDefine(HKEY("stop"), estop);
 
-       RegisterIterator("SIEVE:SCRIPTS", 0, NULL, GetSieveRules, NULL, NULL, CTX_SIEVELIST, CTX_NONE, IT_NOFLAG);
-
-       RegisterIterator("SIEVE:RULES", 0, NULL, GetSieveRules, NULL, DeleteHash, CTX_SIEVESCRIPT, CTX_NONE, IT_NOFLAG);
+       RegisterIterator("SIEVE:SCRIPTS", 0, NULL, GetSieveScriptListing, NULL, NULL, CTX_SIEVELIST, CTX_NONE, IT_NOFLAG);
 
        RegisterConditional(HKEY("COND:SIEVE:SCRIPT:ACTIVE"), 0, ConditionalSieveScriptIsActive, CTX_SIEVELIST);
        RegisterConditional(HKEY("COND:SIEVE:SCRIPT:ISRULES"), 0, ConditionalSieveScriptIsRulesScript, CTX_SIEVELIST);
-       RegisterNamespace("SIEVE:SCRIPT:NAME", 0, 1, tmplput_SieveScriptName, NULL, CTX_ROOMS);
+       RegisterNamespace("SIEVE:SCRIPT:NAME", 0, 1, tmplput_SieveScriptName, NULL, CTX_SIEVELIST);
        RegisterNamespace("SIEVE:SCRIPT:CONTENT", 0, 1, tmplput_SieveScriptContent, NULL, CTX_SIEVELIST);
 
  
+       RegisterIterator("SIEVE:RULES", 0, NULL, GetSieveRules, NULL, DeleteHash, CTX_SIEVESCRIPT, CTX_NONE, IT_NOFLAG);
+       RegisterIterator("SIEVE:RULE:EMPTY", 0, NULL, GetEmptySieveRule, NULL, DeleteHash, CTX_SIEVESCRIPT, CTX_NONE, IT_NOFLAG);
+
        RegisterConditional(HKEY("COND:SIEVE:ACTIVE"), 1, ConditionalSieveRule_Active, CTX_SIEVESCRIPT);
        RegisterConditional(HKEY("COND:SIEVE:HFIELD"), 1, ConditionalSieveRule_hfield, CTX_SIEVESCRIPT);
        RegisterConditional(HKEY("COND:SIEVE:COMPARE"), 1, ConditionalSieveRule_compare, CTX_SIEVESCRIPT);
@@ -1663,7 +1686,7 @@ InitModule_SIEVE
        //RegisterNamespace("SIEVE:SCRIPT:HFIELD", 0, 1, tmplput_SieveRule_hfield, NULL, CTX_SIEVESCRIPT);
        //RegisterNamespace("SIEVE:SCRIPT:COMPARE", 0, 1, tmplput_SieveRule_compare, NULL, CTX_SIEVESCRIPT);
        RegisterNamespace("SIEVE:SCRIPT:HTEXT", 0, 1, tmplput_SieveRule_htext, NULL, CTX_SIEVESCRIPT);
-       //RegisterNamespace("SIEVE:SCRIPT:SIZECOMP", 0, 1, tmplput_SieveRule_sizecomp, NULL, CTX_SIEVESCRIPT);
+       RegisterNamespace("SIEVE:SCRIPT:SIZE", 0, 1, tmplput_SieveRule_sizeval, NULL, CTX_SIEVESCRIPT);
        ///RegisterNamespace("SIEVE:SCRIPT:ACTION", 0, 1, tmplput_SieveRule_action, NULL, CTX_SIEVESCRIPT);
        RegisterNamespace("SIEVE:SCRIPT:FILEINTO", 0, 1, tmplput_SieveRule_fileinto, NULL, CTX_SIEVESCRIPT);
        RegisterNamespace("SIEVE:SCRIPT:REDIRECT", 0, 1, tmplput_SieveRule_redirect, NULL, CTX_SIEVESCRIPT);