Use account ID instead of name in passwordstorerc.
[claws.git] / src / news.c
index 3717569472e995177d01cb6dd8ae830812353952..3bfbce46b496a2f3d9b728ccb8705d9c04c7a7ba 100644 (file)
@@ -48,6 +48,7 @@
 #include "statusbar.h"
 #include "codeconv.h"
 #include "utils.h"
+#include "passwordstore.h"
 #include "prefs_common.h"
 #include "prefs_account.h"
 #include "inputdialog.h"
 #include "remotefolder.h"
 #include "alertpanel.h"
 #include "inc.h"
+#include "account.h"
 #ifdef USE_GNUTLS
 #  include "ssl.h"
 #endif
+#include "main.h"
 
 #define NNTP_PORT      119
 #ifdef USE_GNUTLS
@@ -374,15 +377,6 @@ static Session *news_session_new_for_folder(Folder *folder)
        cm_return_val_if_fail(folder->account != NULL, NULL);
 
        ac = folder->account;
-       if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
-               userid = ac->userid;
-               if (ac->passwd && ac->passwd[0])
-                       passwd = g_strdup(ac->passwd);
-               else
-                       passwd = input_dialog_query_password_keep(ac->nntp_server,
-                                                                 userid,
-                                                                 &(ac->session_passwd));
-       }
 
 #ifdef USE_GNUTLS
        port = ac->set_nntpport ? ac->nntpport
@@ -407,6 +401,18 @@ static Session *news_session_new_for_folder(Folder *folder)
        session = news_session_new(folder, ac->nntp_server, port, userid, passwd);
 #endif
 
+       if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
+               userid = ac->userid;
+               if (password_get(userid, ac->nntp_server, "nntp", port, &passwd)) {
+                       /* NOP */;
+               } else if ((passwd = passwd_store_get_account(ac->account_id,
+                                       PWS_ACCOUNT_RECV)) == NULL) {
+                       passwd = input_dialog_query_password_keep(ac->nntp_server,
+                                                                 userid,
+                                                                 &(ac->session_passwd));
+               }
+       }
+
        if (session != NULL)
                r = nntp_threaded_mode_reader(folder);
        else
@@ -443,7 +449,8 @@ static Session *news_session_new_for_folder(Folder *folder)
            else {
                /* An error state bail out */
                log_error(LOG_PROTOCOL, _("Error creating session with %s:%d\n"), ac->nntp_server, port);
-               session_destroy(SESSION(session));
+               if (session != NULL)
+                       session_destroy(SESSION(session));
                g_free(passwd);
                if (ac->session_passwd) {
                        g_free(ac->session_passwd);
@@ -578,7 +585,7 @@ static gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
        ok = news_get_article(folder,
                              num, filename);
        if (ok != NEWSNNTP_NO_ERROR) {
-               g_warning("can't read article %d\n", num);
+               g_warning("can't read article %d", num);
                if (ok == NEWSNNTP_ERROR_STREAM) {
                        session_destroy(SESSION(session));
                        REMOTE_FOLDER(folder)->session = NULL;
@@ -756,7 +763,7 @@ void news_remove_group_list_cache(Folder *folder)
        g_free(path);
 
        if (is_file_exist(filename)) {
-               if (remove(filename) < 0)
+               if (claws_unlink(filename) < 0)
                        FILE_OP_ERROR(filename, "remove");
        }
        g_free(filename);
@@ -935,7 +942,7 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
        }
        if (change_file_mode_rw(tmpfp, tmp) < 0) {
                FILE_OP_ERROR(tmp, "chmod");
-               g_warning("can't change file mode\n");
+               g_warning("can't change file mode");
        }
        
        get_rfc822_date(buf, sizeof(buf));
@@ -970,7 +977,7 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
        }
 
        news_post(folder, tmp);
-       remove(tmp);
+       claws_unlink(tmp);
 
        g_free(tmp);
 
@@ -1288,8 +1295,6 @@ static GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnu
        NewsSession *session;
        GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
        guint first, last, next;
-/*     guint tofetch, fetched;
-*/
        
        cm_return_val_if_fail(folder != NULL, NULL);
        cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
@@ -1303,9 +1308,6 @@ static GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnu
        tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, g_int_compare);
 
        progressindicator_start(PROGRESS_TYPE_NETWORK);
-/*     tofetch = g_slist_length(tmp_msgnum_list);
-       fetched = 0;
-*/
 
        first = GPOINTER_TO_INT(tmp_msgnum_list->data);
        last = first;
@@ -1315,13 +1317,8 @@ static GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnu
        for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
                next = GPOINTER_TO_INT(elem->data);
                if(next != (last + 1)) {
-/*                     session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
-                       session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
-*/
                        tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
                        msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
-/*                     fetched = last - first + 1;
-*/
                        first = next;
                }
                last = next;
@@ -1329,9 +1326,6 @@ static GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnu
        
        news_folder_unlock(NEWS_FOLDER(item->folder));
        
-/*     session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
-       session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
-*/
        tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
        msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
 
@@ -1382,7 +1376,7 @@ static gint news_remove_folder(Folder *folder, FolderItem *item)
 
        path = folder_item_get_path(item);
        if (remove_dir_recursive(path) < 0) {
-               g_warning("can't remove directory `%s'\n", path);
+               g_warning("can't remove directory '%s'", path);
                g_free(path);
                return -1;
        }