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)
221 osr_sanitize(fileinto);
222 osr_sanitize(redirect);
223 osr_sanitize(automsg);
225 /* FIXME ... do conditional */
227 /* Open braces if we're in a conditional loop */
228 if (strcasecmp(hfield, "all")) {
235 if (!strcasecmp(action, "keep")) {
236 serv_printf(" keep;");
239 else if (!strcasecmp(action, "discard")) {
240 serv_printf(" discard;");
243 else if (!strcasecmp(action, "reject")) {
244 serv_printf(" reject \"%s\";", automsg);
247 else if (!strcasecmp(action, "fileinto")) {
248 serv_printf(" fileinto \"%s\";", fileinto);
251 else if (!strcasecmp(action, "redirect")) {
252 serv_printf(" redirect \"%s\";", redirect);
255 else if (!strcasecmp(action, "vacation")) {
256 serv_printf(" vacation \"%s\";", automsg);
260 /* Do 'final' action */
262 if (!strcasecmp(final, "stop")) {
263 serv_printf(" stop;");
267 /* Close the braces if we're in a conditional loop */
269 if (strcasecmp(hfield, "all")) {
280 * \brief Translate the fields from the rule editor into something we can save...
282 void parse_fields_from_rule_editor(void) {
300 char encoded_rule[4096];
302 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
303 serv_getln(buf, sizeof buf);
308 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
310 serv_puts("# Do not attempt to manually edit it. If you do so,");
311 serv_puts("# your changes will be overwritten the next time WebCit");
312 serv_puts("# saves its mail filtering rule set. If you really want");
313 serv_puts("# to use these rules as the basis for another script,");
314 serv_puts("# copy them to another script and save that instead.");
316 serv_puts("require \"fileinto\";");
317 serv_puts("require \"reject\";");
318 serv_puts("require \"vacation\";");
319 serv_puts("require \"envelope\";");
322 for (i=0; i<MAX_RULES; ++i) {
326 sprintf(fname, "active%d", i);
327 active = !strcasecmp(bstr(fname), "on") ;
331 sprintf(fname, "hfield%d", i);
332 safestrncpy(hfield, bstr(fname), sizeof hfield);
334 sprintf(fname, "compare%d", i);
335 safestrncpy(compare, bstr(fname), sizeof compare);
337 sprintf(fname, "htext%d", i);
338 safestrncpy(htext, bstr(fname), sizeof htext);
340 sprintf(fname, "sizecomp%d", i);
341 safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
343 sprintf(fname, "sizeval%d", i);
344 sizeval = atoi(bstr(fname));
346 sprintf(fname, "action%d", i);
347 safestrncpy(action, bstr(fname), sizeof action);
349 sprintf(fname, "fileinto%d", i);
350 safestrncpy(fileinto, bstr(fname), sizeof fileinto);
352 sprintf(fname, "redirect%d", i);
353 safestrncpy(redirect, bstr(fname), sizeof redirect);
355 sprintf(fname, "automsg%d", i);
356 safestrncpy(automsg, bstr(fname), sizeof automsg);
358 sprintf(fname, "final%d", i);
359 safestrncpy(final, bstr(fname), sizeof final);
361 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
362 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
363 redirect, automsg, final
366 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
367 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
368 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
369 action, fileinto, redirect, automsg, final);
384 * \brief save sieve config
386 void save_sieve(void) {
388 char script_names[MAX_SCRIPTS][64];
390 int active_script = (-1);
395 if (strlen(bstr("save_button")) == 0) {
396 strcpy(WC->ImportantMessage,
397 _("Cancelled. Changes were not saved."));
402 parse_fields_from_rule_editor();
404 serv_puts("MSIV listscripts");
405 serv_getln(buf, sizeof(buf));
406 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
407 if (num_scripts < MAX_SCRIPTS) {
408 extract_token(script_names[num_scripts], buf, 0, '|', 64);
409 if (extract_int(buf, 1) > 0) {
410 active_script = num_scripts;
416 bigaction = atoi(bstr("bigaction"));
418 if (bigaction == 0) {
419 serv_puts("MSIV setactive||");
420 serv_getln(buf, sizeof buf);
423 else if (bigaction == 1) {
424 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
425 serv_getln(buf, sizeof buf);
428 else if (bigaction == 2) {
429 serv_printf("MSIV setactive|%s|", bstr("active_script"));
430 serv_getln(buf, sizeof buf);
433 if (num_scripts > 0) {
434 for (i=0; i<num_scripts; ++i) {
436 * We only want to save the scripts from the "manually edited scripts"
437 * screen. The script that WebCit generates from its ruleset will be
438 * auto-generated by parse_fields_from_rule_editor() and saved there.
440 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
441 serv_printf("MSIV putscript|%s|", script_names[i]);
442 serv_getln(buf, sizeof buf);
444 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
445 striplt(bstr(this_name));
446 serv_printf("%s", bstr(this_name));
453 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
460 * \brief show a list of available scripts to add/remove them
462 void display_add_remove_scripts(char *message)
465 char script_name[256];
467 output_headers(1, 1, 2, 0, 0, 0);
468 wprintf("<div id=\"banner\">\n");
469 wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
471 "<span class=\"titlebar\">"
472 "<img src=\"static/advanpage2_48x.gif\">");
473 wprintf(_("Add or delete scripts"));
474 wprintf("</span></td></tr></table>\n"
475 "</div>\n<div id=\"content\">\n"
478 if (message != NULL) wprintf(message);
480 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
482 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
483 do_template("beginbox");
485 wprintf(_("To create a new script, enter the desired "
486 "script name in the box below and click 'Create'."));
487 wprintf("<br /><br />");
489 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
490 wprintf(_("Script name: "));
491 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
492 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
493 "</form></center>\n", _("Create"));
495 do_template("endbox");
497 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
498 do_template("beginbox");
499 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
500 _("Return to the script editing screen")
502 do_template("endbox");
504 wprintf("</td><td>");
506 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
507 do_template("beginbox");
509 wprintf(_("To delete an existing script, select the script "
510 "name from the list and click 'Delete'."));
511 wprintf("<br /><br />");
514 "<form method=\"POST\" action=\"delete_script\">\n");
515 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
517 serv_puts("MSIV listscripts");
518 serv_getln(buf, sizeof buf);
520 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
521 extract_token(script_name, buf, 0, '|', sizeof script_name);
522 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
524 escputs(script_name);
525 wprintf("</option>\n");
529 wprintf("</select><br />\n");
531 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
532 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
533 wprintf("</form></center>\n");
534 do_template("endbox");
536 wprintf("</td></tr></table>\n");
544 * \brief delete a script
546 void delete_script(void) {
549 serv_printf("MSIV deletescript|%s", bstr("script_name"));
550 serv_getln(buf, sizeof buf);
551 display_add_remove_scripts(&buf[4]);
557 * \brief create a new script
558 * take the web environment script name and create it on the citadel server
560 void create_script(void) {
563 serv_printf("MSIV getscript|%s", bstr("script_name"));
564 serv_getln(buf, sizeof buf);
566 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
569 display_add_remove_scripts(_("A script by that name already exists."));
573 serv_printf("MSIV putscript|%s", bstr("script_name"));
574 serv_getln(buf, sizeof buf);
578 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
582 display_add_remove_scripts(&buf[4]);
588 void display_rules_editor_inner_div(void) {
591 char rules[MAX_RULES][2048];
596 int num_roomnames = 0;
597 int num_roomnames_alloc = 0;
612 memset(rules, 0, sizeof rules);
613 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
614 serv_getln(buf, sizeof buf);
615 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
616 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
617 j = extract_int(buf, 1);
618 remove_token(buf, 0, '|');
619 remove_token(buf, 0, '|');
620 CtdlDecodeBase64(rules[j], buf, strlen(buf));
624 /* load the roomnames */
626 serv_getln(buf, sizeof buf);
628 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
630 if (num_roomnames > num_roomnames_alloc) {
631 num_roomnames_alloc += 250;
632 rooms = realloc(rooms, (num_roomnames_alloc * 128));
634 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
640 * This script should get called by every onChange event...
643 wprintf("<script type=\"text/javascript\"> \n"
645 "var highest_active_rule = (-1); \n"
647 "function UpdateRules() { \n"
648 " for (i=0; i<%d; ++i) { \n", MAX_RULES);
649 wprintf(" d = ($('movedown'+i)); \n"
650 " if (i < highest_active_rule) { \n"
651 " d.style.display = 'block'; \n"
654 " d.style.display = 'none'; \n"
656 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
657 " if (d == 'all') { \n"
658 " $('div_size'+i).style.display = 'none'; \n"
659 " $('div_compare'+i).style.display = 'none'; \n"
660 " $('div_nocompare'+i).style.display = 'block'; \n"
662 " else if (d == 'size') { \n"
663 " $('div_size'+i).style.display = 'block'; \n"
664 " $('div_compare'+i).style.display = 'none'; \n"
665 " $('div_nocompare'+i).style.display = 'none'; \n"
668 " $('div_size'+i).style.display = 'none'; \n"
669 " $('div_compare'+i).style.display = 'block'; \n"
670 " $('div_nocompare'+i).style.display = 'none'; \n"
672 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
673 " if (d == 'fileinto') { \n"
674 " $('div_fileinto'+i).style.display = 'block'; \n"
675 " $('div_redirect'+i).style.display = 'none'; \n"
676 " $('div_automsg'+i).style.display = 'none'; \n"
677 " } else if (d == 'redirect') { \n"
678 " $('div_fileinto'+i).style.display = 'none'; \n"
679 " $('div_redirect'+i).style.display = 'block'; \n"
680 " $('div_automsg'+i).style.display = 'none'; \n"
681 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
682 " $('div_fileinto'+i).style.display = 'none'; \n"
683 " $('div_redirect'+i).style.display = 'none'; \n"
684 " $('div_automsg'+i).style.display = 'block'; \n"
686 " $('div_fileinto'+i).style.display = 'none'; \n"
687 " $('div_redirect'+i).style.display = 'none'; \n"
688 " $('div_automsg'+i).style.display = 'none'; \n"
690 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
691 wprintf(" $('div_addrule').style.display = 'block'; \n"
693 " $('div_addrule').style.display = 'none'; \n"
698 * Show only the active rows...
700 wprintf(" highest_active_rule = (-1); \n");
701 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
702 wprintf(" if ($('active'+i).checked) { \n"
703 " $('rule' + i).style.display = 'block'; \n"
704 " highest_active_rule = i; \n"
707 " $('rule' + i).style.display = 'none'; \n"
712 * Add a rule (really, just un-hide it)
714 "function AddRule() { \n"
715 " highest_active_rule = highest_active_rule + 1; \n"
716 " $('active'+highest_active_rule).checked = true; \n"
722 "function SwapRules(ra, rb) { \n"
724 " var things = new Array(); \n"
725 " things[0] = 'hfield'; \n"
726 " things[1] = 'compare'; \n"
727 " things[2] = 'htext'; \n"
728 " things[3] = 'action'; \n"
729 " things[4] = 'fileinto'; \n"
730 " things[5] = 'redirect'; \n"
731 " things[6] = 'final'; \n"
732 " things[7] = 'sizecomp'; \n"
733 " things[8] = 'sizeval'; \n"
734 " things[9] = 'automsg'; \n"
736 " for (i=0; i<=9; ++i) { \n"
737 " tempval=$(things[i]+ra).value; \n"
738 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
739 " $(things[i]+rb).value = tempval; \n"
743 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
745 "function DeleteRule(rd) { \n"
746 " for (i=rd; i<highest_active_rule; ++i) { \n"
747 " SwapRules(i, (i+1)); \n"
749 " $('active'+highest_active_rule).checked = false; \n"
757 wprintf("<table cellpadding=2 width=100%%>");
759 for (i=0; i<MAX_RULES; ++i) {
761 /* Grab our existing values to populate */
762 active = extract_int(rules[i], 0);
763 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
764 extract_token(compare, rules[i], 2, '|', sizeof compare);
765 extract_token(htext, rules[i], 3, '|', sizeof htext);
766 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
767 sizeval = extract_int(rules[i], 5);
768 extract_token(action, rules[i], 6, '|', sizeof action);
769 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
770 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
771 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
772 extract_token(final, rules[i], 10, '|', sizeof final);
774 /* now generate the table row */
776 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
778 ((i%2) ? "DDDDDD" : "FFFFFF")
781 wprintf("<td width=5%% align=\"center\">");
783 wprintf("<div style=\"display:none\">");
784 wprintf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
786 (active ? "checked" : "")
790 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
791 "<img border=\"0\" src=\"static/up_pointer.gif\" "
792 "title=\"%s\"/></a>",
793 i-1, i, _("Move rule up") );
795 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
796 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
797 "title=\"%s\"/></a>",
798 i, i+1, i, _("Move rule down") );
800 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
801 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
802 "title=\"%s\"/></a>",
803 i, i, _("Delete rule") );
807 wprintf("<td width=5%% align=\"center\">");
808 wprintf("<font size=+2>%d</font>", i+1);
811 wprintf("<td width=20%%>%s ", _("If") );
813 char *hfield_values[14][2] = {
814 { "from", _("From") },
815 { "tocc", _("To or Cc") },
816 { "subject", _("Subject") },
817 { "replyto", _("Reply-to") },
818 { "sender", _("Sender") },
819 { "resentfrom", _("Resent-From") },
820 { "resentto", _("Resent-To") },
821 { "envfrom", _("Envelope From") },
822 { "envto", _("Envelope To") },
823 { "xmailer", _("X-Mailer") },
824 { "xspamflag", _("X-Spam-Flag") },
825 { "xspamstatus", _("X-Spam-Status") },
826 { "size", _("Message size") },
830 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
832 for (j=0; j<14; ++j) {
833 wprintf("<option %s value=\"%s\">%s</option>",
834 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
840 wprintf("</select>");
843 wprintf("<td width=20%%>");
845 char *compare_values[4][2] = {
846 { "contains", _("contains") },
847 { "notcontains", _("does not contain") },
849 { "isnot", _("is not") }
852 wprintf("<div id=\"div_compare%d\">", i);
853 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
855 for (j=0; j<4; ++j) {
856 wprintf("<option %s value=\"%s\">%s</option>",
857 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
858 compare_values[j][0],
862 wprintf("</select>");
864 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
866 wprintf("\"></div>");
868 wprintf("<div id=\"div_nocompare%d\">", i);
869 wprintf("%s", _("(All messages)"));
872 char *sizecomp_values[2][2] = {
873 { "larger", _("is larger than") },
874 { "smaller", _("is smaller than") }
877 wprintf("<div id=\"div_size%d\">", i);
878 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
880 for (j=0; j<2; ++j) {
881 wprintf("<option %s value=\"%s\">%s</option>",
882 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
883 sizecomp_values[j][0],
884 sizecomp_values[j][1]
887 wprintf("</select>");
889 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
896 char *action_values[6][2] = {
897 { "keep", _("Keep") },
898 { "discard", _("Discard silently") },
899 { "reject", _("Reject") },
900 { "fileinto", _("Move message to") },
901 { "redirect", _("Forward to") },
902 { "vacation", _("Vacation") }
905 wprintf("<td width=20%%>");
906 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
908 for (j=0; j<6; ++j) {
909 wprintf("<option %s value=\"%s\">%s</option>",
910 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
915 wprintf("</select>");
917 wprintf("<div id=\"div_fileinto%d\">", i);
918 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
919 for (j=0; j<num_roomnames; ++j) {
921 if (!strcasecmp(rooms[j].name, fileinto)) {
922 wprintf("selected ");
925 urlescputs(rooms[j].name);
927 escputs(rooms[j].name);
928 wprintf("</option>\n");
930 wprintf("</select>\n");
933 wprintf("<div id=\"div_redirect%d\">", i);
934 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
936 wprintf("\"></div>");
938 wprintf("<div id=\"div_automsg%d\">", i);
939 wprintf(_("Message:"));
941 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
943 wprintf("</textarea>");
948 char *final_values[2][2] = {
949 { "continue", _("continue processing") },
950 { "stop", _("stop") }
953 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
955 wprintf("<td width=20%%>");
956 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
958 for (j=0; j<2; ++j) {
959 wprintf("<option %s value=\"%s\">%s</option>",
960 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
965 wprintf("</select>");
973 wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">Add rule</a><br /></div>\n");
975 wprintf("<script type=\"text/javascript\"> \n");
976 wprintf("UpdateRules(); \n");
977 wprintf("</script> \n");