5 * \defgroup Sieve view/edit sieve config
6 * \ingroup WebcitDisplayItems
11 #define MAX_SCRIPTS 100
13 #define RULES_SCRIPT "__WebCit_Generated_Script__"
16 * \brief view/edit sieve config
18 void display_sieve(void)
20 char script_names[MAX_SCRIPTS][64];
22 int active_script = (-1);
25 int rules_script_is_active = 0;
28 memset(script_names, 0, sizeof script_names);
30 serv_puts("MSIV listscripts");
31 serv_getln(buf, sizeof(buf));
32 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
33 if (num_scripts < MAX_SCRIPTS) {
34 extract_token(script_names[num_scripts], buf, 0, '|', 64);
35 if (extract_int(buf, 1) > 0) {
36 active_script = num_scripts;
37 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
38 rules_script_is_active = 1;
45 output_headers(1, 1, 2, 0, 0, 0);
47 wprintf("<script type=\"text/javascript\"> \n"
49 "var previously_active_script; \n"
51 "function ToggleSievePanels() { \n"
52 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
53 " for (i=0; i<3; ++i) { \n"
55 " $('sievediv' + i).style.display = 'block'; \n"
58 " $('sievediv' + i).style.display = 'none'; \n"
63 "function ToggleScriptPanels() { \n"
64 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
65 " if ($('script_' + previously_active_script)) { \n"
66 " $('script_' + previously_active_script).style.display = 'none'; \n"
68 " $('script_' + d).style.display = 'block'; \n"
69 " previously_active_script = d; \n"
75 wprintf("<div id=\"banner\">\n");
76 wprintf("<TABLE class=\"sieve_banner\"><TR><TD>");
77 wprintf("<SPAN CLASS=\"titlebar\">"
78 "<img src=\"static/advanpage2_48x.gif\">");
79 wprintf(_("View/edit server-side mail filters"));
81 wprintf("</TD></TR></TABLE>\n");
82 wprintf("</div>\n<div id=\"content\">\n");
84 wprintf("<div class=\"fix_scrollbar_bug\">"
85 "<table class=\"sieve_background\">"
86 "<tr><td valign=top>\n");
89 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
90 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
92 wprintf(_("When new mail arrives: "));
93 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
95 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
96 wprintf(_("Leave it in my inbox without filtering"));
97 wprintf("</option>\n");
99 wprintf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
100 wprintf(_("Filter it according to rules selected below"));
101 wprintf("</option>\n");
103 wprintf("<option %s value=\"2\">",
104 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
105 wprintf(_("Filter it through a manually edited script (advanced users only)"));
106 wprintf("</option>\n");
108 wprintf("</select>");
112 /* The "no filtering" div */
114 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
115 wprintf("<div align=\"center\"><br /><br />");
116 wprintf(_("Your incoming mail will not be filtered through any scripts."));
117 wprintf("<br /><br /></div>\n");
120 /* The "webcit managed scripts" div */
122 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
123 display_rules_editor_inner_div();
126 /* The "I'm smart and can write my own Sieve scripts" div */
128 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
130 if (num_scripts > 0) {
131 wprintf(_("The currently active script is: "));
132 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
133 for (i=0; i<num_scripts; ++i) {
134 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
135 wprintf("<option %s value=\"%s\">%s</option>\n",
136 ((active_script == i) ? "selected" : ""),
142 wprintf("</select>\n");
145 wprintf(" ");
146 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
150 if (num_scripts > 0) {
151 for (i=0; i<num_scripts; ++i) {
152 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
153 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
154 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
156 serv_printf("MSIV getscript|%s", script_names[i]);
157 serv_getln(buf, sizeof buf);
158 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
159 wprintf("%s\n", buf);
161 wprintf("</textarea>\n");
167 wprintf("<script type=\"text/javascript\"> \n"
168 "ToggleScriptPanels(); \n"
175 /* The rest of this is common for all panels... */
177 wprintf("<div align=\"center\"><br>");
178 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
180 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
181 wprintf("</div></form>\n");
183 wprintf("</td></tr></table></div>\n");
185 wprintf("<script type=\"text/javascript\"> \n"
186 "ToggleSievePanels(); \n"
197 * \brief Helper function for output_sieve_rule() to output strings with quotes escaped
199 void osr_sanitize(char *str) {
202 if (str == NULL) return;
203 for (i=0; i<strlen(str); ++i) {
207 else if (isspace(str[i])) {
215 * \brief Output parseable Sieve script code based on rules input
217 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
218 char *action, char *fileinto, char *redirect, char *automsg, char *final)
224 osr_sanitize(fileinto);
225 osr_sanitize(redirect);
226 osr_sanitize(automsg);
228 /* Prepare negation and match operators that will be used iff we apply a conditional */
230 if (!strcasecmp(compare, "contains")) {
234 else if (!strcasecmp(compare, "notcontains")) {
238 else if (!strcasecmp(compare, "is")) {
242 else if (!strcasecmp(compare, "isnot")) {
246 else if (!strcasecmp(compare, "matches")) {
250 else if (!strcasecmp(compare, "notmatches")) {
255 /* Now do the conditional */
257 if (!strcasecmp(hfield, "from")) {
258 serv_printf("if%s header %s \"From\" \"%s\"",
264 else if (!strcasecmp(hfield, "tocc")) {
265 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
271 else if (!strcasecmp(hfield, "subject")) {
272 serv_printf("if%s header %s \"Subject\" \"%s\"",
278 else if (!strcasecmp(hfield, "replyto")) {
279 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
285 else if (!strcasecmp(hfield, "sender")) {
286 serv_printf("if%s header %s \"Sender\" \"%s\"",
292 else if (!strcasecmp(hfield, "resentfrom")) {
293 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
299 else if (!strcasecmp(hfield, "resentto")) {
300 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
306 else if (!strcasecmp(hfield, "xmailer")) {
307 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
313 else if (!strcasecmp(hfield, "xspamflag")) {
314 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
320 else if (!strcasecmp(hfield, "xspamstatus")) {
321 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
327 else if (!strcasecmp(hfield, "envfrom")) {
328 serv_printf("if%s envelope %s \"From\" \"%s\"",
334 else if (!strcasecmp(hfield, "envto")) {
335 serv_printf("if%s envelope %s \"To\" \"%s\"",
341 else if (!strcasecmp(hfield, "size")) {
342 if (!strcasecmp(sizecomp, "larger")) {
343 serv_printf("if size :over %d", sizeval);
345 else if (!strcasecmp(sizecomp, "smaller")) {
346 serv_printf("if size :under %d", sizeval);
348 else { /* failsafe - should never get here, but just in case... */
349 serv_printf("if size :over 1");
353 /* Open braces if we're in a conditional loop */
355 if (strcasecmp(hfield, "all")) {
362 if (!strcasecmp(action, "keep")) {
363 serv_printf("keep;");
366 else if (!strcasecmp(action, "discard")) {
367 serv_printf("discard;");
370 else if (!strcasecmp(action, "reject")) {
371 serv_printf("reject \"%s\";", automsg);
374 else if (!strcasecmp(action, "fileinto")) {
375 serv_printf("fileinto \"%s\";", fileinto);
378 else if (!strcasecmp(action, "redirect")) {
379 serv_printf("redirect \"%s\";", redirect);
382 else if (!strcasecmp(action, "vacation")) {
383 serv_printf("vacation \"%s\";", automsg);
387 /* Do 'final' action */
389 if (!strcasecmp(final, "stop")) {
390 serv_printf("stop;");
394 /* Close the braces if we're in a conditional loop */
396 if (strcasecmp(hfield, "all")) {
407 * \brief Translate the fields from the rule editor into something we can save...
409 void parse_fields_from_rule_editor(void) {
427 char encoded_rule[4096];
429 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
430 serv_getln(buf, sizeof buf);
435 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
437 serv_puts("# Do not attempt to manually edit it. If you do so,");
438 serv_puts("# your changes will be overwritten the next time WebCit");
439 serv_puts("# saves its mail filtering rule set. If you really want");
440 serv_puts("# to use these rules as the basis for another script,");
441 serv_puts("# copy them to another script and save that instead.");
443 serv_puts("require \"fileinto\";");
444 serv_puts("require \"reject\";");
445 serv_puts("require \"vacation\";");
446 serv_puts("require \"envelope\";");
449 for (i=0; i<MAX_RULES; ++i) {
453 sprintf(fname, "active%d", i);
454 active = !strcasecmp(bstr(fname), "on") ;
458 sprintf(fname, "hfield%d", i);
459 safestrncpy(hfield, bstr(fname), sizeof hfield);
461 sprintf(fname, "compare%d", i);
462 safestrncpy(compare, bstr(fname), sizeof compare);
464 sprintf(fname, "htext%d", i);
465 safestrncpy(htext, bstr(fname), sizeof htext);
467 sprintf(fname, "sizecomp%d", i);
468 safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
470 sprintf(fname, "sizeval%d", i);
471 sizeval = atoi(bstr(fname));
473 sprintf(fname, "action%d", i);
474 safestrncpy(action, bstr(fname), sizeof action);
476 sprintf(fname, "fileinto%d", i);
477 safestrncpy(fileinto, bstr(fname), sizeof fileinto);
479 sprintf(fname, "redirect%d", i);
480 safestrncpy(redirect, bstr(fname), sizeof redirect);
482 sprintf(fname, "automsg%d", i);
483 safestrncpy(automsg, bstr(fname), sizeof automsg);
485 sprintf(fname, "final%d", i);
486 safestrncpy(final, bstr(fname), sizeof final);
488 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
489 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
490 redirect, automsg, final
493 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
494 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
495 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
496 action, fileinto, redirect, automsg, final);
511 * \brief save sieve config
513 void save_sieve(void) {
515 char script_names[MAX_SCRIPTS][64];
517 int active_script = (-1);
522 if (strlen(bstr("save_button")) == 0) {
523 strcpy(WC->ImportantMessage,
524 _("Cancelled. Changes were not saved."));
529 parse_fields_from_rule_editor();
531 serv_puts("MSIV listscripts");
532 serv_getln(buf, sizeof(buf));
533 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
534 if (num_scripts < MAX_SCRIPTS) {
535 extract_token(script_names[num_scripts], buf, 0, '|', 64);
536 if (extract_int(buf, 1) > 0) {
537 active_script = num_scripts;
543 bigaction = atoi(bstr("bigaction"));
545 if (bigaction == 0) {
546 serv_puts("MSIV setactive||");
547 serv_getln(buf, sizeof buf);
550 else if (bigaction == 1) {
551 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
552 serv_getln(buf, sizeof buf);
555 else if (bigaction == 2) {
556 serv_printf("MSIV setactive|%s|", bstr("active_script"));
557 serv_getln(buf, sizeof buf);
560 if (num_scripts > 0) {
561 for (i=0; i<num_scripts; ++i) {
563 * We only want to save the scripts from the "manually edited scripts"
564 * screen. The script that WebCit generates from its ruleset will be
565 * auto-generated by parse_fields_from_rule_editor() and saved there.
567 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
568 serv_printf("MSIV putscript|%s|", script_names[i]);
569 serv_getln(buf, sizeof buf);
571 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
572 striplt(bstr(this_name));
573 serv_printf("%s", bstr(this_name));
580 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
587 * \brief show a list of available scripts to add/remove them
589 void display_add_remove_scripts(char *message)
592 char script_name[256];
594 output_headers(1, 1, 2, 0, 0, 0);
595 wprintf("<div id=\"banner\">\n");
596 wprintf("<table class=\"sieve_banner\"><tr>"
598 "<span class=\"titlebar\">"
599 "<img src=\"static/advanpage2_48x.gif\">");
600 wprintf(_("Add or delete scripts"));
601 wprintf("</span></td></tr></table>\n"
602 "</div>\n<div id=\"content\">\n"
605 if (message != NULL) wprintf(message);
607 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
609 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
610 do_template("beginbox");
612 wprintf(_("To create a new script, enter the desired "
613 "script name in the box below and click 'Create'."));
614 wprintf("<br /><br />");
616 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
617 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
618 wprintf(_("Script name: "));
619 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
620 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
621 "</form></center>\n", _("Create"));
623 do_template("endbox");
625 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
626 do_template("beginbox");
627 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
628 _("Return to the script editing screen")
630 do_template("endbox");
632 wprintf("</td><td>");
634 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
635 do_template("beginbox");
637 wprintf(_("To delete an existing script, select the script "
638 "name from the list and click 'Delete'."));
639 wprintf("<br /><br />");
642 "<form method=\"POST\" action=\"delete_script\">\n");
643 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
644 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
646 serv_puts("MSIV listscripts");
647 serv_getln(buf, sizeof buf);
649 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
650 extract_token(script_name, buf, 0, '|', sizeof script_name);
651 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
653 escputs(script_name);
654 wprintf("</option>\n");
658 wprintf("</select><br />\n");
660 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
661 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
662 wprintf("</form></center>\n");
663 do_template("endbox");
665 wprintf("</td></tr></table>\n");
673 * \brief delete a script
675 void delete_script(void) {
678 serv_printf("MSIV deletescript|%s", bstr("script_name"));
679 serv_getln(buf, sizeof buf);
680 display_add_remove_scripts(&buf[4]);
686 * \brief create a new script
687 * take the web environment script name and create it on the citadel server
689 void create_script(void) {
692 serv_printf("MSIV getscript|%s", bstr("script_name"));
693 serv_getln(buf, sizeof buf);
695 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
698 display_add_remove_scripts(_("A script by that name already exists."));
702 serv_printf("MSIV putscript|%s", bstr("script_name"));
703 serv_getln(buf, sizeof buf);
707 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
711 display_add_remove_scripts(&buf[4]);
717 void display_rules_editor_inner_div(void) {
720 char rules[MAX_RULES][2048];
725 int num_roomnames = 0;
726 int num_roomnames_alloc = 0;
741 memset(rules, 0, sizeof rules);
742 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
743 serv_getln(buf, sizeof buf);
744 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
745 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
746 j = extract_int(buf, 1);
747 remove_token(buf, 0, '|');
748 remove_token(buf, 0, '|');
749 CtdlDecodeBase64(rules[j], buf, strlen(buf));
753 /* load the roomnames */
755 serv_getln(buf, sizeof buf);
757 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
759 if (num_roomnames > num_roomnames_alloc) {
760 num_roomnames_alloc += 250;
761 rooms = realloc(rooms, (num_roomnames_alloc * 128));
763 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
769 * This script should get called by every onChange event...
772 wprintf("<script type=\"text/javascript\"> \n"
774 "var highest_active_rule = (-1); \n"
776 "function UpdateRules() { \n");
778 * Show only the active rows...
780 wprintf(" highest_active_rule = (-1); \n");
781 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
782 wprintf(" if ($('active'+i).checked) { \n"
783 " $('rule' + i).style.display = 'block'; \n"
784 " highest_active_rule = i; \n"
787 " $('rule' + i).style.display = 'none'; \n"
791 * Show only the fields relevant to the rules...
793 wprintf(" for (i=0; i<=highest_active_rule; ++i) { \n"
794 " d = ($('movedown'+i)); \n"
795 " if (i < highest_active_rule) { \n"
796 " d.style.display = 'block'; \n"
799 " d.style.display = 'none'; \n"
801 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
802 " if (d == 'all') { \n"
803 " $('div_size'+i).style.display = 'none'; \n"
804 " $('div_compare'+i).style.display = 'none'; \n"
805 " $('div_nocompare'+i).style.display = 'block'; \n"
807 " else if (d == 'size') { \n"
808 " $('div_size'+i).style.display = 'block'; \n"
809 " $('div_compare'+i).style.display = 'none'; \n"
810 " $('div_nocompare'+i).style.display = 'none'; \n"
813 " $('div_size'+i).style.display = 'none'; \n"
814 " $('div_compare'+i).style.display = 'block'; \n"
815 " $('div_nocompare'+i).style.display = 'none'; \n"
817 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
818 " if (d == 'fileinto') { \n"
819 " $('div_fileinto'+i).style.display = 'block'; \n"
820 " $('div_redirect'+i).style.display = 'none'; \n"
821 " $('div_automsg'+i).style.display = 'none'; \n"
822 " } else if (d == 'redirect') { \n"
823 " $('div_fileinto'+i).style.display = 'none'; \n"
824 " $('div_redirect'+i).style.display = 'block'; \n"
825 " $('div_automsg'+i).style.display = 'none'; \n"
826 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
827 " $('div_fileinto'+i).style.display = 'none'; \n"
828 " $('div_redirect'+i).style.display = 'none'; \n"
829 " $('div_automsg'+i).style.display = 'block'; \n"
831 " $('div_fileinto'+i).style.display = 'none'; \n"
832 " $('div_redirect'+i).style.display = 'none'; \n"
833 " $('div_automsg'+i).style.display = 'none'; \n"
835 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
836 wprintf(" $('div_addrule').style.display = 'block'; \n"
838 " $('div_addrule').style.display = 'none'; \n"
843 * Add a rule (really, just un-hide it)
845 "function AddRule() { \n"
846 " highest_active_rule = highest_active_rule + 1; \n"
847 " $('active'+highest_active_rule).checked = true; \n"
853 "function SwapRules(ra, rb) { \n"
855 " var things = new Array(); \n"
856 " things[0] = 'hfield'; \n"
857 " things[1] = 'compare'; \n"
858 " things[2] = 'htext'; \n"
859 " things[3] = 'action'; \n"
860 " things[4] = 'fileinto'; \n"
861 " things[5] = 'redirect'; \n"
862 " things[6] = 'final'; \n"
863 " things[7] = 'sizecomp'; \n"
864 " things[8] = 'sizeval'; \n"
865 " things[9] = 'automsg'; \n"
867 " for (i=0; i<=9; ++i) { \n"
868 " tempval=$(things[i]+ra).value; \n"
869 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
870 " $(things[i]+rb).value = tempval; \n"
874 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
876 "function DeleteRule(rd) { \n"
877 " for (j=rd; j<=highest_active_rule; ++j) { \n"
878 " SwapRules(j, (j+1)); \n"
880 " $('active'+highest_active_rule).checked = false; \n"
888 wprintf("<table cellpadding=2 width=100%%>");
890 for (i=0; i<MAX_RULES; ++i) {
892 /* Grab our existing values to populate */
893 active = extract_int(rules[i], 0);
894 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
895 extract_token(compare, rules[i], 2, '|', sizeof compare);
896 extract_token(htext, rules[i], 3, '|', sizeof htext);
897 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
898 sizeval = extract_int(rules[i], 5);
899 extract_token(action, rules[i], 6, '|', sizeof action);
900 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
901 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
902 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
903 extract_token(final, rules[i], 10, '|', sizeof final);
905 /* now generate the table row */
907 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
909 ((i%2) ? "DDDDDD" : "FFFFFF")
912 wprintf("<td width=5%% align=\"center\">");
914 wprintf("<div style=\"display:none\">");
915 wprintf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
917 (active ? "checked" : "")
921 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
922 "<img border=\"0\" src=\"static/up_pointer.gif\" "
923 "title=\"%s\"/></a>",
924 i-1, i, _("Move rule up") );
926 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
927 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
928 "title=\"%s\"/></a>",
929 i, i+1, i, _("Move rule down") );
931 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
932 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
933 "title=\"%s\"/></a>",
934 i, i, _("Delete rule") );
938 wprintf("<td width=5%% align=\"center\">");
939 wprintf("<font size=+2>%d</font>", i+1);
942 wprintf("<td width=20%%>%s ", _("If") );
944 char *hfield_values[14][2] = {
945 { "from", _("From") },
946 { "tocc", _("To or Cc") },
947 { "subject", _("Subject") },
948 { "replyto", _("Reply-to") },
949 { "sender", _("Sender") },
950 { "resentfrom", _("Resent-From") },
951 { "resentto", _("Resent-To") },
952 { "envfrom", _("Envelope From") },
953 { "envto", _("Envelope To") },
954 { "xmailer", _("X-Mailer") },
955 { "xspamflag", _("X-Spam-Flag") },
956 { "xspamstatus", _("X-Spam-Status") },
957 { "size", _("Message size") },
961 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
963 for (j=0; j<14; ++j) {
964 wprintf("<option %s value=\"%s\">%s</option>",
965 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
971 wprintf("</select>");
974 wprintf("<td width=20%%>");
976 char *compare_values[6][2] = {
977 { "contains", _("contains") },
978 { "notcontains", _("does not contain") },
980 { "isnot", _("is not") },
981 { "matches", _("matches") },
982 { "notmatches", _("does not match") }
985 wprintf("<div id=\"div_compare%d\">", i);
986 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
988 for (j=0; j<6; ++j) {
989 wprintf("<option %s value=\"%s\">%s</option>",
990 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
991 compare_values[j][0],
995 wprintf("</select>");
997 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
999 wprintf("\"></div>");
1001 wprintf("<div id=\"div_nocompare%d\">", i);
1002 wprintf("%s", _("(All messages)"));
1005 char *sizecomp_values[2][2] = {
1006 { "larger", _("is larger than") },
1007 { "smaller", _("is smaller than") }
1010 wprintf("<div id=\"div_size%d\">", i);
1011 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1013 for (j=0; j<2; ++j) {
1014 wprintf("<option %s value=\"%s\">%s</option>",
1015 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1016 sizecomp_values[j][0],
1017 sizecomp_values[j][1]
1020 wprintf("</select>");
1022 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1029 char *action_values[6][2] = {
1030 { "keep", _("Keep") },
1031 { "discard", _("Discard silently") },
1032 { "reject", _("Reject") },
1033 { "fileinto", _("Move message to") },
1034 { "redirect", _("Forward to") },
1035 { "vacation", _("Vacation") }
1038 wprintf("<td width=20%%>");
1039 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1041 for (j=0; j<6; ++j) {
1042 wprintf("<option %s value=\"%s\">%s</option>",
1043 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1044 action_values[j][0],
1048 wprintf("</select>");
1050 wprintf("<div id=\"div_fileinto%d\">", i);
1051 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1052 for (j=0; j<num_roomnames; ++j) {
1053 wprintf("<option ");
1054 if (!strcasecmp(rooms[j].name, fileinto)) {
1055 wprintf("selected ");
1057 wprintf("value=\"");
1058 escputs(rooms[j].name);
1060 escputs(rooms[j].name);
1061 wprintf("</option>\n");
1063 wprintf("</select>\n");
1066 wprintf("<div id=\"div_redirect%d\">", i);
1067 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1069 wprintf("\"></div>");
1071 wprintf("<div id=\"div_automsg%d\">", i);
1072 wprintf(_("Message:"));
1074 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1076 wprintf("</textarea>");
1081 char *final_values[2][2] = {
1082 { "continue", _("continue processing") },
1083 { "stop", _("stop") }
1086 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1088 wprintf("<td width=20%%>");
1089 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1091 for (j=0; j<2; ++j) {
1092 wprintf("<option %s value=\"%s\">%s</option>",
1093 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1098 wprintf("</select>");
1105 wprintf("</table>");
1106 wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1110 wprintf("<script type=\"text/javascript\"> \n");
1111 wprintf("UpdateRules(); \n");
1112 wprintf("</script> \n");