]> code.citadel.org Git - citadel.git/blobdiff - webcit/sieve.c
Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel
[citadel.git] / webcit / sieve.c
index cac28be5966e51c3ccd069e290b5c09050f2cb3d..be9484b783170bd425e2996fee7c0dc26425341a 100644 (file)
 #define MAX_SCRIPTS    100
 #define MAX_RULES      50
 #define RULES_SCRIPT   "__WebCit_Generated_Script__"
+<<<<<<< HEAD
+
+
+/*
+ * dummy panel indicating to the user that the server doesn't support Sieve
+ */
+void display_no_sieve(void) {
+
+       output_headers(1, 1, 2, 0, 0, 0);
+
+       wc_printf("<div id=\"banner\">\n");
+       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");
+       wc_printf("</div>\n");
+
+       wc_printf("<div id=\"content\" class=\"service\">\n");
+
+       wc_printf("<table class=\"sieve_background\">"
+               "<tr><td valign=top>\n");
+
+       wc_printf(_("This installation of Citadel was built without support for server-side mail filtering."
+               "<br>Please contact your system administrator if you require this feature.<br>"));
+
+       wc_printf("</td></tr></table>\n");
+       wDumpContent(1);
+}
+
+
+/*
+ * view/edit sieve config
+ */
+void display_sieve(void)
+{
+       char script_names[MAX_SCRIPTS][64];
+       int num_scripts = 0;
+       int active_script = (-1);
+       char buf[SIZ];          /* Don't make this buffer smaller or it will restrict line length */
+       int i;
+       int rules_script_is_active = 0;
+
+       if (!WC->serv_info->serv_supports_sieve) {
+               display_no_sieve();
+               return;
+       }
+
+       memset(script_names, 0, sizeof script_names);
+
+       serv_puts("MSIV listscripts");
+       serv_getln(buf, sizeof(buf));
+       if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
+               if (num_scripts < MAX_SCRIPTS) {
+                       extract_token(script_names[num_scripts], buf, 0, '|', 64);
+                       if (extract_int(buf, 1) > 0) {
+                               active_script = num_scripts;
+                               if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
+                                       rules_script_is_active = 1;
+                               }
+                       }
+                       ++num_scripts;
+               }
+       }
+
+       output_headers(1, 1, 2, 0, 0, 0);
+
+       wc_printf("<script type=\"text/javascript\">                                    \n"
+               "                                                                       \n"
+               "var previously_active_script;                                          \n"
+               "                                                                       \n"
+               "function ToggleSievePanels() {                                         \n"
+               " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
+               " for (i=0; i<3; ++i) {                                                 \n"
+               "  if (i == d) {                                                        \n"
+               "   $('sievediv' + i).style.display = 'block';                          \n"
+               "  }                                                                    \n"
+               "  else {                                                               \n"
+               "   $('sievediv' + i).style.display = 'none';                           \n"
+               "  }                                                                    \n"
+               " }                                                                     \n"
+               "}                                                                      \n"
+               "                                                                       \n"
+               "function ToggleScriptPanels() {                                        \n"
+               " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
+               " if ($('script_' + previously_active_script)) {                        \n"
+               "  $('script_' + previously_active_script).style.display = 'none';      \n"
+               " }                                                                     \n"
+               " $('script_' + d).style.display = 'block';                             \n"
+               " previously_active_script = d;                                         \n"
+               "}                                                                      \n"
+               "                                                                       \n"
+               "</script>                                                              \n"
+       );
+
+       wc_printf("<div id=\"banner\">\n");
+       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");
+       wc_printf("</div>\n");
+
+       wc_printf("<div id=\"content\" class=\"service\">\n");
+
+       wc_printf("<table class=\"sieve_background\">"
+               "<tr><td valign=top>\n");
+
+
+       wc_printf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
+       wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+
+       wc_printf(_("When new mail arrives: "));
+        wc_printf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
+
+       wc_printf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
+       wc_printf(_("Leave it in my inbox without filtering"));
+       wc_printf("</option>\n");
+
+       wc_printf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
+       wc_printf(_("Filter it according to rules selected below"));
+       wc_printf("</option>\n");
+
+       wc_printf("<option %s value=\"2\">",
+                       (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
+       wc_printf(_("Filter it through a manually edited script (advanced users only)"));
+       wc_printf("</option>\n");
+
+       wc_printf("</select>");
+
+
+
+       /* The "no filtering" div */
+
+       wc_printf("<div id=\"sievediv0\" style=\"display:none\">\n");
+       wc_printf("<div align=\"center\"><br><br>");
+       wc_printf(_("Your incoming mail will not be filtered through any scripts."));
+       wc_printf("<br><br></div>\n");
+       wc_printf("</div>\n");
+
+       /* The "webcit managed scripts" div */
+
+       wc_printf("<div id=\"sievediv1\" style=\"display:none\">\n");
+       display_rules_editor_inner_div();
+       wc_printf("</div>\n");
+
+       /* The "I'm smart and can write my own Sieve scripts" div */
+
+       wc_printf("<div id=\"sievediv2\" style=\"display:none\">\n");
+
+       if (num_scripts > 0) {
+               wc_printf(_("The currently active script is: "));
+               wc_printf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
+               for (i=0; i<num_scripts; ++i) {
+                       if (strcasecmp(script_names[i], RULES_SCRIPT)) {
+                               wc_printf("<option %s value=\"%s\">%s</option>\n",
+                                       ((active_script == i) ? "selected" : ""),
+                                       script_names[i],
+                                       script_names[i]
+                               );
+                       }
+               }
+               wc_printf("</select>\n");
+       }
+
+       wc_printf("&nbsp;&nbsp;&nbsp;");
+       wc_printf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
+
+       wc_printf("<br>\n");
+
+       if (num_scripts > 0) {
+               for (i=0; i<num_scripts; ++i) {
+                       if (strcasecmp(script_names[i], RULES_SCRIPT)) {
+                               wc_printf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
+                               wc_printf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
+                                       script_names[i]);
+                               serv_printf("MSIV getscript|%s", script_names[i]);
+                               serv_getln(buf, sizeof buf);
+                               if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
+                                       wc_printf("%s\n", buf);
+                               }
+                               wc_printf("</textarea>\n");
+                               wc_printf("</div>\n");
+                       }
+               }
+       }
+
+       wc_printf("<script type=\"text/javascript\">    \n"
+               "ToggleScriptPanels();                  \n"
+               "</script>                              \n"
+       );
+
+       wc_printf("</div>\n");
+
+
+       /* The rest of this is common for all panels... */
+
+       wc_printf("<div align=\"center\"><br>");
+       wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
+       wc_printf("&nbsp;");
+       wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
+       wc_printf("</div></form>\n");
+
+       wc_printf("</td></tr></table>\n");
+
+       wc_printf("<script type=\"text/javascript\">    \n"
+               "ToggleSievePanels();                   \n"
+               "</script>                              \n"
+       );
+
+       wDumpContent(1);
+
+}
+
+
+
+=======
 #define FOO 1
+>>>>>>> 1423eb9402b934a3f524a9b7bfd593e9b004cc0a
 /*
  * Helper function for output_sieve_rule() to output strings with quotes escaped
  */
@@ -698,7 +914,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");
@@ -985,17 +1201,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") );