+
+ /* If it's the first remote account then add the connection
+ specific SMTP servers as well */
+ if (add_specific)
+ add_connection_specific_transport_accounts (MODEST_TNY_ACCOUNT_STORE (user_data));
+
+}
+
+/* This is the callback of the tny_camel_account_set_online called in
+ on_account_removed to disconnect the account */
+static void
+on_account_disconnect_when_removing (TnyCamelAccount *account,
+ gboolean canceled,
+ GError *err,
+ gpointer user_data)
+{
+ ModestTnyAccountStore *self;
+ ModestTnyAccountStorePrivate *priv;
+
+ self = MODEST_TNY_ACCOUNT_STORE (user_data);
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
+
+ /* Remove the connection-status-changed handler if it's still there */
+ if (modest_signal_mgr_is_connected (priv->sighandlers,
+ G_OBJECT (account),
+ "connection_status_changed")) {
+ priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
+ G_OBJECT (account),
+ "connection_status_changed");
+ }
+
+ /* Cancel all pending operations */
+ tny_account_cancel (TNY_ACCOUNT (account));
+
+ /* Unref the extra reference added by get_server_account */
+ g_object_unref (account);
+
+ /* Clear the cache if it's an store account */
+ if (TNY_IS_STORE_ACCOUNT (account)) {
+ tny_store_account_delete_cache (TNY_STORE_ACCOUNT (account));
+ } else if (TNY_IS_TRANSPORT_ACCOUNT (account)) {
+ ModestTnySendQueue* send_queue;
+ send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (account), FALSE);
+ if (TNY_IS_SEND_QUEUE (send_queue)) {
+ if (modest_tny_send_queue_sending_in_progress (send_queue))
+ tny_send_queue_cancel (TNY_SEND_QUEUE (send_queue),
+ TNY_SEND_QUEUE_CANCEL_ACTION_REMOVE,
+ NULL);
+ modest_runtime_remove_send_queue (TNY_TRANSPORT_ACCOUNT (account));
+ }
+ }
+}
+
+/*
+ * We use this one for both removing "normal" and "connection
+ * specific" transport accounts
+ */
+static void
+remove_transport_account (ModestTnyAccountStore *self,
+ TnyTransportAccount *transport_account)
+{
+ ModestTnyAccountStorePrivate *priv;
+ TnyFolder *outbox = NULL;
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
+
+ /* Remove it from the list of accounts and notify the
+ observers. Do not need to wait for account
+ disconnection */
+ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL], 0, transport_account);
+ tny_list_remove (priv->transport_accounts, (GObject *) transport_account);
+
+ /* Remove the OUTBOX of the account from the global outbox */
+ outbox = g_hash_table_lookup (priv->outbox_of_transport, transport_account);
+
+ if (TNY_IS_FOLDER (outbox)) {
+ TnyAccount *local_account = NULL;
+ TnyAccount *outbox_account = tny_folder_get_account (outbox);
+
+ if (outbox_account) {
+ tny_list_remove (priv->store_accounts_outboxes, G_OBJECT (outbox_account));
+ /* Remove existing emails to send */
+ tny_store_account_delete_cache (TNY_STORE_ACCOUNT (outbox_account));
+ g_object_unref (outbox_account);
+ }
+
+ local_account = modest_tny_account_store_get_local_folders_account (self);
+ modest_tny_local_folders_account_remove_folder_from_outbox (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (local_account),
+ outbox);
+
+ g_hash_table_remove (priv->outbox_of_transport, transport_account);
+
+ /* Notify the change in the local account */
+ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_CHANGED_SIGNAL], 0, local_account);
+ g_object_unref (local_account);
+ } else {
+ g_warning ("Removing a transport account that has no outbox");
+ }
+
+ /* Cancel all pending operations */
+ tny_account_cancel (TNY_ACCOUNT (transport_account));
+
+ /* Disconnect and notify the observers. The callback will free the reference */
+ tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (transport_account), FALSE,
+ on_account_disconnect_when_removing, self);
+}
+
+static gboolean
+images_cache_remove_filter (TnyStreamCache *self, const gchar *id, const gchar *account_name)
+{
+ gchar *account_name_with_separator;
+ gboolean result;
+ if (account_name == NULL || account_name[0] == '\0')
+ return FALSE;
+
+ if (id == NULL || id[0] == '\0')
+ return FALSE;
+
+ account_name_with_separator = g_strconcat (account_name, "__", NULL);
+
+ result = (g_str_has_prefix (id, account_name));
+ g_free (account_name_with_separator);
+
+ return result;