1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <glib/gi18n.h>
33 #include <tny-account.h>
34 #include <tny-account-store.h>
35 #include <tny-store-account.h>
36 #include <tny-transport-account.h>
37 #include <tny-simple-list.h>
38 #include <tny-account-store.h>
39 #include <tny-maemo-conic-device.h> /* For ConIcIap */
40 #include <tny-camel-transport-account.h>
41 #include <tny-camel-imap-store-account.h>
42 #include <tny-camel-pop-store-account.h>
43 #include <modest-runtime.h>
44 #include <modest-marshal.h>
45 #include <modest-protocol-info.h>
46 #include <modest-local-folder-info.h>
47 #include <modest-tny-account.h>
48 #include <modest-account-mgr.h>
49 #include <modest-account-mgr-helpers.h>
51 #include "modest-tny-account-store.h"
52 #include "modest-tny-platform-factory.h"
53 #include <tny-gtk-lockable.h>
54 #include <camel/camel.h>
56 /* 'private'/'protected' functions */
57 static void modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass);
58 //static void modest_tny_account_store_init (ModestTnyAccountStore *obj);
59 static void modest_tny_account_store_finalize (GObject *obj);
61 /* implementations for tny-account-store-iface */
62 static void modest_tny_account_store_instance_init (ModestTnyAccountStore *obj);
63 static void modest_tny_account_store_init (gpointer g, gpointer iface_data);
68 ACCOUNT_UPDATE_SIGNAL,
69 PASSWORD_REQUESTED_SIGNAL,
73 typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate;
74 struct _ModestTnyAccountStorePrivate {
76 GHashTable *password_hash;
77 ModestAccountMgr *account_mgr;
78 TnySessionCamel *session;
81 /* we cache them here */
82 GSList *store_accounts;
83 GSList *transport_accounts;
86 #define MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
87 MODEST_TYPE_TNY_ACCOUNT_STORE, \
88 ModestTnyAccountStorePrivate))
91 static GObjectClass *parent_class = NULL;
93 static guint signals[LAST_SIGNAL] = {0};
96 modest_tny_account_store_get_type (void)
98 static GType my_type = 0;
101 static const GTypeInfo my_info = {
102 sizeof(ModestTnyAccountStoreClass),
103 NULL, /* base init */
104 NULL, /* base finalize */
105 (GClassInitFunc) modest_tny_account_store_class_init,
106 NULL, /* class finalize */
107 NULL, /* class data */
108 sizeof(ModestTnyAccountStore),
110 (GInstanceInitFunc) modest_tny_account_store_instance_init,
114 static const GInterfaceInfo iface_info = {
115 (GInterfaceInitFunc) modest_tny_account_store_init,
116 NULL, /* interface_finalize */
117 NULL /* interface_data */
120 my_type = g_type_register_static (G_TYPE_OBJECT,
121 "ModestTnyAccountStore",
123 g_type_add_interface_static (my_type, TNY_TYPE_ACCOUNT_STORE,
130 modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass)
132 GObjectClass *gobject_class;
133 gobject_class = (GObjectClass*) klass;
135 parent_class = g_type_class_peek_parent (klass);
136 gobject_class->finalize = modest_tny_account_store_finalize;
138 g_type_class_add_private (gobject_class,
139 sizeof(ModestTnyAccountStorePrivate));
141 signals[ACCOUNT_UPDATE_SIGNAL] =
142 g_signal_new ("account_update",
143 G_TYPE_FROM_CLASS (gobject_class),
145 G_STRUCT_OFFSET(ModestTnyAccountStoreClass, account_update),
147 g_cclosure_marshal_VOID__STRING,
148 G_TYPE_NONE, 1, G_TYPE_STRING);
150 signals[PASSWORD_REQUESTED_SIGNAL] =
151 g_signal_new ("password_requested",
152 G_TYPE_FROM_CLASS (gobject_class),
154 G_STRUCT_OFFSET(ModestTnyAccountStoreClass, password_requested),
156 modest_marshal_VOID__STRING_POINTER_POINTER_POINTER,
157 G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER,
163 modest_tny_account_store_instance_init (ModestTnyAccountStore *obj)
165 ModestTnyAccountStorePrivate *priv =
166 MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
168 priv->cache_dir = NULL;
169 priv->account_mgr = NULL;
170 priv->session = NULL;
173 priv->password_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
180 account_list_free (GSList *accounts)
182 GSList *cursor = accounts;
185 /* TODO: This uses cursor->data after causing it to be freed,
187 * It's not clear what is being attempted here. murrayc */
188 g_object_unref (G_OBJECT(cursor->data));
189 if (G_IS_OBJECT(cursor->data)) { /* check twice... */
190 const gchar *id = tny_account_get_id(TNY_ACCOUNT(cursor->data));
191 modest_runtime_verify_object_death(cursor->data,id);
193 cursor = cursor->next;
195 g_slist_free (accounts);
200 on_account_removed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account,
203 ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
204 ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
206 /* FIXME: make this more finegrained; changes do not really affect _all_
207 * accounts, and some do not affect tny accounts at all (such as 'last_update')
211 account_list_free (priv->store_accounts);
212 priv->store_accounts = NULL;
214 account_list_free (priv->transport_accounts);
215 priv->transport_accounts = NULL;
217 g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
223 on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account,
224 const gchar *key, gpointer user_data)
226 ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
227 ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
229 /* FIXME: make this more finegrained; changes do not really affect _all_
230 * accounts, and some do not affect tny accounts at all (such as 'last_update')
232 if (priv->store_accounts) {
233 account_list_free (priv->store_accounts);
234 priv->store_accounts = NULL;
237 if (priv->transport_accounts) {
238 account_list_free (priv->transport_accounts);
239 priv->transport_accounts = NULL;
242 g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
247 static ModestTnyAccountStore*
248 get_account_store_for_account (TnyAccount *account)
250 return MODEST_TNY_ACCOUNT_STORE(g_object_get_data (G_OBJECT(account),
255 get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
258 const TnyAccountStore *account_store;
259 ModestTnyAccountStore *self;
260 ModestTnyAccountStorePrivate *priv;
263 gboolean already_asked;
265 key = tny_account_get_id (account);
266 account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
268 self = MODEST_TNY_ACCOUNT_STORE (account_store);
269 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
271 /* is it in the hash? if it's already there, it must be wrong... */
272 pwd_ptr = (gpointer)&pwd; /* pwd_ptr so the compiler does not complained about
273 * type-punned ptrs...*/
274 already_asked = g_hash_table_lookup_extended (priv->password_hash,
277 (gpointer*)&pwd_ptr);
279 /* if the password is not already there, try ModestConf */
280 if (!already_asked) {
281 pwd = modest_account_mgr_get_string (priv->account_mgr,
282 key, MODEST_ACCOUNT_PASSWORD,TRUE);
283 g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup (pwd));
286 /* if it was already asked, it must have been wrong, so ask again */
287 if (already_asked || !pwd || strlen(pwd) == 0) {
289 /* we don't have it yet. Get the password from the user */
290 const gchar* name = tny_account_get_name (account);
291 gboolean remember = FALSE;
294 g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0,
295 name, &pwd, cancel, &remember);
299 modest_account_mgr_set_string (priv->account_mgr,key,
300 MODEST_ACCOUNT_PASSWORD,
302 /* We need to dup the string even knowing that
303 it's already a dup of the contents of an
304 entry, because it if it's wrong, then camel
306 g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup(pwd));
308 g_hash_table_remove (priv->password_hash, key);
320 forget_password (TnyAccount *account)
322 ModestTnyAccountStore *self;
323 ModestTnyAccountStorePrivate *priv;
324 const TnyAccountStore *account_store;
328 account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
329 self = MODEST_TNY_ACCOUNT_STORE (account_store);
330 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
331 key = tny_account_get_id (account);
333 /* Do not remove the key, this will allow us to detect that we
334 have already asked for it at least once */
335 pwd = g_hash_table_lookup (priv->password_hash, key);
337 memset (pwd, 0, strlen (pwd));
338 g_hash_table_insert (priv->password_hash, g_strdup (key), NULL);
341 /* Remove from configuration system */
342 modest_account_mgr_unset (priv->account_mgr,
343 key, MODEST_ACCOUNT_PASSWORD, TRUE);
348 modest_tny_account_store_finalize (GObject *obj)
350 ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(obj);
351 ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
353 //gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
355 g_free (priv->cache_dir);
356 priv->cache_dir = NULL;
358 if (priv->password_hash) {
359 g_hash_table_destroy (priv->password_hash);
360 priv->password_hash = NULL;
363 if (priv->account_mgr) {
364 g_object_unref (G_OBJECT(priv->account_mgr));
365 priv->account_mgr = NULL;
369 g_object_unref (G_OBJECT(priv->device));
373 /* this includes the local folder */
374 account_list_free (priv->store_accounts);
375 priv->store_accounts = NULL;
377 account_list_free (priv->transport_accounts);
378 priv->transport_accounts = NULL;
381 camel_object_unref (CAMEL_OBJECT(priv->session));
382 modest_runtime_verify_object_death(priv->session, "");
383 priv->session = NULL;
386 G_OBJECT_CLASS(parent_class)->finalize (obj);
390 ModestTnyAccountStore*
391 modest_tny_account_store_new (ModestAccountMgr *account_mgr, TnyDevice *device) {
394 ModestTnyAccountStorePrivate *priv;
397 g_return_val_if_fail (account_mgr, NULL);
398 g_return_val_if_fail (device, NULL);
400 obj = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL));
401 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
403 priv->account_mgr = g_object_ref (G_OBJECT(account_mgr));
404 priv->device = g_object_ref (device);
406 priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
408 tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ());
409 /* FIXME: unref this in the end? */
410 tny_session_camel_set_async_connecting (priv->session, TRUE);
412 /* force a cache fill... ugly */
413 list = TNY_LIST(tny_simple_list_new());
414 tny_account_store_get_accounts (TNY_ACCOUNT_STORE(obj), list,
415 TNY_ACCOUNT_STORE_BOTH);
416 g_object_unref(list);
418 /* Connect signals */
419 g_signal_connect (G_OBJECT(account_mgr), "account_changed",
420 G_CALLBACK (on_account_changed), obj);
421 g_signal_connect (G_OBJECT(account_mgr), "account_removed",
422 G_CALLBACK (on_account_removed), obj);
424 return MODEST_TNY_ACCOUNT_STORE(obj);
429 get_cached_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type)
431 ModestTnyAccountStorePrivate *priv;
432 GSList *accounts, *cursor;
434 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
435 accounts = (type == TNY_ACCOUNT_TYPE_STORE ? priv->store_accounts : priv->transport_accounts);
439 tny_list_prepend (list, G_OBJECT(cursor->data));
440 cursor = cursor->next;
446 /* this function fills the TnyList, and also returns a GSList of the accounts,
447 * for caching purposes
450 get_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type)
452 ModestTnyAccountStorePrivate *priv;
453 GSList *account_names, *cursor;
454 GSList *accounts = NULL;
456 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
458 account_names = modest_account_mgr_account_names (priv->account_mgr);
460 for (cursor = account_names; cursor; cursor = cursor->next) {
462 gchar *account_name = (gchar*)cursor->data;
464 /* only return enabled accounts */
465 if (modest_account_mgr_get_enabled(priv->account_mgr, account_name)) {
466 TnyAccount *tny_account =
467 modest_tny_account_new_from_account (priv->account_mgr,
473 g_object_set_data (G_OBJECT(tny_account), "account_store",
475 tny_list_prepend (list, G_OBJECT(tny_account));
476 accounts = g_slist_append (accounts, tny_account); /* cache it */
478 g_printerr ("modest: failed to create account for %s\n",
481 g_free (account_name);
483 g_slist_free (account_names);
485 /* also, add the local folder pseudo-account */
486 if (type == TNY_ACCOUNT_TYPE_STORE) {
487 TnyAccount *tny_account =
488 modest_tny_account_new_for_local_folders (priv->account_mgr, priv->session);
489 tny_list_prepend (list, G_OBJECT(tny_account));
490 accounts = g_slist_append (accounts, tny_account); /* cache it */
497 modest_tny_account_store_get_accounts (TnyAccountStore *self, TnyList *list,
498 TnyGetAccountsRequestType request_type)
500 ModestTnyAccountStorePrivate *priv;
502 g_return_if_fail (self);
503 g_return_if_fail (TNY_IS_LIST(list));
505 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
507 if (request_type == TNY_ACCOUNT_STORE_BOTH) {
508 modest_tny_account_store_get_accounts (self, list,
509 TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
510 modest_tny_account_store_get_accounts (self, list,
511 TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
515 if (request_type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) {
517 if (!priv->store_accounts)
518 priv->store_accounts = get_accounts (self, list, TNY_ACCOUNT_TYPE_STORE);
520 get_cached_accounts (self, list, TNY_ACCOUNT_TYPE_STORE);
522 } else if (request_type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
524 if (!priv->transport_accounts)
525 priv->transport_accounts =
526 get_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
528 get_cached_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
530 g_return_if_reached (); /* incorrect req type */
535 modest_tny_account_store_get_cache_dir (TnyAccountStore *self)
537 ModestTnyAccountStorePrivate *priv;
538 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
540 if (!priv->cache_dir)
541 priv->cache_dir = g_build_filename (g_get_home_dir(),
542 MODEST_DIR, MODEST_CACHE_DIR, NULL);
543 return priv->cache_dir;
548 * callers need to unref
551 modest_tny_account_store_get_device (TnyAccountStore *self)
553 ModestTnyAccountStorePrivate *priv;
555 g_return_val_if_fail (self, NULL);
557 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
560 return g_object_ref (G_OBJECT(priv->device));
567 modest_tny_account_store_find_account_by_url (TnyAccountStore *self, const gchar* url_string)
569 TnyAccount *account = NULL;
570 ModestTnyAccountStorePrivate *priv;
573 g_return_val_if_fail (self, NULL);
574 g_return_val_if_fail (url_string, NULL);
576 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
578 for (cursor = priv->store_accounts; cursor ; cursor = cursor->next) {
579 if (tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), url_string)) {
580 account = TNY_ACCOUNT(cursor->data);
586 for (cursor = priv->transport_accounts; !account && cursor ; cursor = cursor->next) {
587 if (tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), url_string)) {
588 account = TNY_ACCOUNT(cursor->data);
595 g_object_ref (G_OBJECT(account));
603 modest_tny_account_store_alert (TnyAccountStore *self, TnyAlertType type,
606 GtkMessageType gtktype;
607 gboolean retval = FALSE;
612 case TNY_ALERT_TYPE_INFO:
613 gtktype = GTK_MESSAGE_INFO;
615 case TNY_ALERT_TYPE_WARNING:
616 gtktype = GTK_MESSAGE_WARNING;
618 case TNY_ALERT_TYPE_ERROR:
620 gtktype = GTK_MESSAGE_ERROR;
624 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
625 gtktype, GTK_BUTTONS_YES_NO, prompt);
627 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
630 gtk_widget_destroy (dialog);
638 modest_tny_account_store_add_store_account (TnyAccountStore *self,
639 TnyStoreAccount *account)
641 /* we should not need this...*/
642 g_printerr ("modest: add_store_account_func not implemented\n");
647 modest_tny_account_store_add_transport_account (TnyAccountStore *self,
648 TnyTransportAccount *account)
650 /* we should not need this...*/
651 g_printerr ("modest: add_transport_account_func not implemented\n");
657 modest_tny_account_store_init (gpointer g, gpointer iface_data)
659 TnyAccountStoreIface *klass;
661 g_return_if_fail (g);
663 klass = (TnyAccountStoreIface *)g;
665 klass->get_accounts_func =
666 modest_tny_account_store_get_accounts;
667 klass->add_transport_account_func =
668 modest_tny_account_store_add_transport_account;
669 klass->add_store_account_func =
670 modest_tny_account_store_add_store_account;
671 klass->get_cache_dir_func =
672 modest_tny_account_store_get_cache_dir;
673 klass->get_device_func =
674 modest_tny_account_store_get_device;
676 modest_tny_account_store_alert;
677 klass->find_account_func =
678 modest_tny_account_store_find_account_by_url;
682 modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self,
683 ModestTnyGetPassFunc func)
685 /* not implemented, we use signals */
686 g_printerr ("modest: set_get_pass_func not implemented\n");
690 tny_account_store_get_session (TnyAccountStore *self)
692 g_return_val_if_fail (self, NULL);
693 return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self)->session;
698 modest_tny_account_store_get_tny_account_by_id (ModestTnyAccountStore *self, const gchar *id)
700 TnyAccount *account = NULL;
701 ModestTnyAccountStorePrivate *priv;
704 g_return_val_if_fail (self, NULL);
705 g_return_val_if_fail (id, NULL);
707 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
709 for (cursor = priv->store_accounts; cursor ; cursor = cursor->next) {
710 const gchar *acc_id = tny_account_get_id (TNY_ACCOUNT(cursor->data));
711 if (acc_id && strcmp (acc_id, id) == 0) {
712 account = TNY_ACCOUNT(cursor->data);
717 /* if we already found something, no need to search the transport accounts */
718 for (cursor = priv->transport_accounts; !account && cursor ; cursor = cursor->next) {
719 const gchar *acc_id = tny_account_get_id (TNY_ACCOUNT(cursor->data));
720 if (acc_id && strcmp (acc_id, id) == 0) {
721 account = TNY_ACCOUNT(cursor->data);
727 g_object_ref (G_OBJECT(account));
733 modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self,
734 const gchar *account_name,
737 TnyAccount *account = NULL;
738 ModestAccountData *account_data;
739 const gchar *id = NULL;
740 ModestTnyAccountStorePrivate *priv;
742 g_return_val_if_fail (self, NULL);
743 g_return_val_if_fail (account_name, NULL);
744 g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
747 priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
749 account_data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
751 g_printerr ("modest: cannot get account data for account '%s'\n", account_name);
755 if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
756 id = account_data->store_account->account_name;
757 else if (account_data->transport_account)
758 id = account_data->transport_account->account_name;
761 g_printerr ("modest: could not get an id for account %s\n",
764 account = modest_tny_account_store_get_tny_account_by_id (self, id);
767 g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
768 type == TNY_ACCOUNT_TYPE_STORE? "store" : "transport",
769 account_name, id ? id : "<none>");
771 modest_account_mgr_free_account_data (priv->account_mgr, account_data);
775 static TnyAccount* get_smtp_specific_transport_account_for_open_connection (ModestTnyAccountStore *self, const gchar *account_name)
777 /* Get the current connection: */
778 TnyDevice *device = modest_runtime_get_device ();
780 if (!tny_device_is_online (device))
783 g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
784 TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
785 const gchar* iap_id = tny_maemo_conic_device_get_current_iap_id (maemo_device);
789 ConIcIap* connection = tny_maemo_conic_device_get_iap (maemo_device, iap_id);
793 const gchar *connection_name = con_ic_iap_get_name (connection);
794 if (!connection_name)
797 /* Get the connection-specific transport acccount, if any: */
798 ModestAccountMgr *account_manager = modest_runtime_get_account_mgr ();
799 gchar* server_account_name = modest_account_mgr_get_connection_specific_smtp (account_manager,
800 account_name, connection_name);
802 if (!server_account_name)
803 return NULL; /* No connection-specific SMTP server was specified for this connection. */
805 TnyAccount* account = modest_tny_account_store_get_tny_account_by_id (self, server_account_name);
806 g_free (server_account_name);
808 /* Unref the get()ed object, as required by the tny_maemo_conic_device_get_iap() documentation. */
809 g_object_unref (connection);
815 TnyAccount* modest_tny_account_store_get_transport_account_for_open_connection (ModestTnyAccountStore *self,
816 const gchar *account_name)
818 /* Get the connection-specific transport acccount, if any: */
819 TnyAccount *account = get_smtp_specific_transport_account_for_open_connection (self, account_name);
821 /* If there is no connection-specific transport account (the common case),
822 * just get the regular transport account: */
824 account = modest_tny_account_store_get_tny_account_by_account (self, account_name,
825 TNY_ACCOUNT_TYPE_TRANSPORT);