+/* this function fills the TnyList, and also returns a GSList of the accounts,
+ * for caching purposes
+ */
+static GSList*
+get_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type)
+{
+ ModestTnyAccountStorePrivate *priv;
+ GSList *account_names, *cursor;
+ GSList *accounts = NULL;
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ account_names = modest_account_mgr_account_names (priv->account_mgr);
+
+ for (cursor = account_names; cursor; cursor = cursor->next) {
+
+ gchar *account_name = (gchar*)cursor->data;
+
+ /* only return enabled accounts */
+ if (modest_account_mgr_get_enabled(priv->account_mgr, account_name)) {
+ TnyAccount *tny_account =
+ modest_tny_account_new_from_account (priv->account_mgr,
+ account_name,
+ type, priv->session,
+ get_password,
+ forget_password);
+ if (tny_account) { /* something went wrong */
+ g_object_set_data (G_OBJECT(tny_account), "account_store",
+ (gpointer)self);
+ tny_list_prepend (list, G_OBJECT(tny_account));
+ accounts = g_slist_append (accounts, tny_account); /* cache it */
+ } else
+ g_printerr ("modest: failed to create account for %s\n",
+ account_name);
+ }
+ g_free (account_name);
+ }
+ g_slist_free (account_names);
+
+ /* also, add the local folder pseudo-account */
+ if (type == TNY_ACCOUNT_TYPE_STORE) {
+ TnyAccount *tny_account =
+ modest_tny_account_new_for_local_folders (priv->account_mgr, priv->session);
+ tny_list_prepend (list, G_OBJECT(tny_account));
+ accounts = g_slist_append (accounts, tny_account); /* cache it */
+ }