* we have now several bstrs:
[citadel.git] / webcit / sieve.c
index 3dde76a609fa029e0c17e8910b53fe1757892db5..849af01e08747c3487675ff9b22f1964994bee9d 100644 (file)
@@ -1,19 +1,44 @@
 /* 
  * $Id$
  */
-/**
- * \defgroup Sieve view/edit sieve config
- * \ingroup WebcitDisplayItems
- */
-/*@{*/
+
 #include "webcit.h"
 
 #define MAX_SCRIPTS    100
 #define MAX_RULES      25
 #define RULES_SCRIPT   "__WebCit_Generated_Script__"
 
-/**
- * \brief view/edit sieve config
+
+/*
+ * dummy panel indicating to the user that the server doesn't support Sieve
+ */
+void display_no_sieve(void) {
+
+       output_headers(1, 1, 2, 0, 0, 0);
+
+       wprintf("<div id=\"banner\">\n");
+       wprintf("<img src=\"static/advanpage2_48x.gif\">");
+       wprintf("<h1>");
+       wprintf(_("View/edit server-side mail filters"));
+       wprintf("</h1>\n");
+       wprintf("</div>\n");
+
+       wprintf("<div id=\"content\" class=\"service\">\n");
+
+       wprintf("<div class=\"fix_scrollbar_bug\">"
+               "<table class=\"sieve_background\">"
+               "<tr><td valign=top>\n");
+
+       wprintf(_("This installation of Citadel was built without support for server-side mail filtering."
+               "<br>Please contact your system administrator if you require this feature.<br>"));
+
+       wprintf("</td></tr></table></div>\n");
+       wDumpContent(1);
+}
+
+
+/*
+ * view/edit sieve config
  */
 void display_sieve(void)
 {
@@ -23,7 +48,11 @@ void display_sieve(void)
        char buf[256];
        int i;
        int rules_script_is_active = 0;
-       
+
+       if (!serv_info.serv_supports_sieve) {
+               display_no_sieve();
+               return;
+       }
 
        memset(script_names, 0, sizeof script_names);
 
@@ -193,8 +222,8 @@ void display_sieve(void)
 
 
 
-/**
- * \brief      Helper function for output_sieve_rule() to output strings with quotes escaped
+/*
+ * Helper function for output_sieve_rule() to output strings with quotes escaped
  */
 void osr_sanitize(char *str) {
        int i, len;
@@ -212,8 +241,8 @@ void osr_sanitize(char *str) {
 }
 
 
-/**
- * \brief      Output parseable Sieve script code based on rules input
+/*
+ * Output parseable Sieve script code based on rules input
  */
 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
                        char *action, char *fileinto, char *redirect, char *automsg, char *final,
@@ -405,8 +434,8 @@ void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp,
 
 
 
-/**
- * \brief Translate the fields from the rule editor into something we can save...
+/*
+ * Translate the fields from the rule editor into something we can save...
  */
 void parse_fields_from_rule_editor(void) {
 
@@ -425,12 +454,9 @@ void parse_fields_from_rule_editor(void) {
        char buf[256];
        char fname[256];
        char rule[2048];
-       char *encoded_rule;
+       char encoded_rule[4096];
        char my_addresses[4096];
-       size_t encoded_len;
        
-       encoded_len = 4096;
-       encoded_rule = (char*) malloc (encoded_len);
        /* Enumerate my email addresses in case they are needed for a vacation rule */
        my_addresses[0] = 0;
        serv_puts("GVEA");
@@ -470,46 +496,46 @@ void parse_fields_from_rule_editor(void) {
                strcpy(rule, "");
 
                sprintf(fname, "active%d", i);
-               active = !strcasecmp(bstr(fname), "on") ;
+               active = !strcasecmp(BSTR(fname), "on") ;
 
                if (active) {
 
                        sprintf(fname, "hfield%d", i);
-                       safestrncpy(hfield, bstr(fname), sizeof hfield);
+                       safestrncpy(hfield, BSTR(fname), sizeof hfield);
        
                        sprintf(fname, "compare%d", i);
-                       safestrncpy(compare, bstr(fname), sizeof compare);
+                       safestrncpy(compare, BSTR(fname), sizeof compare);
        
                        sprintf(fname, "htext%d", i);
-                       safestrncpy(htext, bstr(fname), sizeof htext);
+                       safestrncpy(htext, BSTR(fname), sizeof htext);
        
                        sprintf(fname, "sizecomp%d", i);
-                       safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
+                       safestrncpy(sizecomp, BSTR(fname), sizeof sizecomp);
        
                        sprintf(fname, "sizeval%d", i);
-                       sizeval = atoi(bstr(fname));
+                       sizeval = IBSTR(fname);
        
                        sprintf(fname, "action%d", i);
-                       safestrncpy(action, bstr(fname), sizeof action);
+                       safestrncpy(action, BSTR(fname), sizeof action);
        
                        sprintf(fname, "fileinto%d", i);
-                       safestrncpy(fileinto, bstr(fname), sizeof fileinto);
+                       safestrncpy(fileinto, BSTR(fname), sizeof fileinto);
        
                        sprintf(fname, "redirect%d", i);
-                       safestrncpy(redirect, bstr(fname), sizeof redirect);
+                       safestrncpy(redirect, BSTR(fname), sizeof redirect);
        
                        sprintf(fname, "automsg%d", i);
-                       safestrncpy(automsg, bstr(fname), sizeof automsg);
+                       safestrncpy(automsg, BSTR(fname), sizeof automsg);
        
                        sprintf(fname, "final%d", i);
-                       safestrncpy(final, bstr(fname), sizeof final);
+                       safestrncpy(final, BSTR(fname), sizeof final);
        
                        snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
                                active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
                                redirect, automsg, final
                        );
        
-                       CtdlEncodeBase64(&encoded_rule, rule, strlen(rule)+1, &encoded_len, 0);
+                       CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
                        serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
                        output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
                                        action, fileinto, redirect, automsg, final, my_addresses);
@@ -521,13 +547,12 @@ void parse_fields_from_rule_editor(void) {
 
        serv_puts("stop;");
        serv_puts("000");
-       free(encoded_rule);
 }
 
 
 
-/**
- * \brief save sieve config
+/*
+ * save sieve config
  */
 void save_sieve(void) {
        int bigaction;
@@ -538,7 +563,7 @@ void save_sieve(void) {
        char this_name[64];
        char buf[256];
 
-       if (IsEmptyStr(bstr("save_button"))) {
+       if (!havebstr("save_button")) {
                strcpy(WC->ImportantMessage,
                        _("Cancelled.  Changes were not saved."));
                display_main_menu();
@@ -559,7 +584,7 @@ void save_sieve(void) {
                }
        }
 
-       bigaction = atoi(bstr("bigaction"));
+       bigaction = ibstr("bigaction");
 
        if (bigaction == 0) {
                serv_puts("MSIV setactive||");
@@ -588,7 +613,7 @@ void save_sieve(void) {
                                serv_getln(buf, sizeof buf);
                                if (buf[0] == '4') {
                                        snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
-                                       striplt(bstr(this_name));
+                                       striplt((char*)BSTR(this_name)); /* TODO: get rid of typecast*/
                                        serv_printf("%s", bstr(this_name));
                                        serv_puts("000");
                                }
@@ -602,8 +627,8 @@ void save_sieve(void) {
 }
 
 
-/**
- * \brief show a list of available scripts to add/remove them
+/*
+ * show a list of available scripts to add/remove them
  */
 void display_add_remove_scripts(char *message)
 {
@@ -686,8 +711,8 @@ void display_add_remove_scripts(char *message)
 
 
 
-/**
- * \brief delete a script
+/*
+ * delete a script
  */
 void delete_script(void) {
        char buf[256];
@@ -699,8 +724,8 @@ void delete_script(void) {
                
 
 
-/**
- * \brief create a new script
+/*
+ * create a new script
  * take the web environment script name and create it on the citadel server
  */
 void create_script(void) {
@@ -1130,9 +1155,3 @@ void display_rules_editor_inner_div(void) {
 
        free(rooms);
 }
-
-
-
-
-
-/*@}*/