+ const gchar* account_name = NULL;
+ GSList *account_names = modest_account_mgr_account_names (self, TRUE /* only enabled */);
+
+ /* Return TRUE if there is no account */
+ if (!account_names)
+ return NULL;
+
+ /* Get the first one, alphabetically, by title: */
+ /* gchar *old_default = modest_account_mgr_get_default_account (self); */
+ GSList* list_sorted = g_slist_sort (account_names, on_accounts_list_sort_by_title);
+
+ GSList* iter = list_sorted;
+ gboolean found = FALSE;
+ while (iter && !found) {
+ account_name = (const gchar*)list_sorted->data;
+
+ if (account_name)
+ found = TRUE;
+
+ if (!found)
+ iter = g_slist_next (iter);
+ }
+
+ gchar* result = NULL;
+ if (account_name)
+ result = g_strdup (account_name);
+
+ modest_account_mgr_free_account_names (account_names);
+ account_names = NULL;
+
+ return result;