Removed SessionMsgType enum and its use, since it is useless.
[claws.git] / src / plugins / managesieve / managesieve.c
index f49e29bb7327136b7475489a157cd77e3f873079..6dac66f8f38fc401f6a255a6238445acb1c02100 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "claws.h"
 #include "account.h"
+#include "passwordstore.h"
 #include "gtk/inputdialog.h"
 #include "md5.h"
 #include "utils.h"
@@ -153,7 +154,7 @@ static gboolean sieve_read_chunk_cb(SockInfo *source,
 
                if (read_len == -1 &&
                                session->state == SESSION_DISCONNECTED) {
-                       g_warning ("sock_read: session disconnected\n");
+                       g_warning ("sock_read: session disconnected");
                        if (session->io_tag > 0) {
                                g_source_remove(session->io_tag);
                                session->io_tag = 0;
@@ -162,7 +163,7 @@ static gboolean sieve_read_chunk_cb(SockInfo *source,
                }
 
                if (read_len == 0) {
-                       g_warning("sock_read: received EOF\n");
+                       g_warning("sock_read: received EOF");
                        session->state = SESSION_EOF;
                        return FALSE;
                }
@@ -172,7 +173,7 @@ static gboolean sieve_read_chunk_cb(SockInfo *source,
                        case EAGAIN:
                                return TRUE;
                        default:
-                               g_warning("sock_read: %s\n",
+                               g_warning("sock_read: %s",
                                                g_strerror(errno));
                                session->state = SESSION_ERROR;
                                return FALSE;
@@ -262,7 +263,7 @@ static gint sieve_auth_recv(SieveSession *session, const gchar *msg)
                        tmp = g_base64_encode(session->user, strlen(session->user));
                        g_snprintf(buf, sizeof(buf), "\"%s\"", tmp);
 
-                       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, buf) < 0) {
+                       if (session_send_msg(SESSION(session), buf) < 0) {
                                g_free(tmp);
                                return SE_ERROR;
                        }
@@ -270,8 +271,7 @@ static gint sieve_auth_recv(SieveSession *session, const gchar *msg)
                        log_print(LOG_PROTOCOL, "Sieve> [USERID]\n");
                } else {
                        /* Server rejects AUTH */
-                       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-                                        "\"*\"") < 0)
+                       if (session_send_msg(SESSION(session), "\"*\"") < 0)
                                return SE_ERROR;
                        log_print(LOG_PROTOCOL, "Sieve> *\n");
                }
@@ -306,8 +306,7 @@ static gint sieve_auth_recv(SieveSession *session, const gchar *msg)
                        response = g_strdup_printf("\"%s\"", response64);
                        g_free(response64);
 
-                       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-                                        response) < 0) {
+                       if (session_send_msg(SESSION(session), response) < 0) {
                                g_free(response);
                                return SE_ERROR;
                        }
@@ -315,15 +314,14 @@ static gint sieve_auth_recv(SieveSession *session, const gchar *msg)
                        g_free(response);
                } else {
                        /* Server rejects AUTH */
-                       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-                                        "\"*\"") < 0)
+                       if (session_send_msg(SESSION(session), "\"*\"") < 0)
                                return SE_ERROR;
                        log_print(LOG_PROTOCOL, "Sieve> *\n");
                }
                break;
        default:
                /* stop sieve_auth when no correct authtype */
-               if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, "*") < 0)
+               if (session_send_msg(SESSION(session), "*") < 0)
                        return SE_ERROR;
                log_print(LOG_PROTOCOL, "Sieve> *\n");
                break;
@@ -347,7 +345,7 @@ static gint sieve_auth_login_user_recv(SieveSession *session, const gchar *msg)
                tmp = g_strdup("\"*\"");
        }
 
-       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, tmp) < 0) {
+       if (session_send_msg(SESSION(session), tmp) < 0) {
                g_free(tmp);
                return SE_ERROR;
        }
@@ -364,8 +362,7 @@ static gint sieve_auth_cram_md5(SieveSession *session)
        session->state = SIEVE_AUTH;
        session->auth_type = SIEVEAUTH_CRAM_MD5;
 
-       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-                               "Authenticate \"CRAM-MD5\"") < 0)
+       if (session_send_msg(SESSION(session), "Authenticate \"CRAM-MD5\"") < 0)
                return SE_ERROR;
        log_print(LOG_PROTOCOL, "Sieve> Authenticate CRAM-MD5\n");
 
@@ -388,7 +385,7 @@ static gint sieve_auth_plain(SieveSession *session)
        out = g_strconcat("Authenticate \"PLAIN\" \"", b64buf, "\"", NULL);
        g_free(b64buf);
 
