Make SpamReport plugin use the password store.
[claws.git] / src / plugins / spam_report / spam_report_prefs.c
index f0c7604..617794a 100644 (file)
@@ -30,6 +30,7 @@
 #include <gtk/gtk.h>
 
 #include "gtkutils.h"
+#include "password.h"
 #include "prefs.h"
 #include "prefs_gtk.h"
 #include "prefswindow.h"
@@ -75,6 +76,7 @@ void spamreport_prefs_init(void)
 {
        static gchar *path[3];
        gchar *rcpath;
+       guint i;
 
        path[0] = _("Plugins");
        path[1] = _("SpamReport");
@@ -84,7 +86,16 @@ void spamreport_prefs_init(void)
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
         prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
        g_free(rcpath);
-        
+
+       /* Move passwords that are still in main config to password store. */
+       for (i = 0; i < INTF_LAST; i++) {
+               if (spamreport_prefs.pass[i] != NULL &&
+                               strlen(spamreport_prefs.pass[i]) > 0) {
+                       spamreport_passwd_set(spam_interfaces[i].name,
+                                       spamreport_prefs.pass[i]);
+               }
+       }
+
         spamreport_prefs_page.page.path = path;
         spamreport_prefs_page.page.create_widget = create_spamreport_prefs_page;
         spamreport_prefs_page.page.destroy_widget = destroy_spamreport_prefs_page;
@@ -114,6 +125,7 @@ static void create_spamreport_prefs_page(PrefsPage *page,
        gtk_widget_show(vbox);
        
        for (i = 0; i < INTF_LAST; i++) {
+               gchar *pass;
                prefs_page->frame[i] = gtk_frame_new(spam_interfaces[i].name);
                gtk_box_pack_start(GTK_BOX(vbox), prefs_page->frame[i], FALSE, FALSE, 6);
 
@@ -125,8 +137,13 @@ static void create_spamreport_prefs_page(PrefsPage *page,
 
                gtk_entry_set_text(GTK_ENTRY(prefs_page->user_entry[i]),
                        spamreport_prefs.user[i] ? spamreport_prefs.user[i]:"");
-               gtk_entry_set_text(GTK_ENTRY(prefs_page->pass_entry[i]),
-                       spamreport_prefs.pass[i] ? spamreport_prefs.pass[i]:"");
+
+               pass = spamreport_passwd_get(spam_interfaces[i].name);
+               gtk_entry_set_text(GTK_ENTRY(prefs_page->pass_entry[i]), pass ? pass:"");
+               if (pass != NULL) {
+                       memset(pass, 0, strlen(pass));
+               }
+               g_free(pass);
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_page->enabled_chkbtn[i]),
                        spamreport_prefs.enabled[i]);
 
@@ -191,6 +208,7 @@ static void save_spamreport_prefs(PrefsPage *page)
         int i = 0;
        
        for (i = 0; i < INTF_LAST; i++) {
+               gchar *pass;
 
                g_free(spamreport_prefs.user[i]);
                g_free(spamreport_prefs.pass[i]);
@@ -199,8 +217,13 @@ static void save_spamreport_prefs(PrefsPage *page)
                        GTK_TOGGLE_BUTTON(prefs_page->enabled_chkbtn[i]));
                spamreport_prefs.user[i] = gtk_editable_get_chars(
                        GTK_EDITABLE(prefs_page->user_entry[i]), 0, -1);
-               spamreport_prefs.pass[i] = gtk_editable_get_chars(
-                       GTK_EDITABLE(prefs_page->pass_entry[i]), 0, -1);
+
+               pass = gtk_editable_get_chars(GTK_EDITABLE(prefs_page->pass_entry[i]), 0, -1);
+               if (strlen(pass) > 0) {
+                       spamreport_passwd_set(spam_interfaces[i].name, pass);
+                       memset(pass, 0, strlen(pass));
+               }
+               g_free(pass);
        }
 
         pref_file = prefs_write_open(rc_file_path);
@@ -211,7 +234,7 @@ static void save_spamreport_prefs(PrefsPage *page)
           return;
         
         if (prefs_write_param(param, pref_file->fp) < 0) {
-          g_warning("failed to write SpamReport Plugin configuration\n");
+          g_warning("failed to write SpamReport Plugin configuration");
           prefs_file_close_revert(pref_file);
           return;
         }