Empty account block in password store when deleting an account.
authorAndrej Kacian <ticho@claws-mail.org>
Thu, 24 Mar 2016 19:39:26 +0000 (20:39 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Thu, 24 Mar 2016 19:39:26 +0000 (20:39 +0100)
This effectively deletes it, as empty password blocks are
not saved to disk.

src/account.c
src/passwordstore.c
src/passwordstore.h

index 58dfab9f718071a31ea563212569bb64af079b96..e2f472f5788460c32891c8b351d2a15c52f70256 100644 (file)
@@ -54,6 +54,7 @@
 #include "filtering.h"
 #include "prefs_actions.h"
 #include "hooks.h"
+#include "passwordstore.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
@@ -1103,6 +1104,10 @@ static void account_delete(GtkWidget *widget, gpointer data)
                                GINT_TO_POINTER(ac_prefs->account_id));
        }
 
+       gchar *uid = g_strdup_printf("%d", ac_prefs->account_id);
+       passwd_store_delete_block(PWS_ACCOUNT, uid);
+       g_free(uid);
+
        debug_print("Removing filter rules relative to this account...\n");
        for(cur = filtering_rules ; cur != NULL ;) {
                FilteringProp * prop = (FilteringProp *) cur->data;
index 4cdddd1c0bf2a926cf9d56a1376355a25e13180d..dcb9d523fc223e3260a1d91e1df3fec738d84248 100644 (file)
@@ -208,6 +208,27 @@ gchar *passwd_store_get(PasswordBlockType block_type,
        return password;
 }
 
+gboolean passwd_store_delete_block(PasswordBlockType block_type,
+               const gchar *block_name)
+{
+       PasswordBlock *block;
+
+       g_return_val_if_fail(block_type >= 0 && block_type < NUM_PWS_TYPES,
+                       FALSE);
+       g_return_val_if_fail(block_name != NULL, FALSE);
+
+       debug_print("Deleting block (%d/%s)\n", block_type, block_name);
+
+       // find correct block
+       if ((block = _get_block(block_type, block_name)) == NULL) {
+               debug_print("Block (%d/%s) not found.\n", block_type, block_name);
+               return FALSE;
+       }
+
+       g_hash_table_destroy(block->entries);
+       return TRUE;
+}
+
 gboolean passwd_store_set_account(gint account_id,
                const gchar *password_id,
                const gchar *password,
index 373116bf4f4dfaf8bdb889b7e6570e4fa6abfb60..20d2c6ba5cb53cc49c5eaff1e6f839621597efc7 100644 (file)
@@ -57,6 +57,9 @@ gchar *passwd_store_get(PasswordBlockType block_type,
                const gchar *block_name,
                const gchar *password_id);
 
+gboolean passwd_store_delete_block(PasswordBlockType block_type,
+               const gchar *block_name);
+
 /* Reencrypts all stored passwords using new_mpwd as an encryption
  * password. */
 void passwd_store_reencrypt_all(const gchar *old_mpwd,