Rules editor now encodes the form fields and saves them
[citadel.git] / webcit / sieve.c
1 /* 
2  * $Id: $
3  */
4 /**
5  * \defgroup Sieve view/edit sieve config
6  * \ingroup WebcitDisplayItems
7  */
8 /*@{*/
9 #include "webcit.h"
10
11 #define MAX_SCRIPTS     100
12 #define MAX_RULES       25
13 #define RULES_SCRIPT    "__WebCit_Generated_Script__"
14
15 /**
16  * \brief view/edit sieve config
17  */
18 void display_sieve(void)
19 {
20         char script_names[MAX_SCRIPTS][64];
21         int num_scripts = 0;
22         int active_script = (-1);
23         char buf[256];
24         int i;
25         int rules_script_is_active = 0;
26         
27
28         memset(script_names, 0, sizeof script_names);
29
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;
39                                 }
40                         }
41                         ++num_scripts;
42                 }
43         }
44
45         output_headers(1, 1, 2, 0, 0, 0);
46
47         wprintf("<script type=\"text/javascript\">                                      \n"
48                 "                                                                       \n"
49                 "var previously_active_script;                                          \n"
50                 "                                                                       \n"
51                 "function ToggleSievePanels() {                                         \n"
52                 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
53                 " for (i=0; i<3; ++i) {                                                 \n"
54                 "  if (i == d) {                                                        \n"
55                 "   $('sievediv' + i).style.display = 'block';                          \n"
56                 "  }                                                                    \n"
57                 "  else {                                                               \n"
58                 "   $('sievediv' + i).style.display = 'none';                           \n"
59                 "  }                                                                    \n"
60                 " }                                                                     \n"
61                 "}                                                                      \n"
62                 "                                                                       \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"
67                 " }                                                                     \n"
68                 " $('script_' + d).style.display = 'block';                             \n"
69                 " previously_active_script = d;                                         \n"
70                 "}                                                                      \n"
71                 "                                                                       \n"
72                 "</script>                                                              \n"
73         );
74
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"));
80         wprintf("</SPAN>\n");
81         wprintf("</TD></TR></TABLE>\n");
82         wprintf("</div>\n<div id=\"content\">\n");
83
84         wprintf("<div class=\"fix_scrollbar_bug\">"
85                 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
86                 "<tr><td valign=top>\n");
87
88
89         wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
90
91         wprintf(_("When new mail arrives: "));
92         wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
93
94         wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
95         wprintf(_("Leave it in my inbox without filtering"));
96         wprintf("</option>\n");
97
98         wprintf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
99         wprintf(_("Filter it according to rules selected below"));
100         wprintf("</option>\n");
101
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");
106
107         wprintf("</select>");
108
109
110
111         /* The "no filtering" div */
112
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");
117         wprintf("</div>\n");
118
119         /* The "webcit managed scripts" div */
120
121         wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
122         display_rules_editor_inner_div();
123         wprintf("</div>\n");
124
125         /* The "I'm smart and can write my own Sieve scripts" div */
126
127         wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
128
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" : ""),
136                                         script_names[i],
137                                         script_names[i]
138                                 );
139                         }
140                 }
141                 wprintf("</select>\n");
142         }
143
144         wprintf("&nbsp;&nbsp;&nbsp;");
145         wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
146
147         wprintf("<br />\n");
148
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",
154                                         script_names[i]);
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);
159                                 }
160                                 wprintf("</textarea>\n");
161                                 wprintf("</div>\n");
162                         }
163                 }
164         }
165
166         wprintf("<script type=\"text/javascript\">      \n"
167                 "ToggleScriptPanels();                  \n"
168                 "</script>                              \n"
169         );
170
171         wprintf("</div>\n");
172
173
174         /* The rest of this is common for all panels... */
175
176         wprintf("<div align=\"center\"><br>");
177         wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
178         wprintf("&nbsp;");
179         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
180         wprintf("</div></form>\n");
181
182         wprintf("</td></tr></table></div>\n");
183
184         wprintf("<script type=\"text/javascript\">      \n"
185                 "ToggleSievePanels();                   \n"
186                 "</script>                              \n"
187         );
188
189         wDumpContent(1);
190
191 }
192
193
194
195 /**
196  * \brief Translate the fields from the rule editor into something we can save...
197  */
198 void parse_fields_from_rule_editor(void) {
199
200         int active;
201         char hfield[256];
202         char compare[32];
203         char htext[256];
204         char sizecomp[32];
205         int sizeval;
206         char action[32];
207         char fileinto[128];
208         char redirect[256];
209         char automsg[1024];
210         char final[32];
211
212         int i;
213         char buf[256];
214         char fname[256];
215         char rule[2048];
216         char encoded_rule[4096];
217
218         serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
219         serv_getln(buf, sizeof buf);
220         if (buf[0] != '4') {
221                 return;
222         }
223
224         serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
225         serv_puts("# ");
226         serv_puts("# Do not attempt to manually edit it.  If you do so,");
227         serv_puts("# your changes will be overwritten the next time WebCit");
228         serv_puts("# saves its mail filtering rule set.  If you really want");
229         serv_puts("# to use these rules as the basis for another script,");
230         serv_puts("# copy them to another script and save that instead.");
231         serv_puts("");
232
233         for (i=0; i<MAX_RULES; ++i) {
234                 
235                 strcpy(rule, "");
236
237                 sprintf(fname, "active%d", i);
238                 active = atoi(bstr(fname));
239
240                 sprintf(fname, "hfield%d", i);
241                 safestrncpy(hfield, bstr(fname), sizeof hfield);
242
243                 sprintf(fname, "compare%d", i);
244                 safestrncpy(compare, bstr(fname), sizeof compare);
245
246                 sprintf(fname, "htext%d", i);
247                 safestrncpy(htext, bstr(fname), sizeof htext);
248
249                 sprintf(fname, "sizecomp%d", i);
250                 safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
251
252                 sprintf(fname, "sizeval%d", i);
253                 sizeval = atoi(bstr(fname));
254
255                 sprintf(fname, "action%d", i);
256                 safestrncpy(action, bstr(fname), sizeof action);
257
258                 sprintf(fname, "fileinto%d", i);
259                 safestrncpy(fileinto, bstr(fname), sizeof fileinto);
260
261                 sprintf(fname, "redirect%d", i);
262                 safestrncpy(redirect, bstr(fname), sizeof redirect);
263
264                 sprintf(fname, "automsg%d", i);
265                 safestrncpy(automsg, bstr(fname), sizeof automsg);
266
267                 sprintf(fname, "final%d", i);
268                 safestrncpy(final, bstr(fname), sizeof final);
269
270                 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
271                         active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
272                         redirect, automsg, final
273                 );
274
275                 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
276                 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
277
278                 /* FIXME: this is where we need to generate Sieve code based on the rule */
279
280
281         }
282
283         serv_puts("000");
284
285 }
286
287
288
289 /**
290  * \brief save sieve config
291  */
292 void save_sieve(void) {
293         int bigaction;
294         char script_names[MAX_SCRIPTS][64];
295         int num_scripts = 0;
296         int active_script = (-1);
297         int i;
298         char this_name[64];
299         char buf[256];
300
301         if (strlen(bstr("save_button")) == 0) {
302                 strcpy(WC->ImportantMessage,
303                         _("Cancelled.  Changes were not saved."));
304                 display_main_menu();
305                 return;
306         }
307
308         parse_fields_from_rule_editor();
309
310         serv_puts("MSIV listscripts");
311         serv_getln(buf, sizeof(buf));
312         if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
313                 if (num_scripts < MAX_SCRIPTS) {
314                         extract_token(script_names[num_scripts], buf, 0, '|', 64);
315                         if (extract_int(buf, 1) > 0) {
316                                 active_script = num_scripts;
317                         }
318                         ++num_scripts;
319                 }
320         }
321
322         bigaction = atoi(bstr("bigaction"));
323
324         if (bigaction == 0) {
325                 serv_puts("MSIV setactive||");
326                 serv_getln(buf, sizeof buf);
327         }
328
329         else if (bigaction == 1) {
330                 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
331                 serv_getln(buf, sizeof buf);
332         }
333
334         else if (bigaction == 2) {
335                 serv_printf("MSIV setactive|%s|", bstr("active_script"));
336                 serv_getln(buf, sizeof buf);
337         }
338
339         if (num_scripts > 0) {
340                 for (i=0; i<num_scripts; ++i) {
341                         /*
342                          * We only want to save the scripts from the "manually edited scripts"
343                          * screen.  The script that WebCit generates from its ruleset will be
344                          * auto-generated by parse_fields_from_rule_editor() and saved there.
345                          */
346                         if (strcasecmp(script_names[i], RULES_SCRIPT)) {
347                                 serv_printf("MSIV putscript|%s|", script_names[i]);
348                                 serv_getln(buf, sizeof buf);
349                                 if (buf[0] == '4') {
350                                         snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
351                                         striplt(bstr(this_name));
352                                         serv_printf("%s", bstr(this_name));
353                                         serv_puts("000");
354                                 }
355                         }
356                 }
357         }
358
359         strcpy(WC->ImportantMessage, _("Your changes have been saved."));
360         display_main_menu();
361         return;
362 }
363
364
365 /**
366  * \brief show a list of available scripts to add/remove them
367  */
368 void display_add_remove_scripts(char *message)
369 {
370         char buf[256];
371         char script_name[256];
372
373         output_headers(1, 1, 2, 0, 0, 0);
374         wprintf("<div id=\"banner\">\n");
375         wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
376                 "<td>"
377                 "<span class=\"titlebar\">"
378                 "<img src=\"static/advanpage2_48x.gif\">");
379         wprintf(_("Add or delete scripts"));
380         wprintf("</span></td></tr></table>\n"
381                 "</div>\n<div id=\"content\">\n"
382         );
383
384         if (message != NULL) wprintf(message);
385
386         wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
387
388         svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
389         do_template("beginbox");
390
391         wprintf(_("To create a new script, enter the desired "
392                 "script name in the box below and click 'Create'."));
393         wprintf("<br /><br />");
394
395         wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
396         wprintf(_("Script name: "));
397         wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
398                 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
399                 "</form></center>\n", _("Create"));
400
401         do_template("endbox");
402
403         svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
404         do_template("beginbox");
405         wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
406                 _("Return to the script editing screen")
407         );
408         do_template("endbox");
409
410         wprintf("</td><td>");
411
412         svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
413         do_template("beginbox");
414
415         wprintf(_("To delete an existing script, select the script "
416                 "name from the list and click 'Delete'."));
417         wprintf("<br /><br />");
418         
419         wprintf("<center>"
420                 "<form method=\"POST\" action=\"delete_script\">\n");
421         wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
422
423         serv_puts("MSIV listscripts");
424         serv_getln(buf, sizeof buf);
425         if (buf[0] == '1') {
426                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
427                         extract_token(script_name, buf, 0, '|', sizeof script_name);
428                         if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
429                                 wprintf("<option>");
430                                 escputs(script_name);
431                                 wprintf("</option>\n");
432                         }
433                 }
434         }
435         wprintf("</select><br />\n");
436
437         wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
438                 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
439         wprintf("</form></center>\n");
440         do_template("endbox");
441
442         wprintf("</td></tr></table>\n");
443
444         wDumpContent(1);
445 }
446
447
448
449 /**
450  * \brief delete a script
451  */
452 void delete_script(void) {
453         char buf[256];
454
455         serv_printf("MSIV deletescript|%s", bstr("script_name"));
456         serv_getln(buf, sizeof buf);
457         display_add_remove_scripts(&buf[4]);
458 }
459                 
460
461
462 /**
463  * \brief create a new script
464  * take the web environment script name and create it on the citadel server
465  */
466 void create_script(void) {
467         char buf[256];
468
469         serv_printf("MSIV getscript|%s", bstr("script_name"));
470         serv_getln(buf, sizeof buf);
471         if (buf[0] == '1') {
472                 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
473                         /* flush */
474                 }
475                 display_add_remove_scripts(_("A script by that name already exists."));
476                 return;
477         }
478         
479         serv_printf("MSIV putscript|%s", bstr("script_name"));
480         serv_getln(buf, sizeof buf);
481         if (buf[0] == '4') {
482                 serv_puts("keep;");
483                 serv_puts("000");
484                 display_add_remove_scripts(_("A new script has been created.  Return to the script editing screen to edit and activate it."));
485                 return;
486         }
487
488         display_add_remove_scripts(&buf[4]);
489 }
490
491
492
493
494 void display_rules_editor_inner_div(void) {
495         int i, j;
496         char buf[256];
497
498         struct {
499                 char name[128];
500         } *rooms = NULL;
501         int num_roomnames = 0;
502         int num_roomnames_alloc = 0;
503
504
505         /* load the roomnames */
506         serv_puts("LKRA");
507         serv_getln(buf, sizeof buf);
508         if (buf[0] == '1') {
509                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
510                         ++num_roomnames;
511                         if (num_roomnames > num_roomnames_alloc) {
512                                 num_roomnames_alloc += 250;
513                                 rooms = realloc(rooms, (num_roomnames_alloc * 128));
514                         }
515                         extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
516                 }
517         }
518
519
520 /*
521  * This script should get called by every onChange event...
522  *
523  */
524         wprintf("<script type=\"text/javascript\">                                      \n"
525                 "                                                                       \n"
526                 "var highest_active_rule = (-1);                                        \n"
527                 "                                                                       \n"
528                 "function UpdateRules() {                                               \n"
529                 "  for (i=0; i<%d; ++i) {                                               \n", MAX_RULES);
530         wprintf("    d = ($('movedown'+i));                                             \n"
531                 "    if (i < highest_active_rule) {                                     \n"
532                 "      d.style.display = 'block';                                       \n"
533                 "    }                                                                  \n"
534                 "    else {                                                             \n"
535                 "      d.style.display = 'none';                                        \n"
536                 "    }                                                                  \n"
537                 "    d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value);    \n"
538                 "    if (d == 'all') {                                                  \n"
539                 "      $('div_size'+i).style.display = 'none';                          \n"
540                 "      $('div_compare'+i).style.display = 'none';                       \n"
541                 "      $('div_nocompare'+i).style.display = 'block';                    \n"
542                 "    }                                                                  \n"
543                 "    else if (d == 'size') {                                            \n"
544                 "      $('div_size'+i).style.display = 'block';                         \n"
545                 "      $('div_compare'+i).style.display = 'none';                       \n"
546                 "      $('div_nocompare'+i).style.display = 'none';                     \n"
547                 "    }                                                                  \n"
548                 "    else {                                                             \n"
549                 "      $('div_size'+i).style.display = 'none';                          \n"
550                 "      $('div_compare'+i).style.display = 'block';                      \n"
551                 "      $('div_nocompare'+i).style.display = 'none';                     \n"
552                 "    }                                                                  \n"
553                 "    d = ($('action'+i).options[$('action'+i).selectedIndex].value);    \n"
554                 "    if (d == 'fileinto') {                                             \n"
555                 "      $('div_fileinto'+i).style.display = 'block';                     \n"
556                 "      $('div_redirect'+i).style.display = 'none';                      \n"
557                 "      $('div_automsg'+i).style.display = 'none';                       \n"
558                 "    } else if (d == 'redirect') {                                      \n"
559                 "      $('div_fileinto'+i).style.display = 'none';                      \n"
560                 "      $('div_redirect'+i).style.display = 'block';                     \n"
561                 "      $('div_automsg'+i).style.display = 'none';                       \n"
562                 "    } else if ((d == 'reject') || (d == 'vacation'))  {                \n"
563                 "      $('div_fileinto'+i).style.display = 'none';                      \n"
564                 "      $('div_redirect'+i).style.display = 'none';                      \n"
565                 "      $('div_automsg'+i).style.display = 'block';                      \n"
566                 "    } else {                                                           \n"
567                 "      $('div_fileinto'+i).style.display = 'none';                      \n"
568                 "      $('div_redirect'+i).style.display = 'none';                      \n"
569                 "      $('div_automsg'+i).style.display = 'none';                       \n"
570                 "    }                                                                  \n"
571                 "    if (highest_active_rule < %d) {                                    \n", MAX_RULES-1 );
572         wprintf("      $('div_addrule').style.display = 'block';                        \n"
573                 "    } else {                                                           \n"
574                 "      $('div_addrule').style.display = 'none';                         \n"
575                 "    }                                                                  \n"
576                 "  }                                                                    \n"
577         );
578 /*
579  * Show only the active rows...
580  */
581         wprintf("  highest_active_rule = (-1);                                          \n");
582         wprintf("  for (i=0; i<%d; ++i) {                                               \n", MAX_RULES);
583         wprintf("   if ($('active'+i).checked) {                                        \n"
584                 "     $('rule' + i).style.display = 'block';                            \n"
585                 "     highest_active_rule = i;                                          \n"
586                 "   }                                                                   \n"
587                 "   else {                                                              \n"
588                 "     $('rule' + i).style.display = 'none';                             \n"
589                 "   }                                                                   \n"
590                 "  }                                                                    \n"
591                 "}                                                                      \n"
592 /*
593  * Add a rule (really, just un-hide it)
594  */
595                 "function AddRule() {                                                   \n"
596                 "  highest_active_rule = highest_active_rule + 1;                       \n"
597                 "  $('active'+highest_active_rule).checked = true;                      \n"
598                 "  UpdateRules();                                                       \n"
599                 "}                                                                      \n"
600 /*
601  * Swap two rules
602  */
603                 "function SwapRules(ra, rb) {                                           \n"
604                 "                                                                       \n"
605                 "  var things = new Array();                                            \n"
606                 "  things[0] = 'hfield';                                                \n"
607                 "  things[1] = 'compare';                                               \n"
608                 "  things[2] = 'htext';                                                 \n"
609                 "  things[3] = 'action';                                                \n"
610                 "  things[4] = 'fileinto';                                              \n"
611                 "  things[5] = 'redirect';                                              \n"
612                 "  things[6] = 'final';                                                 \n"
613                 "  things[7] = 'sizecomp';                                              \n"
614                 "  things[8] = 'sizeval';                                               \n"
615                 "  things[9] = 'automsg';                                               \n"
616                 "                                                                       \n"
617                 "  for (i=0; i<=9; ++i) {                                               \n"
618                 "    tempval=$(things[i]+ra).value;                                     \n"
619                 "    $(things[i]+ra).value = $(things[i]+rb).value;                     \n"
620                 "    $(things[i]+rb).value = tempval;                                   \n"
621                 "  }                                                                    \n"
622                 "}                                                                      \n"
623 /*
624  * Delete a rule (percolate the deleted rule out to the end,
625  *                and then decrement highest_active_rule)
626  */
627                 "function DeleteRule(rd) {                                              \n"
628                 "  for (i=rd; i<highest_active_rule; ++i) {                             \n"
629                 "    SwapRules(i, (i+1));                                               \n"
630                 "  }                                                                    \n"
631                 "  $('active'+highest_active_rule).checked = false;                     \n"
632                 "}                                                                      \n"
633                 "</script>                                                              \n"
634         );
635
636
637         wprintf("<br />");
638
639         wprintf("<table cellpadding=2 width=100%%>");
640
641         for (i=0; i<MAX_RULES; ++i) {
642                 
643                 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
644                         i,
645                         ((i%2) ? "DDDDDD" : "FFFFFF")
646                 );
647
648                 wprintf("<td width=5%% align=\"center\">");
649
650                 wprintf("<div style=\"display:none\">");
651                 wprintf("<input type=\"checkbox\" id=\"active%d\">", i);
652                 wprintf("</div>");
653
654                 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
655                         "<img border=\"0\" src=\"static/up_pointer.gif\" "
656                         "title=\"%s\"/></a>",
657                         i-1, i, _("Move rule up") );
658
659                 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
660                         "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
661                         "title=\"%s\"/></a>",
662                         i, i+1, i, _("Move rule down") );
663
664                 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
665                         "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
666                         "title=\"%s\"/></a>",
667                         i, i, _("Delete rule") );
668
669                 wprintf("</td>");
670
671                 wprintf("<td width=5%% align=\"center\">");
672                 wprintf("<font size=+2>%d</font>", i+1);
673                 wprintf("</td>");
674
675                 wprintf("<td width=20%%>%s ", _("If") );
676
677                 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
678                         i, i);
679                 wprintf("<option value=\"from\">%s</option>", _("From"));
680                 wprintf("<option value=\"tocc\">%s</option>", _("To or Cc"));
681                 wprintf("<option value=\"subject\">%s</option>", _("Subject"));
682                 wprintf("<option value=\"replyto\">%s</option>", _("Reply-to"));
683                 wprintf("<option value=\"sender\">%s</option>", _("Sender"));
684                 wprintf("<option value=\"resentfrom\">%s</option>", _("Resent-From"));
685                 wprintf("<option value=\"resentto\">%s</option>", _("Resent-To"));
686                 wprintf("<option value=\"envfrom\">%s</option>", _("Envelope From"));
687                 wprintf("<option value=\"envto\">%s</option>", _("Envelope To"));
688                 wprintf("<option value=\"xmailer\">%s</option>", _("X-Mailer"));
689                 wprintf("<option value=\"xspamflag\">%s</option>", _("X-Spam-Flag"));
690                 wprintf("<option value=\"xspamstatus\">%s</option>", _("X-Spam-Status"));
691                 wprintf("<option value=\"size\">%s</option>", _("Message size"));
692                 wprintf("<option value=\"all\">%s</option>", _("All"));
693                 wprintf("</select>");
694                 wprintf("</td>");
695
696                 wprintf("<td width=20%%>");
697
698                 wprintf("<div id=\"div_compare%d\">", i);
699                 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
700                         i, i);
701                 wprintf("<option value=\"contains\">%s</option>", _("contains"));
702                 wprintf("<option value=\"notcontains\">%s</option>", _("does not contain"));
703                 wprintf("<option value=\"is\">%s</option>", _("is"));
704                 wprintf("<option value=\"isnot\">%s</option>", _("is not"));
705                 wprintf("</select>");
706
707                 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\">", i, i);
708                 wprintf("</div>");
709
710                 wprintf("<div id=\"div_nocompare%d\">", i);
711                 wprintf("%s", _("(All messages)"));
712                 wprintf("</div>");
713
714                 wprintf("<div id=\"div_size%d\">", i);
715                 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
716                         i, i);
717                 wprintf("<option value=\"larger\">%s</option>", _("is larger than"));
718                 wprintf("<option value=\"smaller\">%s</option>", _("is smaller than"));
719                 wprintf("</select>");
720
721                 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\">", i, i);
722                 wprintf("bytes");
723                 wprintf("</div>");
724
725                 wprintf("</td>");
726
727                 wprintf("<td width=20%%>");
728                 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
729                         i, i);
730                 wprintf("<option value=\"keep\">%s</option>", _("Keep"));
731                 wprintf("<option value=\"discard\">%s</option>", _("Discard silently"));
732                 wprintf("<option value=\"reject\">%s</option>", _("Reject"));
733                 wprintf("<option value=\"fileinto\">%s</option>", _("Move message to"));
734                 wprintf("<option value=\"redirect\">%s</option>", _("Forward to"));
735                 wprintf("<option value=\"vacation\">%s</option>", _("Vacation"));
736                 wprintf("</select>");
737
738                 wprintf("<div id=\"div_fileinto%d\">", i);
739                 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
740                 for (j=0; j<num_roomnames; ++j) {
741                         wprintf("<option ");
742                         if (!strcasecmp(rooms[j].name, "Mail")) {
743                                 wprintf("selected ");
744                         }
745                         wprintf("value=\"");
746                         urlescputs(rooms[j].name);
747                         wprintf("\">");
748                         escputs(rooms[j].name);
749                         wprintf("</option>\n");
750                 }
751                 wprintf("</select>\n");
752                 wprintf("</div>");
753
754                 wprintf("<div id=\"div_redirect%d\">", i);
755                 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\">", i, i);
756                 wprintf("</div>");
757
758                 wprintf("<div id=\"div_automsg%d\">", i);
759                 wprintf(_("Message:"));
760                 wprintf("<br />");
761                 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
762                 wprintf("</textarea>");
763                 wprintf("</div>");
764
765                 wprintf("</td>");
766
767
768
769                 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
770
771                 wprintf("<td width=20%%>");
772                 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
773                         i, i);
774                 wprintf("<option value=\"continue\">%s</option>", _("continue processing"));
775                 wprintf("<option value=\"stop\">%s</option>", _("stop"));
776                 wprintf("</select>");
777                 wprintf("</td>");
778
779                 wprintf("</tr>\n");
780
781         }
782
783         wprintf("</table>");
784         wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">Add rule</a><br /></div>\n");
785
786         wprintf("<script type=\"text/javascript\">                                      \n"
787                 "UpdateRules();                                                         \n"
788                 "</script>                                                              \n"
789         );
790
791         free(rooms);
792 }
793
794
795
796
797
798
799 /*@}*/