Fix CID 1491365: resource leak.
[claws.git] / src / imap.c
index dd0ab1deb7a682e2a1fda3aa7223a96223d6d137..fdd048be63a484eda351e4ad57eac65aada6410f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
+ * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -748,7 +748,7 @@ static void imap_handle_error(Session *session, const gchar *server, int libetpa
                break;
 #ifdef USE_GNUTLS
        case MAILIMAP_ERROR_SSL:
-               MY_LOG_WARNING(g_strconcat(_("IMAP error on %s:"), " ", _("SSL/TLS error"), "\n", NULL), session_server)
+               MY_LOG_WARNING(g_strconcat(_("IMAP error on %s:"), " ", _("TLS error"), "\n", NULL), session_server)
                break;
 #endif
        default:
@@ -951,14 +951,14 @@ static gint imap_auth(IMAPSession *session, const gchar *user, const gchar *pass
                        ok = imap_cmd_login(session, user, pass, "SCRAM-SHA-1");
                if (ok == MAILIMAP_ERROR_LOGIN && imap_has_capability(session, "PLAIN"))
                        ok = imap_cmd_login(session, user, pass, "PLAIN");
-               if (ok == MAILIMAP_ERROR_LOGIN && imap_has_capability(session, "XOAUTH2"))
-                       ok = imap_cmd_login(session, user, pass, "XOAUTH2");
                if (ok == MAILIMAP_ERROR_LOGIN && imap_has_capability(session, "LOGIN"))
                        ok = imap_cmd_login(session, user, pass, "LOGIN");
                if (ok == MAILIMAP_ERROR_LOGIN && imap_has_capability(session, "GSSAPI"))
                        ok = imap_cmd_login(session, user, pass, "GSSAPI");
                if (ok == MAILIMAP_ERROR_LOGIN) /* we always try plaintext login before giving up */
                        ok = imap_cmd_login(session, user, pass, "plaintext");
+               if (ok == MAILIMAP_ERROR_LOGIN && imap_has_capability(session, "XOAUTH2"))
+                       ok = imap_cmd_login(session, user, pass, "XOAUTH2");
        }
 
        if (ok == MAILIMAP_NO_ERROR)
@@ -994,6 +994,11 @@ static gint imap_auth(IMAPSession *session, const gchar *user, const gchar *pass
                                     "LOGIN SASL plugin is installed.");
                }
 
+               if (type == IMAP_AUTH_OAUTH2) {
+                       ext_info = _("\n\nOAuth2 error. Check and correct your OAuth2 "
+                                    "account preferences.");
+               } 
+
                if (time(NULL) - last_login_err > 10) {
                        if (!prefs_common.no_recv_err_panel) {
                                alertpanel_error_log(_("Connection to %s failed: "
@@ -1170,7 +1175,7 @@ static IMAPSession *imap_session_new(Folder * folder,
        if (account->ssl_imap != SSL_NONE) {
                if (alertpanel_full(_("Insecure connection"),
                        _("This connection is configured to be secured "
-                         "using SSL/TLS, but SSL/TLS is not available "
+                         "using TLS, but TLS is not available "
                          "in this build of Claws Mail. \n\n"
                          "Do you want to continue connecting to this "
                          "server? The communication would not be "
@@ -1243,7 +1248,7 @@ static IMAPSession *imap_session_new(Folder * folder,
        else {
 #ifdef USE_GNUTLS
                if (r == MAILIMAP_ERROR_SSL)
-                       log_error(LOG_PROTOCOL, _("SSL/TLS handshake failed\n"));
+                       log_error(LOG_PROTOCOL, _("TLS handshake failed\n"));
                else
 #endif
                        imap_handle_error(NULL, account->recv_server, r);
@@ -1289,6 +1294,8 @@ static IMAPSession *imap_session_new(Folder * folder,
                                SESSION(session)->sock = NULL;
                                imap_safe_destroy(session);
                        }
+                       imap_session_destroy(session);
+            session_destroy(SESSION(session));
                        return NULL;
                }
 
@@ -1947,7 +1954,7 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
        msginfo = (MsgInfo *)msglist->data;
        src = msginfo->folder;
        if (!same_dest_ok && src == dest) {
-               g_warning("the src folder is identical to the dest.");
+               g_warning("the src folder is identical to the dest");
                return -1;
        }
 
@@ -3112,12 +3119,12 @@ static FolderItem *imap_create_special_folder(Folder *folder,
        new_item = imap_create_folder(folder, item, name);
 
        if (!new_item) {
-               g_warning("Can't create '%s'", name);
+               g_warning("can't create '%s'", name);
                if (!folder->inbox) return NULL;
 
                new_item = imap_create_folder(folder, folder->inbox, name);
                if (!new_item)
-                       g_warning("Can't create '%s' under INBOX", name);
+                       g_warning("can't create '%s' under INBOX", name);
                else
                        new_item->stype = stype;
        } else
@@ -3221,9 +3228,11 @@ static FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
                gchar *cached_msg = imap_get_cached_filename(parent, to_number(name));
                if (is_file_exist(cached_msg)) {
                        if (claws_unlink(cached_msg) != 0) {
+                               g_free(cached_msg);
                                return NULL;
                        }
                }
+               g_free(cached_msg);
        }
 
        debug_print("getting session...\n");
@@ -3261,6 +3270,7 @@ static FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
 
        separator = imap_get_path_separator(session, IMAP_FOLDER(folder), imap_path, &ok);
        if (is_fatal(ok)) {
+               g_free(dirpath);
                g_free(imap_path);
                return NULL;
        }
@@ -3379,8 +3389,7 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
 
        if (strchr(name, imap_get_path_separator(session, IMAP_FOLDER(folder), item->path, &ok)) != NULL ||
                is_fatal(ok)) {
-               g_warning("New folder name must not contain the namespace "
-                           "path separator");
+               g_warning("new folder name must not contain the namespace path separator");
                return -1;
        }