From: Jose Dapena Paz Date: Thu, 2 Apr 2009 20:57:20 +0000 (+0000) Subject: Implement proper fetch of mailbox and account id from recipient X-Git-Tag: git_migration_finished~148 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=bb2af3f3812101dd2947281c76030875d85c210a Implement proper fetch of mailbox and account id from recipient pmo-trunk-r8569 --- diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index 9b46b4b..0cb3db2 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -852,22 +852,53 @@ modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self) } gchar* -modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name) +modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name, const gchar *mailbox) { - gchar *fullname, *email, *from; + gchar **from; g_return_val_if_fail (self, NULL); g_return_val_if_fail (name, NULL); - fullname = modest_account_mgr_get_string (self, name,MODEST_ACCOUNT_FULLNAME, - FALSE); - email = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_EMAIL, - FALSE); - from = g_strdup_printf ("%s <%s>", - fullname ? fullname : "", - email ? email : ""); - g_free (fullname); - g_free (email); + from = NULL; + + if (mailbox) { + gchar *transport_account; + gchar *proto; + + transport_account = modest_account_mgr_get_server_account_name (self, + name, + TNY_ACCOUNT_TYPE_TRANSPORT); + if (transport_account) { + proto = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_PROTO, TRUE); + if (proto != NULL) { + ModestProtocol *protocol = + modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (), + MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, + TRUE); + if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) { + from = modest_account_protocol_get_from (MODEST_ACCOUNT_PROTOCOL (protocol), + name, + mailbox); + } + g_free (proto); + } + + } + } + + if (from == NULL) { + gchar *fullname, *email; + + fullname = modest_account_mgr_get_string (self, name,MODEST_ACCOUNT_FULLNAME, + FALSE); + email = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_EMAIL, + FALSE); + from = g_strdup_printf ("%s <%s>", + fullname ? fullname : "", + email ? email : ""); + g_free (fullname); + g_free (email); + } return from; } diff --git a/src/modest-account-mgr-helpers.h b/src/modest-account-mgr-helpers.h index be552b5..8cd26ea 100644 --- a/src/modest-account-mgr-helpers.h +++ b/src/modest-account-mgr-helpers.h @@ -358,12 +358,13 @@ ModestServerAccountSettings *modest_account_mgr_load_server_settings (ModestAcco * modest_account_mgr_get_from_string * @self: a #ModestAccountMgr instance * @name: the account name + * @mailbox: the mailbox * * get the From: string for some account; ie. "Foo Bar" <foo.bar@cuux.yy>" * * Returns: the newly allocated from-string, or NULL in case of error */ -gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name); +gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name, const gchar *mailbox); /** diff --git a/src/modest-utils.c b/src/modest-utils.c index a36dc59..7f6f17b 100644 --- a/src/modest-utils.c +++ b/src/modest-utils.c @@ -727,13 +727,18 @@ modest_utils_get_account_name_from_recipient (const gchar *from_header, gchar ** ModestAccountMgr *mgr = NULL; GSList *accounts = NULL, *node = NULL; + if (mailbox) + *mailbox = NULL; g_return_val_if_fail (from_header, NULL); mgr = modest_runtime_get_account_mgr (); accounts = modest_account_mgr_account_names (mgr, TRUE); for (node = accounts; node != NULL; node = g_slist_next (node)) { - gchar *from = + gchar *from; + gchar *proto; + + from = modest_account_mgr_get_from_string (mgr, node->data); if (from) { @@ -754,6 +759,35 @@ modest_utils_get_account_name_from_recipient (const gchar *from_header, gchar ** g_free (from_header_email); g_free (from); } + proto = modest_account_mgr_get_string (self, node->data, MODEST_ACCOUNT_PROTO, TRUE); + if (proto != NULL) { + ModestProtocol *protocol = + modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (), + MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, + proto); + if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) { + ModestPairList *pair_list; + ModestPair *pair; + gchar *from_header_email = + modest_text_utils_get_email_address (from_header); + pair_list = modest_account_protocol_get_from_list (MODEST_ACCOUNT_PROTOCOL (protocol), + node->data); + + pair = modest_pair_list_find_by_first_as_string (pair_list, from_header_email); + if (pair != NULL) { + account_name = g_strdup (node->data); + if (mailbox) + *mailbox = g_strdup (from_header_email); + } + + modest_pair_list_free (pair_list); + + } + g_free (proto); + } + if (mailbox && *mailbox) + break; + } g_slist_foreach (accounts, (GFunc) g_free, NULL); g_slist_free (accounts);