5 * \defgroup Sieve view/edit sieve config
6 * \ingroup WebcitDisplayItems
11 #define MAX_SCRIPTS 100
14 * \brief view/edit sieve config
16 void display_sieve(void)
18 char script_names[MAX_SCRIPTS][64];
20 int active_script = (-1);
25 memset(script_names, 0, sizeof script_names);
27 serv_puts("MSIV listscripts");
28 serv_getln(buf, sizeof(buf));
29 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
30 if (num_scripts < MAX_SCRIPTS) {
31 extract_token(script_names[num_scripts], buf, 0, '|', 64);
32 if (extract_int(buf, 1) > 0) {
33 active_script = num_scripts;
39 output_headers(1, 1, 2, 0, 0, 0);
41 wprintf("<script type=\"text/javascript\"> \n"
43 "var previously_active_script; \n"
45 "function ToggleSievePanels() { \n"
46 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
47 " for (i=0; i<3; ++i) { \n"
49 " $('sievediv' + i).style.display = 'block'; \n"
52 " $('sievediv' + i).style.display = 'none'; \n"
57 "function ToggleScriptPanels() { \n"
58 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
59 " if ($('script_' + previously_active_script)) { \n"
60 " $('script_' + previously_active_script).style.display = 'none'; \n"
62 " $('script_' + d).style.display = 'block'; \n"
63 " previously_active_script = d; \n"
69 wprintf("<div id=\"banner\">\n");
70 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
71 wprintf("<SPAN CLASS=\"titlebar\">");
72 wprintf(_("View/edit server-side mail filters"));
74 wprintf("</TD></TR></TABLE>\n");
75 wprintf("</div>\n<div id=\"content\">\n");
77 wprintf("<div class=\"fix_scrollbar_bug\">"
78 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
79 "<tr><td valign=top>\n");
82 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
84 wprintf(_("When new mail arrives: "));
85 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
87 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
88 wprintf(_("Leave it in my inbox without filtering"));
89 wprintf("</option>\n");
91 wprintf("<option value=\"1\">");
92 wprintf(_("Filter it according to rules selected below"));
93 wprintf("</option>\n");
95 wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
96 wprintf(_("Filter it through a manually edited script (advanced users only)"));
97 wprintf("</option>\n");
103 /* The "no filtering" div */
105 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
106 wprintf("<div align=\"center\"><br /><br />");
107 wprintf(_("Your incoming mail will not be filtered through any scripts."));
108 wprintf("<br /><br /></div>\n");
111 /* The "webcit managed scripts" div */
113 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
114 wprintf("<div align=\"center\"><br /><br />");
115 wprintf("FIXME div 1 isn't finished yet");
116 wprintf("<br /><br /></div>\n");
120 /* The "I'm smart and can write my own Sieve scripts" div */
122 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
124 if (num_scripts > 0) {
125 wprintf(_("The currently active script is: "));
126 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
127 for (i=0; i<num_scripts; ++i) {
128 wprintf("<option %s value=\"%s\">%s</option>\n",
129 ((active_script == i) ? "selected" : ""),
134 wprintf("</select>\n");
137 wprintf(" ");
138 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add/remove scripts"));
142 if (num_scripts > 0) {
143 for (i=0; i<num_scripts; ++i) {
144 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
145 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n", 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);
151 wprintf("</textarea>\n");
156 wprintf("<script type=\"text/javascript\"> \n"
157 "ToggleScriptPanels(); \n"
164 /* The rest of this is common for all panels... */
166 wprintf("<div align=\"center\"><br>");
167 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
169 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
170 wprintf("</div></form>\n");
172 wprintf("</td></tr></table></div>\n");
174 wprintf("<script type=\"text/javascript\"> \n"
175 "ToggleSievePanels(); \n"
185 * \brief save sieve config
187 void save_sieve(void) {
189 char script_names[MAX_SCRIPTS][64];
191 int active_script = (-1);
196 if (strlen(bstr("save_button")) == 0) {
197 strcpy(WC->ImportantMessage,
198 _("Cancelled. Changes were not saved."));
203 serv_puts("MSIV listscripts");
204 serv_getln(buf, sizeof(buf));
205 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
206 if (num_scripts < MAX_SCRIPTS) {
207 extract_token(script_names[num_scripts], buf, 0, '|', 64);
208 if (extract_int(buf, 1) > 0) {
209 active_script = num_scripts;
215 bigaction = atoi(bstr("bigaction"));
217 if (bigaction == 0) {
218 serv_puts("MSIV setactive||");
219 serv_getln(buf, sizeof buf);
222 else if (bigaction == 2) {
223 serv_printf("MSIV setactive|%s|", bstr("active_script"));
224 serv_getln(buf, sizeof buf);
227 if (num_scripts > 0) {
228 for (i=0; i<num_scripts; ++i) {
229 serv_printf("MSIV putscript|%s|", script_names[i]);
230 serv_getln(buf, sizeof buf);
232 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
233 striplt(bstr(this_name));
234 serv_printf("%s", bstr(this_name));
240 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
246 void display_add_remove_scripts(void) {
247 output_headers(1, 1, 2, 0, 0, 0);
249 wprintf("<div id=\"banner\">\n");
250 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
251 wprintf("<SPAN CLASS=\"titlebar\">");
252 wprintf(_("Add/remove Sieve scripts"));
253 wprintf("</SPAN>\n");
254 wprintf("</TD></TR></TABLE>\n");
255 wprintf("</div>\n<div id=\"content\">\n");
257 wprintf("<div class=\"fix_scrollbar_bug\">"
258 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
259 "<tr><td valign=top>\n");
262 /* blah blah go here FIXME */
264 wprintf("</td></tr></table></div>\n");
266 wprintf("<script type=\"text/javascript\"> \n"
267 "ToggleSievePanels(); \n"