+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ /* Special case for the local account */
+ if (!strcmp (account_name, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) &&
+ type == TNY_ACCOUNT_TYPE_STORE) {
+ id = g_strdup (MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID);
+ } else {
+ ModestAccountData *account_data;
+
+ account_data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
+ if (!account_data) {
+ g_printerr ("modest: %s: cannot get account data for account '%s'\n", __FUNCTION__, account_name);
+ return NULL;
+ }
+
+ if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
+ id = g_strdup (account_data->store_account->account_name);
+ else if (account_data->transport_account)
+ id = g_strdup (account_data->transport_account->account_name);
+
+ modest_account_mgr_free_account_data (priv->account_mgr, account_data);
+ }
+
+ if (!id)
+ g_printerr ("modest: could not get an id for account %s\n",
+ account_name);
+ else
+ account = modest_tny_account_store_get_tny_account_by_id (self, id);
+
+ if (!account)
+ g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
+ type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
+ account_name, id ? id : "<none>");
+
+ return account;
+}
+
+static TnyAccount*
+get_smtp_specific_transport_account_for_open_connection (ModestTnyAccountStore *self,
+ const gchar *account_name)
+{
+ /* Get the current connection: */
+ TnyDevice *device = modest_runtime_get_device ();
+
+ if (!tny_device_is_online (device))
+ return NULL;
+
+#ifdef MODEST_PLATFORM_MAEMO
+ g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
+ TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
+ const gchar* iap_id = tny_maemo_conic_device_get_current_iap_id (maemo_device);
+ /* printf ("DEBUG: %s: iap_id=%s\n", __FUNCTION__, iap_id); */
+ if (!iap_id)
+ return NULL;
+
+ ConIcIap* connection = tny_maemo_conic_device_get_iap (maemo_device, iap_id);
+ if (!connection)
+ return NULL;
+
+ const gchar *connection_name = con_ic_iap_get_name (connection);
+ /* printf ("DEBUG: %s: connection_name=%s\n", __FUNCTION__, connection_name); */
+ if (!connection_name)
+ return NULL;
+
+ /* Get the connection-specific transport acccount, if any: */
+ ModestAccountMgr *account_manager = modest_runtime_get_account_mgr ();
+ gchar* server_account_name = modest_account_mgr_get_connection_specific_smtp (account_manager,
+ account_name, connection_name);
+
+ /* printf ("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
+ if (!server_account_name) {
+ return NULL; /* No connection-specific SMTP server was specified for this connection. */
+ }
+
+ TnyAccount* account = modest_tny_account_store_get_tny_account_by_id (self, server_account_name);
+
+ /* printf ("DEBUG: %s: account=%p\n", __FUNCTION__, account); */
+ g_free (server_account_name);
+
+ /* Unref the get()ed object, as required by the tny_maemo_conic_device_get_iap() documentation. */
+ g_object_unref (connection);
+
+ return account;
+#else
+ return NULL; /* TODO: Implement this for GNOME, instead of just Maemo? */
+#endif /* MODEST_PLATFORM_MAEMO */
+}
+
+
+TnyAccount*
+modest_tny_account_store_get_transport_account_for_open_connection (ModestTnyAccountStore *self,
+ const gchar *account_name)
+{
+ /* Get the connection-specific transport acccount, if any: */
+ TnyAccount *account = get_smtp_specific_transport_account_for_open_connection (self, account_name);
+
+ /* If there is no connection-specific transport account (the common case),
+ * just get the regular transport account: */
+ if (!account) {
+ /* printf("DEBUG: %s: using regular transport account for account %s.\n", __FUNCTION__, account_name); */
+ account = modest_tny_account_store_get_tny_account_by_account (self, account_name,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
+ }
+
+ return account;
+}
+
+gboolean modest_tny_account_is_virtual_local_folders (TnyAccount *self)
+{
+ /* We should make this more sophisticated if we ever use ModestTnyLocalFoldersAccount
+ * for anything else. */
+ return MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (self);