- if (current_top && MODEST_IS_HEADER_WINDOW (current_top)) {
- ModestHeaderView *header_view;
- TnyFolder *folder;
- gboolean deleted = FALSE;
-
- header_view = modest_header_window_get_header_view (MODEST_HEADER_WINDOW (current_top));
- folder = modest_header_view_get_folder (header_view);
- if (folder) {
- /* Close if it's my account */
- if (!TNY_IS_MERGE_FOLDER (folder)) {
- TnyAccount *my_account;
-
- my_account = tny_folder_get_account (folder);
- if (my_account) {
- if (my_account == account) {
- close_all_but_first (stack);
- deleted = TRUE;
- }
- g_object_unref (my_account);
- }
- }
-
- /* Close if viewing outbox and no account left */
- if (tny_folder_get_folder_type (folder) == TNY_FOLDER_TYPE_OUTBOX) {
- if (!has_accounts) {
- close_all_but_first (stack);
- deleted = TRUE;
- }
- }
- g_object_unref (folder);
-
- if (deleted)
- current_top = (ModestWindow *) hildon_window_stack_peek (stack);
- }
+ if (current_top &&
+ (MODEST_IS_HEADER_WINDOW (current_top) ||
+ MODEST_IS_FOLDER_WINDOW (current_top))) {
+ const gchar *acc_name;
+
+ acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+
+ /* We emit it in an idle, because sometimes this
+ function could called when the account settings
+ dialog is about to close but still there. That
+ modal dialog would otherwise, prevent the
+ windows from being closed */
+ if (!strcmp (acc_name, modest_window_get_active_account (current_top)))
+ g_idle_add (on_idle_close_all_but_first, NULL);