]> code.citadel.org Git - citadel.git/blobdiff - webcit/sieve.c
More work on the rules editor
[citadel.git] / webcit / sieve.c
index 32c92408af64b1ff25e0d3e032283095e362251f..210345ec7c794885a6f57f61e4271e6d493c0294 100644 (file)
@@ -9,7 +9,7 @@
 #include "webcit.h"
 
 #define MAX_SCRIPTS    100
-#define MAX_RULES      10
+#define MAX_RULES      25
 
 /**
  * \brief view/edit sieve config
@@ -414,22 +414,48 @@ void display_rules_editor_inner_div(void) {
                "    else {                                                             \n"
                "      d.style.display = 'none';                                        \n"
                "    }                                                                  \n"
+               "    d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value);    \n"
+               "    if (d == 'all') {                                                  \n"
+               "      $('div_size'+i).style.display = 'none';                          \n"
+               "      $('div_compare'+i).style.display = 'none';                       \n"
+               "    }                                                                  \n"
+               "    else if (d == 'size') {                                            \n"
+               "      $('div_size'+i).style.display = 'block';                         \n"
+               "      $('div_compare'+i).style.display = 'none';                       \n"
+               "    }                                                                  \n"
+               "    else {                                                             \n"
+               "      $('div_size'+i).style.display = 'none';                          \n"
+               "      $('div_compare'+i).style.display = 'block';                      \n"
+               "    }                                                                  \n"
                "    d = ($('action'+i).options[$('action'+i).selectedIndex].value);    \n"
                "    if (d == 'fileinto') {                                             \n"
                "      $('div_fileinto'+i).style.display = 'block';                     \n"
                "      $('div_redirect'+i).style.display = 'none';                      \n"
+               "      $('div_automsg'+i).style.display = 'none';                       \n"
                "    } else if (d == 'redirect') {                                      \n"
                "      $('div_fileinto'+i).style.display = 'none';                      \n"
-               "    $('div_redirect'+i).style.display = 'block';                       \n"
-               "    } else  {                                                          \n"
+               "      $('div_redirect'+i).style.display = 'block';                     \n"
+               "      $('div_automsg'+i).style.display = 'none';                       \n"
+               "    } else if ((d == 'reject') || (d == 'vacation'))  {                \n"
                "      $('div_fileinto'+i).style.display = 'none';                      \n"
                "      $('div_redirect'+i).style.display = 'none';                      \n"
+               "      $('div_automsg'+i).style.display = 'block';                      \n"
+               "    } else {                                                           \n"
+               "      $('div_fileinto'+i).style.display = 'none';                      \n"
+               "      $('div_redirect'+i).style.display = 'none';                      \n"
+               "      $('div_automsg'+i).style.display = 'none';                       \n"
+               "    }                                                                  \n"
+               "    if (highest_active_rule < %d) {                                    \n", MAX_RULES-1 );
+       wprintf("      $('div_addrule').style.display = 'block';                        \n"
+               "    } else {                                                           \n"
+               "      $('div_addrule').style.display = 'none';                         \n"
                "    }                                                                  \n"
                "  }                                                                    \n"
        );
 /*
  * Show only the active rows...
  */
