7 #define MAX_SCRIPTS 100
9 #define RULES_SCRIPT "__WebCit_Generated_Script__"
13 * dummy panel indicating to the user that the server doesn't support Sieve
15 void display_no_sieve(void) {
17 output_headers(1, 1, 2, 0, 0, 0);
19 wprintf("<div id=\"banner\">\n");
20 wprintf("<img src=\"static/advanpage2_48x.gif\">");
22 wprintf(_("View/edit server-side mail filters"));
26 wprintf("<div id=\"content\" class=\"service\">\n");
28 wprintf("<div class=\"fix_scrollbar_bug\">"
29 "<table class=\"sieve_background\">"
30 "<tr><td valign=top>\n");
32 wprintf(_("This installation of Citadel was built without support for server-side mail filtering."
33 "<br>Please contact your system administrator if you require this feature.<br>"));
35 wprintf("</td></tr></table></div>\n");
41 * view/edit sieve config
43 void display_sieve(void)
45 char script_names[MAX_SCRIPTS][64];
47 int active_script = (-1);
50 int rules_script_is_active = 0;
52 if (!serv_info.serv_supports_sieve) {
57 memset(script_names, 0, sizeof script_names);
59 serv_puts("MSIV listscripts");
60 serv_getln(buf, sizeof(buf));
61 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
62 if (num_scripts < MAX_SCRIPTS) {
63 extract_token(script_names[num_scripts], buf, 0, '|', 64);
64 if (extract_int(buf, 1) > 0) {
65 active_script = num_scripts;
66 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
67 rules_script_is_active = 1;
74 output_headers(1, 1, 2, 0, 0, 0);
76 wprintf("<script type=\"text/javascript\"> \n"
78 "var previously_active_script; \n"
80 "function ToggleSievePanels() { \n"
81 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
82 " for (i=0; i<3; ++i) { \n"
84 " $('sievediv' + i).style.display = 'block'; \n"
87 " $('sievediv' + i).style.display = 'none'; \n"
92 "function ToggleScriptPanels() { \n"
93 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
94 " if ($('script_' + previously_active_script)) { \n"
95 " $('script_' + previously_active_script).style.display = 'none'; \n"
97 " $('script_' + d).style.display = 'block'; \n"
98 " previously_active_script = d; \n"
104 wprintf("<div id=\"banner\">\n");
105 wprintf("<img src=\"static/advanpage2_48x.gif\">");
107 wprintf(_("View/edit server-side mail filters"));
111 wprintf("<div id=\"content\" class=\"service\">\n");
113 wprintf("<div class=\"fix_scrollbar_bug\">"
114 "<table class=\"sieve_background\">"
115 "<tr><td valign=top>\n");
118 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
119 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
121 wprintf(_("When new mail arrives: "));
122 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
124 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
125 wprintf(_("Leave it in my inbox without filtering"));
126 wprintf("</option>\n");
128 wprintf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
129 wprintf(_("Filter it according to rules selected below"));
130 wprintf("</option>\n");
132 wprintf("<option %s value=\"2\">",
133 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
134 wprintf(_("Filter it through a manually edited script (advanced users only)"));
135 wprintf("</option>\n");
137 wprintf("</select>");
141 /* The "no filtering" div */
143 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
144 wprintf("<div align=\"center\"><br /><br />");
145 wprintf(_("Your incoming mail will not be filtered through any scripts."));
146 wprintf("<br /><br /></div>\n");
149 /* The "webcit managed scripts" div */
151 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
152 display_rules_editor_inner_div();
155 /* The "I'm smart and can write my own Sieve scripts" div */
157 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
159 if (num_scripts > 0) {
160 wprintf(_("The currently active script is: "));
161 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
162 for (i=0; i<num_scripts; ++i) {
163 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
164 wprintf("<option %s value=\"%s\">%s</option>\n",
165 ((active_script == i) ? "selected" : ""),
171 wprintf("</select>\n");
174 wprintf(" ");
175 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
179 if (num_scripts > 0) {
180 for (i=0; i<num_scripts; ++i) {
181 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
182 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
183 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
185 serv_printf("MSIV getscript|%s", script_names[i]);
186 serv_getln(buf, sizeof buf);
187 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
188 wprintf("%s\n", buf);
190 wprintf("</textarea>\n");
196 wprintf("<script type=\"text/javascript\"> \n"
197 "ToggleScriptPanels(); \n"
204 /* The rest of this is common for all panels... */
206 wprintf("<div align=\"center\"><br>");
207 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
209 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
210 wprintf("</div></form>\n");
212 wprintf("</td></tr></table></div>\n");
214 wprintf("<script type=\"text/javascript\"> \n"
215 "ToggleSievePanels(); \n"
226 * Helper function for output_sieve_rule() to output strings with quotes escaped
228 void osr_sanitize(char *str) {
231 if (str == NULL) return;
233 for (i=0; i<len; ++i) {
237 else if (isspace(str[i])) {
245 * Output parseable Sieve script code based on rules input
247 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
248 char *action, char *fileinto, char *redirect, char *automsg, char *final,
255 osr_sanitize(fileinto);
256 osr_sanitize(redirect);
257 osr_sanitize(automsg);
259 /* Prepare negation and match operators that will be used iff we apply a conditional */
261 if (!strcasecmp(compare, "contains")) {
265 else if (!strcasecmp(compare, "notcontains")) {
269 else if (!strcasecmp(compare, "is")) {
273 else if (!strcasecmp(compare, "isnot")) {
277 else if (!strcasecmp(compare, "matches")) {
281 else if (!strcasecmp(compare, "notmatches")) {
286 /* Now do the conditional */
288 if (!strcasecmp(hfield, "from")) {
289 serv_printf("if%s header %s \"From\" \"%s\"",
295 else if (!strcasecmp(hfield, "tocc")) {
296 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
302 else if (!strcasecmp(hfield, "subject")) {
303 serv_printf("if%s header %s \"Subject\" \"%s\"",
309 else if (!strcasecmp(hfield, "replyto")) {
310 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
316 else if (!strcasecmp(hfield, "sender")) {
317 serv_printf("if%s header %s \"Sender\" \"%s\"",
323 else if (!strcasecmp(hfield, "resentfrom")) {
324 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
330 else if (!strcasecmp(hfield, "resentto")) {
331 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
337 else if (!strcasecmp(hfield, "xmailer")) {
338 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
344 else if (!strcasecmp(hfield, "xspamflag")) {
345 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
351 else if (!strcasecmp(hfield, "xspamstatus")) {
352 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
358 else if (!strcasecmp(hfield, "envfrom")) {
359 serv_printf("if%s envelope %s \"From\" \"%s\"",
365 else if (!strcasecmp(hfield, "envto")) {
366 serv_printf("if%s envelope %s \"To\" \"%s\"",
372 else if (!strcasecmp(hfield, "size")) {
373 if (!strcasecmp(sizecomp, "larger")) {
374 serv_printf("if size :over %d", sizeval);
376 else if (!strcasecmp(sizecomp, "smaller")) {
377 serv_printf("if size :under %d", sizeval);
379 else { /* failsafe - should never get here, but just in case... */
380 serv_printf("if size :over 1");
384 /* Open braces if we're in a conditional loop */
386 if (strcasecmp(hfield, "all")) {
393 if (!strcasecmp(action, "keep")) {
394 serv_printf("keep;");
397 else if (!strcasecmp(action, "discard")) {
398 serv_printf("discard;");
401 else if (!strcasecmp(action, "reject")) {
402 serv_printf("reject \"%s\";", automsg);
405 else if (!strcasecmp(action, "fileinto")) {
406 serv_printf("fileinto \"%s\";", fileinto);
409 else if (!strcasecmp(action, "redirect")) {
410 serv_printf("redirect \"%s\";", redirect);
413 else if (!strcasecmp(action, "vacation")) {
414 serv_printf("vacation :addresses [%s]\n\"%s\";", my_addresses, automsg);
418 /* Do 'final' action */
420 if (!strcasecmp(final, "stop")) {
421 serv_printf("stop;");
425 /* Close the braces if we're in a conditional loop */
427 if (strcasecmp(hfield, "all")) {
438 * Translate the fields from the rule editor into something we can save...
440 void parse_fields_from_rule_editor(void) {
457 char encoded_rule[4096];
458 char my_addresses[4096];
460 /* Enumerate my email addresses in case they are needed for a vacation rule */
463 serv_getln(buf, sizeof buf);
464 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
465 if (!IsEmptyStr(my_addresses)) {
466 strcat(my_addresses, ",\n");
468 strcat(my_addresses, "\"");
469 strcat(my_addresses, buf);
470 strcat(my_addresses, "\"");
473 /* Now generate the script and write it to the Citadel server */
474 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
475 serv_getln(buf, sizeof buf);
480 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
482 serv_puts("# Do not attempt to manually edit it. If you do so,");
483 serv_puts("# your changes will be overwritten the next time WebCit");
484 serv_puts("# saves its mail filtering rule set. If you really want");
485 serv_puts("# to use these rules as the basis for another script,");
486 serv_puts("# copy them to another script and save that instead.");
488 serv_puts("require \"fileinto\";");
489 serv_puts("require \"reject\";");
490 serv_puts("require \"vacation\";");
491 serv_puts("require \"envelope\";");
494 for (i=0; i<MAX_RULES; ++i) {
498 sprintf(fname, "active%d", i);
499 active = !strcasecmp(BSTR(fname), "on") ;
503 sprintf(fname, "hfield%d", i);
504 safestrncpy(hfield, BSTR(fname), sizeof hfield);
506 sprintf(fname, "compare%d", i);
507 safestrncpy(compare, BSTR(fname), sizeof compare);
509 sprintf(fname, "htext%d", i);
510 safestrncpy(htext, BSTR(fname), sizeof htext);
512 sprintf(fname, "sizecomp%d", i);
513 safestrncpy(sizecomp, BSTR(fname), sizeof sizecomp);
515 sprintf(fname, "sizeval%d", i);
516 sizeval = IBSTR(fname);
518 sprintf(fname, "action%d", i);
519 safestrncpy(action, BSTR(fname), sizeof action);
521 sprintf(fname, "fileinto%d", i);
522 safestrncpy(fileinto, BSTR(fname), sizeof fileinto);
524 sprintf(fname, "redirect%d", i);
525 safestrncpy(redirect, BSTR(fname), sizeof redirect);
527 sprintf(fname, "automsg%d", i);
528 safestrncpy(automsg, BSTR(fname), sizeof automsg);
530 sprintf(fname, "final%d", i);
531 safestrncpy(final, BSTR(fname), sizeof final);
533 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
534 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
535 redirect, automsg, final
538 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
539 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
540 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
541 action, fileinto, redirect, automsg, final, my_addresses);
557 void save_sieve(void) {
559 char script_names[MAX_SCRIPTS][64];
561 int active_script = (-1);
566 if (!havebstr("save_button")) {
567 strcpy(WC->ImportantMessage,
568 _("Cancelled. Changes were not saved."));
573 parse_fields_from_rule_editor();
575 serv_puts("MSIV listscripts");
576 serv_getln(buf, sizeof(buf));
577 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
578 if (num_scripts < MAX_SCRIPTS) {
579 extract_token(script_names[num_scripts], buf, 0, '|', 64);
580 if (extract_int(buf, 1) > 0) {
581 active_script = num_scripts;
587 bigaction = ibstr("bigaction");
589 if (bigaction == 0) {
590 serv_puts("MSIV setactive||");
591 serv_getln(buf, sizeof buf);
594 else if (bigaction == 1) {
595 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
596 serv_getln(buf, sizeof buf);
599 else if (bigaction == 2) {
600 serv_printf("MSIV setactive|%s|", bstr("active_script"));
601 serv_getln(buf, sizeof buf);
604 if (num_scripts > 0) {
605 for (i=0; i<num_scripts; ++i) {
607 * We only want to save the scripts from the "manually edited scripts"
608 * screen. The script that WebCit generates from its ruleset will be
609 * auto-generated by parse_fields_from_rule_editor() and saved there.
611 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
612 serv_printf("MSIV putscript|%s|", script_names[i]);
613 serv_getln(buf, sizeof buf);
615 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
616 striplt((char*)BSTR(this_name)); /* TODO: get rid of typecast*/
617 serv_printf("%s", bstr(this_name));
624 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
631 * show a list of available scripts to add/remove them
633 void display_add_remove_scripts(char *message)
636 char script_name[256];
638 output_headers(1, 1, 2, 0, 0, 0);
639 wprintf("<div id=\"banner\">\n");
640 wprintf("<img src=\"static/advanpage2_48x.gif\">");
641 wprintf(_("Add or delete scripts"));
645 wprintf("<div id=\"content\" class=\"service\">\n");
647 if (message != NULL) wprintf(message);
649 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
651 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
652 do_template("beginbox");
654 wprintf(_("To create a new script, enter the desired "
655 "script name in the box below and click 'Create'."));
656 wprintf("<br /><br />");
658 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
659 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
660 wprintf(_("Script name: "));
661 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
662 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
663 "</form></center>\n", _("Create"));
665 do_template("endbox");
667 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
668 do_template("beginbox");
669 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
670 _("Return to the script editing screen")
672 do_template("endbox");
674 wprintf("</td><td>");
676 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
677 do_template("beginbox");
679 wprintf(_("To delete an existing script, select the script "
680 "name from the list and click 'Delete'."));
681 wprintf("<br /><br />");
684 "<form method=\"POST\" action=\"delete_script\">\n");
685 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
686 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
688 serv_puts("MSIV listscripts");
689 serv_getln(buf, sizeof buf);
691 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
692 extract_token(script_name, buf, 0, '|', sizeof script_name);
693 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
695 escputs(script_name);
696 wprintf("</option>\n");
700 wprintf("</select><br />\n");
702 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
703 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
704 wprintf("</form></center>\n");
705 do_template("endbox");
707 wprintf("</td></tr></table>\n");
717 void delete_script(void) {
720 serv_printf("MSIV deletescript|%s", bstr("script_name"));
721 serv_getln(buf, sizeof buf);
722 display_add_remove_scripts(&buf[4]);
728 * create a new script
729 * take the web environment script name and create it on the citadel server
731 void create_script(void) {
734 serv_printf("MSIV getscript|%s", bstr("script_name"));
735 serv_getln(buf, sizeof buf);
737 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
740 display_add_remove_scripts(_("A script by that name already exists."));
744 serv_printf("MSIV putscript|%s", bstr("script_name"));
745 serv_getln(buf, sizeof buf);
749 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
753 display_add_remove_scripts(&buf[4]);
759 void display_rules_editor_inner_div(void) {
762 char rules[MAX_RULES][2048];
767 int num_roomnames = 0;
768 int num_roomnames_alloc = 0;
783 memset(rules, 0, sizeof rules);
784 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
785 serv_getln(buf, sizeof buf);
786 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
787 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
788 j = extract_int(buf, 1);
789 remove_token(buf, 0, '|');
790 remove_token(buf, 0, '|');
791 CtdlDecodeBase64(rules[j], buf, strlen(buf));
795 /* load the roomnames */
797 serv_getln(buf, sizeof buf);
799 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
801 if (num_roomnames > num_roomnames_alloc) {
802 num_roomnames_alloc += 250;
803 rooms = realloc(rooms, (num_roomnames_alloc * 128));
805 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
811 * This script should get called by every onChange event...
814 wprintf("<script type=\"text/javascript\"> \n"
816 "var highest_active_rule = (-1); \n"
818 "function UpdateRules() { \n");
820 * Show only the active rows...
822 wprintf(" highest_active_rule = (-1); \n");
823 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
824 wprintf(" if ($('active'+i).checked) { \n"
825 " $('rule' + i).style.display = 'block'; \n"
826 " highest_active_rule = i; \n"
829 " $('rule' + i).style.display = 'none'; \n"
833 * Show only the fields relevant to the rules...
835 wprintf(" for (i=0; i<=highest_active_rule; ++i) { \n"
836 " d = ($('movedown'+i)); \n"
837 " if (i < highest_active_rule) { \n"
838 " d.style.display = 'block'; \n"
841 " d.style.display = 'none'; \n"
843 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
844 " if (d == 'all') { \n"
845 " $('div_size'+i).style.display = 'none'; \n"
846 " $('div_compare'+i).style.display = 'none'; \n"
847 " $('div_nocompare'+i).style.display = 'block'; \n"
849 " else if (d == 'size') { \n"
850 " $('div_size'+i).style.display = 'block'; \n"
851 " $('div_compare'+i).style.display = 'none'; \n"
852 " $('div_nocompare'+i).style.display = 'none'; \n"
855 " $('div_size'+i).style.display = 'none'; \n"
856 " $('div_compare'+i).style.display = 'block'; \n"
857 " $('div_nocompare'+i).style.display = 'none'; \n"
859 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
860 " if (d == 'fileinto') { \n"
861 " $('div_fileinto'+i).style.display = 'block'; \n"
862 " $('div_redirect'+i).style.display = 'none'; \n"
863 " $('div_automsg'+i).style.display = 'none'; \n"
864 " } else if (d == 'redirect') { \n"
865 " $('div_fileinto'+i).style.display = 'none'; \n"
866 " $('div_redirect'+i).style.display = 'block'; \n"
867 " $('div_automsg'+i).style.display = 'none'; \n"
868 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
869 " $('div_fileinto'+i).style.display = 'none'; \n"
870 " $('div_redirect'+i).style.display = 'none'; \n"
871 " $('div_automsg'+i).style.display = 'block'; \n"
873 " $('div_fileinto'+i).style.display = 'none'; \n"
874 " $('div_redirect'+i).style.display = 'none'; \n"
875 " $('div_automsg'+i).style.display = 'none'; \n"
877 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
878 wprintf(" $('div_addrule').style.display = 'block'; \n"
880 " $('div_addrule').style.display = 'none'; \n"
885 * Add a rule (really, just un-hide it)
887 "function AddRule() { \n"
888 " highest_active_rule = highest_active_rule + 1; \n"
889 " $('active'+highest_active_rule).checked = true; \n"
895 "function SwapRules(ra, rb) { \n"
897 " var things = new Array(); \n"
898 " things[0] = 'hfield'; \n"
899 " things[1] = 'compare'; \n"
900 " things[2] = 'htext'; \n"
901 " things[3] = 'action'; \n"
902 " things[4] = 'fileinto'; \n"
903 " things[5] = 'redirect'; \n"
904 " things[6] = 'final'; \n"
905 " things[7] = 'sizecomp'; \n"
906 " things[8] = 'sizeval'; \n"
907 " things[9] = 'automsg'; \n"
909 " for (i=0; i<=9; ++i) { \n"
910 " tempval=$(things[i]+ra).value; \n"
911 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
912 " $(things[i]+rb).value = tempval; \n"
916 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
918 "function DeleteRule(rd) { \n"
919 " for (j=rd; j<=highest_active_rule; ++j) { \n"
920 " SwapRules(j, (j+1)); \n"
922 " $('active'+highest_active_rule).checked = false; \n"
930 wprintf("<table cellpadding=2 width=100%%>");
932 for (i=0; i<MAX_RULES; ++i) {
934 /* Grab our existing values to populate */
935 active = extract_int(rules[i], 0);
936 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
937 extract_token(compare, rules[i], 2, '|', sizeof compare);
938 extract_token(htext, rules[i], 3, '|', sizeof htext);
939 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
940 sizeval = extract_int(rules[i], 5);
941 extract_token(action, rules[i], 6, '|', sizeof action);
942 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
943 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
944 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
945 extract_token(final, rules[i], 10, '|', sizeof final);
947 /* now generate the table row */
949 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
951 ((i%2) ? "DDDDDD" : "FFFFFF")
954 wprintf("<td width=5%% align=\"center\">");
956 wprintf("<div style=\"display:none\">");
957 wprintf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
959 (active ? "checked" : "")
963 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
964 "<img border=\"0\" src=\"static/up_pointer.gif\" "
965 "title=\"%s\"/></a>",
966 i-1, i, _("Move rule up") );
968 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
969 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
970 "title=\"%s\"/></a>",
971 i, i+1, i, _("Move rule down") );
973 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
974 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
975 "title=\"%s\"/></a>",
976 i, i, _("Delete rule") );
980 wprintf("<td width=5%% align=\"center\">");
981 wprintf("<font size=+2>%d</font>", i+1);
984 wprintf("<td width=20%%>%s ", _("If") );
986 char *hfield_values[14][2] = {
987 { "from", _("From") },
988 { "tocc", _("To or Cc") },
989 { "subject", _("Subject") },
990 { "replyto", _("Reply-to") },
991 { "sender", _("Sender") },
992 { "resentfrom", _("Resent-From") },
993 { "resentto", _("Resent-To") },
994 { "envfrom", _("Envelope From") },
995 { "envto", _("Envelope To") },
996 { "xmailer", _("X-Mailer") },
997 { "xspamflag", _("X-Spam-Flag") },
998 { "xspamstatus", _("X-Spam-Status") },
999 { "size", _("Message size") },
1003 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
1005 for (j=0; j<14; ++j) {
1006 wprintf("<option %s value=\"%s\">%s</option>",
1007 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
1008 hfield_values[j][0],
1013 wprintf("</select>");
1016 wprintf("<td width=20%%>");
1018 char *compare_values[6][2] = {
1019 { "contains", _("contains") },
1020 { "notcontains", _("does not contain") },
1022 { "isnot", _("is not") },
1023 { "matches", _("matches") },
1024 { "notmatches", _("does not match") }
1027 wprintf("<div id=\"div_compare%d\">", i);
1028 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1030 for (j=0; j<6; ++j) {
1031 wprintf("<option %s value=\"%s\">%s</option>",
1032 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1033 compare_values[j][0],
1034 compare_values[j][1]
1037 wprintf("</select>");
1039 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1041 wprintf("\"></div>");
1043 wprintf("<div id=\"div_nocompare%d\">", i);
1044 wprintf("%s", _("(All messages)"));
1047 char *sizecomp_values[2][2] = {
1048 { "larger", _("is larger than") },
1049 { "smaller", _("is smaller than") }
1052 wprintf("<div id=\"div_size%d\">", i);
1053 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1055 for (j=0; j<2; ++j) {
1056 wprintf("<option %s value=\"%s\">%s</option>",
1057 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1058 sizecomp_values[j][0],
1059 sizecomp_values[j][1]
1062 wprintf("</select>");
1064 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1071 char *action_values[6][2] = {
1072 { "keep", _("Keep") },
1073 { "discard", _("Discard silently") },
1074 { "reject", _("Reject") },
1075 { "fileinto", _("Move message to") },
1076 { "redirect", _("Forward to") },
1077 { "vacation", _("Vacation") }
1080 wprintf("<td width=20%%>");
1081 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1083 for (j=0; j<6; ++j) {
1084 wprintf("<option %s value=\"%s\">%s</option>",
1085 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1086 action_values[j][0],
1090 wprintf("</select>");
1092 wprintf("<div id=\"div_fileinto%d\">", i);
1093 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1094 for (j=0; j<num_roomnames; ++j) {
1095 wprintf("<option ");
1096 if (!strcasecmp(rooms[j].name, fileinto)) {
1097 wprintf("selected ");
1099 wprintf("value=\"");
1100 escputs(rooms[j].name);
1102 escputs(rooms[j].name);
1103 wprintf("</option>\n");
1105 wprintf("</select>\n");
1108 wprintf("<div id=\"div_redirect%d\">", i);
1109 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1111 wprintf("\"></div>");
1113 wprintf("<div id=\"div_automsg%d\">", i);
1114 wprintf(_("Message:"));
1116 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1118 wprintf("</textarea>");
1123 char *final_values[2][2] = {
1124 { "continue", _("continue processing") },
1125 { "stop", _("stop") }
1128 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1130 wprintf("<td width=20%%>");
1131 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1133 for (j=0; j<2; ++j) {
1134 wprintf("<option %s value=\"%s\">%s</option>",
1135 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1140 wprintf("</select>");
1147 wprintf("</table>");
1148 wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1152 wprintf("<script type=\"text/javascript\"> \n");
1153 wprintf("UpdateRules(); \n");
1154 wprintf("</script> \n");