-       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, out) < 0) {
+       if (session_send_msg(SESSION(session), out) < 0) {
                g_free(out);
                return SE_ERROR;
        }
@@ -405,8 +402,7 @@ static gint sieve_auth_login(SieveSession *session)
        session->state = SIEVE_AUTH;
        session->auth_type = SIEVEAUTH_LOGIN;
 
-       if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-                               "Authenticate \"LOGIN\"") < 0)
+       if (session_send_msg(SESSION(session), "Authenticate \"LOGIN\"") < 0)
                return SE_ERROR;
        log_print(LOG_PROTOCOL, "Sieve> Authenticate LOGIN\n");
 
@@ -551,7 +547,7 @@ static gint sieve_pop_send_queue(SieveSession *session)
        log_send(session, cmd);
        session->state = cmd->next_state;
        session->current_cmd = cmd;
-       if (session_send_msg(SESSION(session), SESSION_SEND, cmd->msg) < 0)
+       if (session_send_msg(SESSION(session), cmd->msg) < 0)
                return SE_ERROR;
 
        return SE_OK;
@@ -620,7 +616,7 @@ static void parse_response(gchar *msg, SieveResult *result)
        }
 
        /* response code */
-       if (msg[0] == '(' && (end = strchr(msg, ')'))) {
+       if (msg && msg[0] == '(' && (end = strchr(msg, ')'))) {
                msg++;
                *end++ = '\0';
                result->code =
@@ -635,7 +631,7 @@ static void parse_response(gchar *msg, SieveResult *result)
        }
 
        /* s2c octets */
-       if (msg[0] == '{' && (end = strchr(msg, '}'))) {
+       if (msg && msg[0] == '{' && (end = strchr(msg, '}'))) {
                msg++;
                *end++ = '\0';
                if (msg[0] == '0' && msg+1 == end) {
@@ -654,7 +650,7 @@ static void parse_response(gchar *msg, SieveResult *result)
        }
 
        /* text */
-       if (*msg) {
+       if (msg && *msg) {
                unquote_inplace(msg);
                result->description = msg;
        } else {
@@ -695,7 +691,7 @@ static gint sieve_session_recv_msg(Session *session, const gchar *msg)
                                        sieve_session->config->tls_type != SIEVE_TLS_NO) {
                                if (sieve_session->capability.starttls) {
                                        log_print(LOG_PROTOCOL, "Sieve> STARTTLS\n");
-                                       session_send_msg(session, SESSION_SEND, "STARTTLS");
+                                       session_send_msg(session, "STARTTLS");
                                        sieve_session->state = SIEVE_STARTTLS;
                                } else if (sieve_session->config->tls_type == SIEVE_TLS_YES) {
                                        log_warning(LOG_PROTOCOL, "Sieve: does not support STARTTLS\n");
@@ -956,7 +952,7 @@ static gint sieve_cmd_noop(SieveSession *session)
 {
        log_print(LOG_PROTOCOL, "Sieve> NOOP\n");
        session->state = SIEVE_NOOP;
-       if (session_send_msg(SESSION(session), SESSION_SEND, "NOOP") < 0) {
+       if (session_send_msg(SESSION(session), "NOOP") < 0) {
                session->state = SIEVE_ERROR;
                session->error = SE_ERROR;
                return 1;
@@ -999,7 +995,9 @@ static gint sieve_session_connect(SieveSession *session)
 {
        session->state = SIEVE_CAPABILITIES;
        session->authenticated = FALSE;
+#ifdef USE_GNUTLS
        session->tls_init_done = FALSE;
+#endif
        return session_connect(SESSION(session), session->host,
                        session->port);
 }
@@ -1037,7 +1035,9 @@ static void sieve_session_reset(SieveSession *session)
        session->current_cmd = NULL;
        session->send_queue = NULL;
        session->state = SIEVE_CAPABILITIES;
+#ifdef USE_GNUTLS
        session->tls_init_done = FALSE;
+#endif
        session->avail_auth_type = 0;
        session->auth_type = 0;
        session->config = config;
@@ -1051,10 +1051,10 @@ static void sieve_session_reset(SieveSession *session)
                g_free(session->pass);
        if (config->auth == SIEVEAUTH_NONE) {
                session->pass = NULL;
-       } else if (reuse_auth && account->passwd) {
-               session->pass = g_strdup(account->passwd);
-       } else if (config->passwd && config->passwd[0]) {
-               session->pass = g_strdup(config->passwd);
+       } else if (reuse_auth && (session->pass = passwd_store_get_account(
+                                account->account_id, PWS_ACCOUNT_RECV))) {
+       } else if ((session->pass = passwd_store_get_account(
+                                account->account_id, "sieve"))) {
        } else if (password_get(session->user, session->host, "sieve",
                                session->port, &session->pass)) {
        } else {
@@ -1145,7 +1145,7 @@ static void sieve_queue_send(SieveSession *session, SieveState next_state,
                session->current_cmd = cmd;
                session->state = next_state;
                log_send(session, cmd);
-               if (session_send_msg(SESSION(session), SESSION_SEND, cmd->msg) < 0) {
+               if (session_send_msg(SESSION(session), cmd->msg) < 0) {
                        /* error */
                }
        }