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 WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><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 border=0 width=100%% bgcolor=\"#FFFFFF\">"
86 "<tr><td valign=top>\n");
89 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
91 wprintf(_("When new mail arrives: "));
92 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
94 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
95 wprintf(_("Leave it in my inbox without filtering"));
96 wprintf("</option>\n");
98 wprintf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
99 wprintf(_("Filter it according to rules selected below"));
100 wprintf("</option>\n");
102 wprintf("<option %s value=\"2\">",
103 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
104 wprintf(_("Filter it through a manually edited script (advanced users only)"));
105 wprintf("</option>\n");
107 wprintf("</select>");
111 /* The "no filtering" div */
113 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
114 wprintf("<div align=\"center\"><br /><br />");
115 wprintf(_("Your incoming mail will not be filtered through any scripts."));
116 wprintf("<br /><br /></div>\n");
119 /* The "webcit managed scripts" div */
121 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
122 display_rules_editor_inner_div();
125 /* The "I'm smart and can write my own Sieve scripts" div */
127 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
129 if (num_scripts > 0) {
130 wprintf(_("The currently active script is: "));
131 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
132 for (i=0; i<num_scripts; ++i) {
133 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
134 wprintf("<option %s value=\"%s\">%s</option>\n",
135 ((active_script == i) ? "selected" : ""),
141 wprintf("</select>\n");
144 wprintf(" ");
145 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
149 if (num_scripts > 0) {
150 for (i=0; i<num_scripts; ++i) {
151 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
152 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
153 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
155 serv_printf("MSIV getscript|%s", script_names[i]);
156 serv_getln(buf, sizeof buf);
157 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
158 wprintf("%s\n", buf);
160 wprintf("</textarea>\n");
166 wprintf("<script type=\"text/javascript\"> \n"
167 "ToggleScriptPanels(); \n"
174 /* The rest of this is common for all panels... */
176 wprintf("<div align=\"center\"><br>");
177 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
179 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
180 wprintf("</div></form>\n");
182 wprintf("</td></tr></table></div>\n");
184 wprintf("<script type=\"text/javascript\"> \n"
185 "ToggleSievePanels(); \n"
196 * \brief Helper function for output_sieve_rule() to output strings with quotes escaped
198 void osr_sanitize(char *str) {
201 if (str == NULL) return;
202 for (i=0; i<strlen(str); ++i) {
206 else if (isspace(str[i])) {
214 * \brief Output parseable Sieve script code based on rules input
216 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
217 char *action, char *fileinto, char *redirect, char *automsg, char *final)
223 osr_sanitize(fileinto);
224 osr_sanitize(redirect);
225 osr_sanitize(automsg);
227 /* Prepare negation and match operators that will be used iff we apply a conditional */
229 if (!strcasecmp(compare, "contains")) {
233 else if (!strcasecmp(compare, "notcontains")) {
237 else if (!strcasecmp(compare, "is")) {
241 else if (!strcasecmp(compare, "isnot")) {
245 else if (!strcasecmp(compare, "matches")) {
249 else if (!strcasecmp(compare, "notmatches")) {
254 /* Now do the conditional */
256 if (!strcasecmp(hfield, "from")) {
257 serv_printf("if%s header %s \"From\" \"%s\"",
263 else if (!strcasecmp(hfield, "tocc")) {
264 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
270 else if (!strcasecmp(hfield, "subject")) {
271 serv_printf("if%s header %s \"Subject\" \"%s\"",
277 else if (!strcasecmp(hfield, "replyto")) {
278 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
284 else if (!strcasecmp(hfield, "sender")) {
285 serv_printf("if%s header %s \"Sender\" \"%s\"",
291 else if (!strcasecmp(hfield, "resentfrom")) {
292 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
298 else if (!strcasecmp(hfield, "resentto")) {
299 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
305 else if (!strcasecmp(hfield, "xmailer")) {
306 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
312 else if (!strcasecmp(hfield, "xspamflag")) {
313 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
319 else if (!strcasecmp(hfield, "xspamstatus")) {
320 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
326 else if (!strcasecmp(hfield, "envfrom")) {
327 serv_printf("if%s envelope %s \"From\" \"%s\"",
333 else if (!strcasecmp(hfield, "envto")) {
334 serv_printf("if%s envelope %s \"To\" \"%s\"",
340 else if (!strcasecmp(hfield, "size")) {
341 if (!strcasecmp(sizecomp, "larger")) {
342 serv_printf("if size :over %d", sizeval);
344 else if (!strcasecmp(sizecomp, "smaller")) {
345 serv_printf("if size :under %d", sizeval);
347 else { /* failsafe - should never get here, but just in case... */
348 serv_printf("if size :over 1");
352 /* Open braces if we're in a conditional loop */
354 if (strcasecmp(hfield, "all")) {
361 if (!strcasecmp(action, "keep")) {
362 serv_printf("keep;");
365 else if (!strcasecmp(action, "discard")) {
366 serv_printf("discard;");
369 else if (!strcasecmp(action, "reject")) {
370 serv_printf("reject \"%s\";", automsg);
373 else if (!strcasecmp(action, "fileinto")) {
374 serv_printf("fileinto \"%s\";", fileinto);
377 else if (!strcasecmp(action, "redirect")) {
378 serv_printf("redirect \"%s\";", redirect);
381 else if (!strcasecmp(action, "vacation")) {
382 serv_printf("vacation \"%s\";", automsg);
386 /* Do 'final' action */
388 if (!strcasecmp(final, "stop")) {
389 serv_printf("stop;");
393 /* Close the braces if we're in a conditional loop */
395 if (strcasecmp(hfield, "all")) {
406 * \brief Translate the fields from the rule editor into something we can save...
408 void parse_fields_from_rule_editor(void) {
426 char encoded_rule[4096];
428 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
429 serv_getln(buf, sizeof buf);
434 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
436 serv_puts("# Do not attempt to manually edit it. If you do so,");
437 serv_puts("# your changes will be overwritten the next time WebCit");
438 serv_puts("# saves its mail filtering rule set. If you really want");
439 serv_puts("# to use these rules as the basis for another script,");
440 serv_puts("# copy them to another script and save that instead.");
442 serv_puts("require \"fileinto\";");
443 serv_puts("require \"reject\";");
444 serv_puts("require \"vacation\";");
445 serv_puts("require \"envelope\";");
448 for (i=0; i<MAX_RULES; ++i) {
452 sprintf(fname, "active%d", i);
453 active = !strcasecmp(bstr(fname), "on") ;
457 sprintf(fname, "hfield%d", i);
458 safestrncpy(hfield, bstr(fname), sizeof hfield);
460 sprintf(fname, "compare%d", i);
461 safestrncpy(compare, bstr(fname), sizeof compare);
463 sprintf(fname, "htext%d", i);
464 safestrncpy(htext, bstr(fname), sizeof htext);
466 sprintf(fname, "sizecomp%d", i);
467 safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
469 sprintf(fname, "sizeval%d", i);
470 sizeval = atoi(bstr(fname));
472 sprintf(fname, "action%d", i);
473 safestrncpy(action, bstr(fname), sizeof action);
475 sprintf(fname, "fileinto%d", i);
476 safestrncpy(fileinto, bstr(fname), sizeof fileinto);
478 sprintf(fname, "redirect%d", i);
479 safestrncpy(redirect, bstr(fname), sizeof redirect);
481 sprintf(fname, "automsg%d", i);
482 safestrncpy(automsg, bstr(fname), sizeof automsg);
484 sprintf(fname, "final%d", i);
485 safestrncpy(final, bstr(fname), sizeof final);
487 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
488 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
489 redirect, automsg, final
492 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
493 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
494 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
495 action, fileinto, redirect, automsg, final);
510 * \brief save sieve config
512 void save_sieve(void) {
514 char script_names[MAX_SCRIPTS][64];
516 int active_script = (-1);
521 if (strlen(bstr("save_button")) == 0) {
522 strcpy(WC->ImportantMessage,
523 _("Cancelled. Changes were not saved."));
528 parse_fields_from_rule_editor();
530 serv_puts("MSIV listscripts");
531 serv_getln(buf, sizeof(buf));
532 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
533 if (num_scripts < MAX_SCRIPTS) {
534 extract_token(script_names[num_scripts], buf, 0, '|', 64);
535 if (extract_int(buf, 1) > 0) {
536 active_script = num_scripts;
542 bigaction = atoi(bstr("bigaction"));
544 if (bigaction == 0) {
545 serv_puts("MSIV setactive||");
546 serv_getln(buf, sizeof buf);
549 else if (bigaction == 1) {
550 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
551 serv_getln(buf, sizeof buf);
554 else if (bigaction == 2) {
555 serv_printf("MSIV setactive|%s|", bstr("active_script"));
556 serv_getln(buf, sizeof buf);
559 if (num_scripts > 0) {
560 for (i=0; i<num_scripts; ++i) {
562 * We only want to save the scripts from the "manually edited scripts"
563 * screen. The script that WebCit generates from its ruleset will be
564 * auto-generated by parse_fields_from_rule_editor() and saved there.
566 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
567 serv_printf("MSIV putscript|%s|", script_names[i]);
568 serv_getln(buf, sizeof buf);
570 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
571 striplt(bstr(this_name));
572 serv_printf("%s", bstr(this_name));
579 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
586 * \brief show a list of available scripts to add/remove them
588 void display_add_remove_scripts(char *message)
591 char script_name[256];
593 output_headers(1, 1, 2, 0, 0, 0);
594 wprintf("<div id=\"banner\">\n");
595 wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
597 "<span class=\"titlebar\">"
598 "<img src=\"static/advanpage2_48x.gif\">");
599 wprintf(_("Add or delete scripts"));
600 wprintf("</span></td></tr></table>\n"
601 "</div>\n<div id=\"content\">\n"
604 if (message != NULL) wprintf(message);
606 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
608 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
609 do_template("beginbox");
611 wprintf(_("To create a new script, enter the desired "
612 "script name in the box below and click 'Create'."));
613 wprintf("<br /><br />");
615 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
616 wprintf(_("Script name: "));
617 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
618 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
619 "</form></center>\n", _("Create"));
621 do_template("endbox");
623 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
624 do_template("beginbox");
625 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
626 _("Return to the script editing screen")
628 do_template("endbox");
630 wprintf("</td><td>");
632 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
633 do_template("beginbox");
635 wprintf(_("To delete an existing script, select the script "
636 "name from the list and click 'Delete'."));
637 wprintf("<br /><br />");
640 "<form method=\"POST\" action=\"delete_script\">\n");
641 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
643 serv_puts("MSIV listscripts");
644 serv_getln(buf, sizeof buf);
646 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
647 extract_token(script_name, buf, 0, '|', sizeof script_name);
648 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
650 escputs(script_name);
651 wprintf("</option>\n");
655 wprintf("</select><br />\n");
657 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
658 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
659 wprintf("</form></center>\n");
660 do_template("endbox");
662 wprintf("</td></tr></table>\n");
670 * \brief delete a script
672 void delete_script(void) {
675 serv_printf("MSIV deletescript|%s", bstr("script_name"));
676 serv_getln(buf, sizeof buf);
677 display_add_remove_scripts(&buf[4]);
683 * \brief create a new script
684 * take the web environment script name and create it on the citadel server
686 void create_script(void) {
689 serv_printf("MSIV getscript|%s", bstr("script_name"));
690 serv_getln(buf, sizeof buf);
692 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
695 display_add_remove_scripts(_("A script by that name already exists."));
699 serv_printf("MSIV putscript|%s", bstr("script_name"));
700 serv_getln(buf, sizeof buf);
704 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
708 display_add_remove_scripts(&buf[4]);
714 void display_rules_editor_inner_div(void) {
717 char rules[MAX_RULES][2048];
722 int num_roomnames = 0;
723 int num_roomnames_alloc = 0;
738 memset(rules, 0, sizeof rules);
739 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
740 serv_getln(buf, sizeof buf);
741 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
742 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
743 j = extract_int(buf, 1);
744 remove_token(buf, 0, '|');
745 remove_token(buf, 0, '|');
746 CtdlDecodeBase64(rules[j], buf, strlen(buf));
750 /* load the roomnames */
752 serv_getln(buf, sizeof buf);
754 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
756 if (num_roomnames > num_roomnames_alloc) {
757 num_roomnames_alloc += 250;
758 rooms = realloc(rooms, (num_roomnames_alloc * 128));
760 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
766 * This script should get called by every onChange event...
769 wprintf("<script type=\"text/javascript\"> \n"
771 "var highest_active_rule = (-1); \n"
773 "function UpdateRules() { \n");
775 * Show only the active rows...
777 wprintf(" highest_active_rule = (-1); \n");
778 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
779 wprintf(" if ($('active'+i).checked) { \n"
780 " $('rule' + i).style.display = 'block'; \n"
781 " highest_active_rule = i; \n"
784 " $('rule' + i).style.display = 'none'; \n"
788 * Show only the fields relevant to the rules...
790 wprintf(" for (i=0; i<=highest_active_rule; ++i) { \n"
791 " d = ($('movedown'+i)); \n"
792 " if (i < highest_active_rule) { \n"
793 " d.style.display = 'block'; \n"
796 " d.style.display = 'none'; \n"
798 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
799 " if (d == 'all') { \n"
800 " $('div_size'+i).style.display = 'none'; \n"
801 " $('div_compare'+i).style.display = 'none'; \n"
802 " $('div_nocompare'+i).style.display = 'block'; \n"
804 " else if (d == 'size') { \n"
805 " $('div_size'+i).style.display = 'block'; \n"
806 " $('div_compare'+i).style.display = 'none'; \n"
807 " $('div_nocompare'+i).style.display = 'none'; \n"
810 " $('div_size'+i).style.display = 'none'; \n"
811 " $('div_compare'+i).style.display = 'block'; \n"
812 " $('div_nocompare'+i).style.display = 'none'; \n"
814 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
815 " if (d == 'fileinto') { \n"
816 " $('div_fileinto'+i).style.display = 'block'; \n"
817 " $('div_redirect'+i).style.display = 'none'; \n"
818 " $('div_automsg'+i).style.display = 'none'; \n"
819 " } else if (d == 'redirect') { \n"
820 " $('div_fileinto'+i).style.display = 'none'; \n"
821 " $('div_redirect'+i).style.display = 'block'; \n"
822 " $('div_automsg'+i).style.display = 'none'; \n"
823 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
824 " $('div_fileinto'+i).style.display = 'none'; \n"
825 " $('div_redirect'+i).style.display = 'none'; \n"
826 " $('div_automsg'+i).style.display = 'block'; \n"
828 " $('div_fileinto'+i).style.display = 'none'; \n"
829 " $('div_redirect'+i).style.display = 'none'; \n"
830 " $('div_automsg'+i).style.display = 'none'; \n"
832 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
833 wprintf(" $('div_addrule').style.display = 'block'; \n"
835 " $('div_addrule').style.display = 'none'; \n"
840 * Add a rule (really, just un-hide it)
842 "function AddRule() { \n"
843 " highest_active_rule = highest_active_rule + 1; \n"
844 " $('active'+highest_active_rule).checked = true; \n"
850 "function SwapRules(ra, rb) { \n"
852 " var things = new Array(); \n"
853 " things[0] = 'hfield'; \n"
854 " things[1] = 'compare'; \n"
855 " things[2] = 'htext'; \n"
856 " things[3] = 'action'; \n"
857 " things[4] = 'fileinto'; \n"
858 " things[5] = 'redirect'; \n"
859 " things[6] = 'final'; \n"
860 " things[7] = 'sizecomp'; \n"
861 " things[8] = 'sizeval'; \n"
862 " things[9] = 'automsg'; \n"
864 " for (i=0; i<=9; ++i) { \n"
865 " tempval=$(things[i]+ra).value; \n"
866 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
867 " $(things[i]+rb).value = tempval; \n"
871 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
873 "function DeleteRule(rd) { \n"
874 " for (j=rd; j<=highest_active_rule; ++j) { \n"
875 " SwapRules(j, (j+1)); \n"
877 " $('active'+highest_active_rule).checked = false; \n"
885 wprintf("<table cellpadding=2 width=100%%>");
887 for (i=0; i<MAX_RULES; ++i) {
889 /* Grab our existing values to populate */
890 active = extract_int(rules[i], 0);
891 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
892 extract_token(compare, rules[i], 2, '|', sizeof compare);
893 extract_token(htext, rules[i], 3, '|', sizeof htext);
894 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
895 sizeval = extract_int(rules[i], 5);
896 extract_token(action, rules[i], 6, '|', sizeof action);
897 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
898 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
899 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
900 extract_token(final, rules[i], 10, '|', sizeof final);
902 /* now generate the table row */
904 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
906 ((i%2) ? "DDDDDD" : "FFFFFF")
909 wprintf("<td width=5%% align=\"center\">");
911 wprintf("<div style=\"display:none\">");
912 wprintf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
914 (active ? "checked" : "")
918 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
919 "<img border=\"0\" src=\"static/up_pointer.gif\" "
920 "title=\"%s\"/></a>",
921 i-1, i, _("Move rule up") );
923 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
924 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
925 "title=\"%s\"/></a>",
926 i, i+1, i, _("Move rule down") );
928 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
929 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
930 "title=\"%s\"/></a>",
931 i, i, _("Delete rule") );
935 wprintf("<td width=5%% align=\"center\">");
936 wprintf("<font size=+2>%d</font>", i+1);
939 wprintf("<td width=20%%>%s ", _("If") );
941 char *hfield_values[14][2] = {
942 { "from", _("From") },
943 { "tocc", _("To or Cc") },
944 { "subject", _("Subject") },
945 { "replyto", _("Reply-to") },
946 { "sender", _("Sender") },
947 { "resentfrom", _("Resent-From") },
948 { "resentto", _("Resent-To") },
949 { "envfrom", _("Envelope From") },
950 { "envto", _("Envelope To") },
951 { "xmailer", _("X-Mailer") },
952 { "xspamflag", _("X-Spam-Flag") },
953 { "xspamstatus", _("X-Spam-Status") },
954 { "size", _("Message size") },
958 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
960 for (j=0; j<14; ++j) {
961 wprintf("<option %s value=\"%s\">%s</option>",
962 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
968 wprintf("</select>");
971 wprintf("<td width=20%%>");
973 char *compare_values[6][2] = {
974 { "contains", _("contains") },
975 { "notcontains", _("does not contain") },
977 { "isnot", _("is not") },
978 { "matches", _("matches") },
979 { "notmatches", _("does not match") }
982 wprintf("<div id=\"div_compare%d\">", i);
983 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
985 for (j=0; j<6; ++j) {
986 wprintf("<option %s value=\"%s\">%s</option>",
987 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
988 compare_values[j][0],
992 wprintf("</select>");
994 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
996 wprintf("\"></div>");
998 wprintf("<div id=\"div_nocompare%d\">", i);
999 wprintf("%s", _("(All messages)"));
1002 char *sizecomp_values[2][2] = {
1003 { "larger", _("is larger than") },
1004 { "smaller", _("is smaller than") }
1007 wprintf("<div id=\"div_size%d\">", i);
1008 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1010 for (j=0; j<2; ++j) {
1011 wprintf("<option %s value=\"%s\">%s</option>",
1012 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1013 sizecomp_values[j][0],
1014 sizecomp_values[j][1]
1017 wprintf("</select>");
1019 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1026 char *action_values[6][2] = {
1027 { "keep", _("Keep") },
1028 { "discard", _("Discard silently") },
1029 { "reject", _("Reject") },
1030 { "fileinto", _("Move message to") },
1031 { "redirect", _("Forward to") },
1032 { "vacation", _("Vacation") }
1035 wprintf("<td width=20%%>");
1036 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1038 for (j=0; j<6; ++j) {
1039 wprintf("<option %s value=\"%s\">%s</option>",
1040 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1041 action_values[j][0],
1045 wprintf("</select>");
1047 wprintf("<div id=\"div_fileinto%d\">", i);
1048 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1049 for (j=0; j<num_roomnames; ++j) {
1050 wprintf("<option ");
1051 if (!strcasecmp(rooms[j].name, fileinto)) {
1052 wprintf("selected ");
1054 wprintf("value=\"");
1055 urlescputs(rooms[j].name);
1057 escputs(rooms[j].name);
1058 wprintf("</option>\n");
1060 wprintf("</select>\n");
1063 wprintf("<div id=\"div_redirect%d\">", i);
1064 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1066 wprintf("\"></div>");
1068 wprintf("<div id=\"div_automsg%d\">", i);
1069 wprintf(_("Message:"));
1071 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1073 wprintf("</textarea>");
1078 char *final_values[2][2] = {
1079 { "continue", _("continue processing") },
1080 { "stop", _("stop") }
1083 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1085 wprintf("<td width=20%%>");
1086 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1088 for (j=0; j<2; ++j) {
1089 wprintf("<option %s value=\"%s\">%s</option>",
1090 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1095 wprintf("</select>");
1102 wprintf("</table>");
1103 wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1107 wprintf("<script type=\"text/javascript\"> \n");
1108 wprintf("UpdateRules(); \n");
1109 wprintf("</script> \n");