Add a plugin method to allow updating stored passwords on master password change.
[claws.git] / src / plugins / spam_report / spam_report_prefs.c
index 772bd57..ec7ae8b 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"
@@ -114,6 +115,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 +127,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 = password_decrypt(spamreport_prefs.pass[i], NULL);
+               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 +198,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 +207,11 @@ 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);
+               spamreport_prefs.pass[i] = password_encrypt(pass, NULL);
+               memset(pass, 0, strlen(pass));
+               g_free(pass);
        }
 
         pref_file = prefs_write_open(rc_file_path);
@@ -221,3 +232,18 @@ static void save_spamreport_prefs(PrefsPage *page)
        } else
                prefs_file_close(pref_file);
 }
+
+void spamreport_master_password_change(const gchar *oldp, const gchar *newp) {
+       gchar *pass;
+       int i;
+
+       for (i = 0; i < INTF_LAST; i++) {
+               pass = password_decrypt(spamreport_prefs.pass[i], oldp);
+               if (pass != NULL) {
+                       g_free(spamreport_prefs.pass[i]);
+                       spamreport_prefs.pass[i] = password_encrypt(pass, newp);
+                       memset(pass, 0, strlen(pass));
+               }
+               g_free(pass);
+       }
+}