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