managesieve: show warnings received when setting active script
authorCharles Lehner <cel@celehner.com>
Fri, 17 Jul 2015 14:07:44 +0000 (10:07 -0400)
committerCharles Lehner <cel@celehner.com>
Fri, 17 Jul 2015 14:10:54 +0000 (10:10 -0400)
src/plugins/managesieve/managesieve.c
src/plugins/managesieve/managesieve.h
src/plugins/managesieve/sieve_manager.c

index 05b4014..3fd4079 100644 (file)
@@ -673,15 +673,35 @@ static gint sieve_session_recv_msg(Session *session, const gchar *msg)
                sieve_session->state = SIEVE_READY;
                break;
        case SIEVE_SETACTIVE:
-               if (response_is_no(msg)) {
-                       /* error */
+               parse_response((gchar *)msg, &result);
+               if (result.success) {
+                       /* clear status possibly set when setting another
+                        * script active. TODO: give textual feedback */
+                       sieve_error(sieve_session, "");
+
                        command_cb(sieve_session->current_cmd, NULL);
-               } else if (response_is_ok(msg)) {
-                       command_cb(sieve_session->current_cmd, (void*)TRUE);
+               } else if (result.description) {
+                       command_cb(sieve_session->current_cmd,
+                                       result.description);
                } else {
                        log_warning(LOG_PROTOCOL, _("error occurred on SIEVE session\n"));
                }
-               sieve_session->state = SIEVE_READY;
+               if (result.has_octets) {
+                       sieve_session->octets_remaining = result.octets;
+                       sieve_session->state = SIEVE_SETACTIVE_DATA;
+               } else {
+                       sieve_session->state = SIEVE_READY;
+               }
+               break;
+       case SIEVE_SETACTIVE_DATA:
+               /* Dovecot shows a script's warnings when making it active */
+               sieve_session->octets_remaining -= strlen(msg) + 1;
+               if (sieve_session->octets_remaining > 0) {
+                       /* TODO: buffer multi-line message */
+                       sieve_error(sieve_session, msg);
+               } else {
+                       sieve_session->state = SIEVE_READY;
+               }
                break;
        case SIEVE_GETSCRIPT:
                if (response_is_no(msg)) {
index 908ffa4..f5c5fbb 100644 (file)
@@ -71,6 +71,7 @@ typedef enum
        SIEVE_AUTH_CRAM_MD5,
        SIEVE_RENAMESCRIPT,
        SIEVE_SETACTIVE,
+       SIEVE_SETACTIVE_DATA,
        SIEVE_GETSCRIPT,
        SIEVE_GETSCRIPT_DATA,
        SIEVE_PUTSCRIPT,
index 8a786e0..ba19e41 100644 (file)
@@ -245,14 +245,14 @@ static void filter_rename(GtkWidget *widget, SieveManagerPage *page)
 }
 
 static void filter_activated(SieveSession *session, gboolean abort,
-               gboolean success, CommandDataName *cmd_data)
+               const gchar *err, CommandDataName *cmd_data)
 {
        SieveManagerPage *page = cmd_data->page;
        GSList *cur;
 
        if (abort) {
-       } else if (!success) {
-               got_session_error(session, "Unable to set active script", page);
+       } else if (err) {
+               got_session_error(session, err, page);
        } else {
                manager_sessions_foreach(cur, session, page) {
                        filter_set_active(page, cmd_data->filter_name);