diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-account-utils.c | 42 | ||||
-rw-r--r-- | e-util/e-account-utils.h | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/e-util/e-account-utils.c b/e-util/e-account-utils.c index 4395542f7c..66242408ac 100644 --- a/e-util/e-account-utils.c +++ b/e-util/e-account-utils.c @@ -137,3 +137,45 @@ e_get_account_by_uid (const gchar *uid) /* XXX EAccountList misuses const. */ return (EAccount *) account; } + +/** + * e_get_any_enabled_account: + * + * Returns the default mail account if it's enabled, otherwise the first + * enabled mail account in the global #EAccountList, or finally %NULL if + * all mail accounts are disabled or none exist. + * + * Returns: an enabled #EAccount, or %NULL if there are none + **/ +EAccount * +e_get_any_enabled_account (void) +{ + EAccount *account; + EAccountList *account_list; + EIterator *iter; + + account = e_get_default_account (); + if (account != NULL && account->enabled) + return account; + + account = NULL; + + account_list = e_get_account_list (); + iter = e_list_get_iterator (E_LIST (account_list)); + + while (e_iterator_is_valid (iter) && account == NULL) { + EAccount *candidate; + + /* XXX EIterator misuses const. */ + candidate = (EAccount *) e_iterator_get (iter); + + if (candidate->enabled) + account = candidate; + else + e_iterator_next (iter); + } + + g_object_unref (iter); + + return account; +} diff --git a/e-util/e-account-utils.h b/e-util/e-account-utils.h index f2ae8fc5dc..f8c5c968a4 100644 --- a/e-util/e-account-utils.h +++ b/e-util/e-account-utils.h @@ -29,6 +29,7 @@ EAccount * e_get_default_account (void); void e_set_default_account (EAccount *account); EAccount * e_get_account_by_name (const gchar *name); EAccount * e_get_account_by_uid (const gchar *uid); +EAccount * e_get_any_enabled_account (void); G_END_DECLS |