+       wprintf("  highest_active_rule = (-1);                                          \n");
        wprintf("  for (i=0; i<%d; ++i) {                                               \n", MAX_RULES);
        wprintf("   if ($('active'+i).checked) {                                        \n"
                "     $('rule' + i).style.display = 'block';                            \n"
@@ -442,7 +468,6 @@ void display_rules_editor_inner_div(void) {
                "}                                                                      \n"
 /*
  * Add a rule (really, just un-hide it)
- * FIXME check the upper bound
  */
                "function AddRule() {                                                   \n"
                "  highest_active_rule = highest_active_rule + 1;                       \n"
@@ -462,23 +487,33 @@ void display_rules_editor_inner_div(void) {
                "  things[4] = 'fileinto';                                              \n"
                "  things[5] = 'redirect';                                              \n"
                "  things[6] = 'final';                                                 \n"
+               "  things[7] = 'sizecomp';                                              \n"
+               "  things[8] = 'sizeval';                                               \n"
+               "  things[9] = 'automsg';                                               \n"
                "                                                                       \n"
-               "  for (i=0; i<7; ++i) {                                                \n"
+               "  for (i=0; i<=9; ++i) {                                               \n"
                "    tempval=$(things[i]+ra).value;                                     \n"
                "    $(things[i]+ra).value = $(things[i]+rb).value;                     \n"
                "    $(things[i]+rb).value = tempval;                                   \n"
                "  }                                                                    \n"
-               "                                                                       \n"
                "}                                                                      \n"
-
+/*
+ * Delete a rule (percolate the deleted rule out to the end,
+ *                and then decrement highest_active_rule)
+ */
+               "function DeleteRule(rd) {                                              \n"
+               "  for (i=rd; i<highest_active_rule; ++i) {                             \n"
+               "    SwapRules(i, (i+1));                                               \n"
+               "  }                                                                    \n"
+               "  $('active'+highest_active_rule).checked = false;                     \n"
+               "}                                                                      \n"
                "</script>                                                              \n"
        );
 
 
        wprintf("<br />");
-       wprintf("<table class=\"mailbox_summary\" rules=rows cellpadding=2 "
-               "style=\"width:100%%;-moz-user-select:none;\">"
-       );
+
+       wprintf("<table border=1 cellpadding=2 width=100%%>");
 
        for (i=0; i<MAX_RULES; ++i) {
                
@@ -497,37 +532,73 @@ void display_rules_editor_inner_div(void) {
                        "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" /></a>",
                        i, i+1, i);
 
+               wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
+                       "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" /></a>",
+                       i, i);
+
                wprintf("&nbsp;%d.&nbsp;%s</td>", i+1, _("If") );
 
                wprintf("<td>");
 
                wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
                        i, i);
+               wprintf("<option value=\"from\">%s</option>", _("From"));
+               wprintf("<option value=\"tocc\">%s</option>", _("To or Cc"));
+               wprintf("<option value=\"subject\">%s</option>", _("Subject"));
+               wprintf("<option value=\"replyto\">%s</option>", _("Reply-to"));
                wprintf("<option value=\"sender\">%s</option>", _("Sender"));
-               wprintf("<option value=\"recipient\">%s</option>", _("Recipient"));
+               wprintf("<option value=\"resentfrom\">%s</option>", _("Resent-From"));
+               wprintf("<option value=\"resentto\">%s</option>", _("Resent-To"));
+               wprintf("<option value=\"envfrom\">%s</option>", _("Envelope From"));
+               wprintf("<option value=\"envto\">%s</option>", _("Envelope To"));
+               wprintf("<option value=\"xmailer\">%s</option>", _("X-Mailer"));
+               wprintf("<option value=\"xspamflag\">%s</option>", _("X-Spam-Flag"));
+               wprintf("<option value=\"xspamstatus\">%s</option>", _("X-Spam-Status"));
+               wprintf("<option value=\"size\">%s</option>", _("Message size"));
+               wprintf("<option value=\"all\">%s</option>", _("(All messages)"));
                wprintf("</select>");
                wprintf("</td>");
 
                wprintf("<td>");
+
+               wprintf("<div id=\"div_compare%d\">", i);
                wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
                        i, i);
-               wprintf("<option value=\"match\">%s</option>", _("matches"));
-               wprintf("<option value=\"notmatch\">%s</option>", _("does not match"));
+               wprintf("<option value=\"contains\">%s</option>", _("contains"));
+               wprintf("<option value=\"notcontains\">%s</option>", _("does not contain"));
+               wprintf("<option value=\"is\">%s</option>", _("is"));
+               wprintf("<option value=\"isnot\">%s</option>", _("is not"));
                wprintf("</select>");
 
                wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\">", i, i);
+               wprintf("</div>");
+
+               wprintf("<div id=\"div_size%d\">", i);
+               wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
+                       i, i);
+               wprintf("<option value=\"larger\">%s</option>", _("is larger than"));
+               wprintf("<option value=\"smaller\">%s</option>", _("is smaller than"));
+               wprintf("</select>");
+
+               wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\">", i, i);
+               wprintf("bytes");
+               wprintf("</div>");
+
                wprintf("</td>");
 
                wprintf("<td>");
                wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
                        i, i);
-               wprintf("<option value=\"fileinto\">%s</option>", _("file into"));
-               wprintf("<option value=\"redirect\">%s</option>", _("forward to"));
-               wprintf("<option value=\"reject\">%s</option>", _("reject"));
+               wprintf("<option value=\"keep\">%s</option>", _("Keep"));
+               wprintf("<option value=\"discard\">%s</option>", _("Discard silently"));
+               wprintf("<option value=\"reject\">%s</option>", _("Reject"));
+               wprintf("<option value=\"fileinto\">%s</option>", _("Move message to"));
+               wprintf("<option value=\"redirect\">%s</option>", _("Forward to"));
+               wprintf("<option value=\"vacation\">%s</option>", _("Vacation"));
                wprintf("</select>");
 
                wprintf("<div id=\"div_fileinto%d\">", i);
-               wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\" style=\"width:100px\">", i, i);
+               wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
                for (j=0; j<num_roomnames; ++j) {
                        wprintf("<option ");
                        if (!strcasecmp(rooms[j].name, "Mail")) {
@@ -545,6 +616,13 @@ void display_rules_editor_inner_div(void) {
                wprintf("<div id=\"div_redirect%d\">", i);
                wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\">", i, i);
                wprintf("</div>");
+
+               wprintf("<div id=\"div_automsg%d\">", i);
+               wprintf(_("Message:"));
+               wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
+               wprintf("</textarea>");
+               wprintf("</div>");
+
                wprintf("</td>");
 
 
@@ -564,10 +642,7 @@ void display_rules_editor_inner_div(void) {
        }
 
        wprintf("</table>");
-       wprintf("<a href=\"javascript:AddRule();\">Add rule</a><br />\n");
-
-       wprintf("<a href=\"javascript:SwapRules(0,1);UpdateRules();\">"
-               "Swap first two rules (test)</a><br />\n");
+       wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">Add rule</a><br /></div>\n");
 
        wprintf("<script type=\"text/javascript\">                                      \n"
                "UpdateRules();                                                         \n"