* Fixes NB#86225, do not open drafts using the active account if they have been...
authorSergio Villar Senin <svillar@igalia.com>
Mon, 21 Jul 2008 08:53:46 +0000 (08:53 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 21 Jul 2008 08:53:46 +0000 (08:53 +0000)
pmo-trunk-r5067

src/dbus_api/modest-dbus-callbacks.c
src/modest-ui-actions.c
src/modest-utils.c
src/modest-utils.h

index 54c5e11..3432018 100644 (file)
@@ -34,6 +34,7 @@
 #include "modest-tny-account.h"
 #include "modest-tny-folder.h"
 #include "modest-ui-actions.h"
+#include "modest-utils.h"
 #include "modest-debug.h"
 #include "modest-search.h"
 #include "widgets/modest-msg-edit-window.h"
@@ -499,27 +500,12 @@ find_msg_async_cb (TnyFolder *folder,
                        }
                
                        from_header = tny_header_dup_from (header);
-                       if (from_header) {
-                               GSList *accounts = modest_account_mgr_account_names (modest_runtime_get_account_mgr (), TRUE);
-                               GSList *node = NULL;
-                               for (node = accounts; node != NULL; node = g_slist_next (node)) {
-                                       gchar *from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr (), node->data);
-                                       
-                                       if (from && (strcmp (from_header, from) == 0)) {
-                                               g_free (modest_account_name);
-                                               modest_account_name = g_strdup (node->data);
-                                               g_free (from);
-                                               break;
-                                       }
-                                       g_free (from);
-                               }
-                               g_slist_foreach (accounts, (GFunc) g_free, NULL);
-                               g_slist_free (accounts);
-                               g_free (from_header);
-                       }
+                       modest_account_name = modest_utils_get_account_name_from_recipient (from_header);
+                       g_free (from_header);
                        
                        if (modest_account_name == NULL) {
-                               modest_account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
+                               ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
+                               modest_account_name = modest_account_mgr_get_default_account (mgr);
                        }
                         msg_view = modest_msg_edit_window_new (msg, modest_account_name, TRUE);
                        g_free (modest_account_name);
index a0b9bce..e4ace6a 100644 (file)
@@ -935,45 +935,27 @@ open_msg_cb (ModestMailOperation *mail_op,
        
        if (open_in_editor) {
                ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
-               gchar *from_header = NULL;
+               gchar *from_header = NULL, *acc_name;
 
                from_header = tny_header_dup_from (header);
 
                /* we cannot edit without a valid account... */
                if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
                        if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
-                               modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), 
+                               modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
                                                                     header);
                                g_free (from_header);
                                goto cleanup;
                        }
                }
-               
-               if (from_header) {
-                       GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
-                       GSList *node = NULL;
-
-                       for (node = accounts; node != NULL; node = g_slist_next (node)) {
-                               gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
-                               
-                               if (from && (strcmp (from_header, from) == 0)) {
-                                       g_free (account);
-                                       account = g_strdup (node->data);
-                                       g_free (from);
-                                       break;
-                               }
-                               g_free (from);
-                       }
 
-                       g_free (from_header);
-                       g_slist_foreach (accounts, (GFunc) g_free, NULL);
-                       g_slist_free (accounts);
+               acc_name = modest_utils_get_account_name_from_recipient (from_header);
+               if (acc_name) {
+                       g_free (account);
+                       account = acc_name;
                }
 
                win = modest_msg_edit_window_new (msg, account, TRUE);
-
-
-
        } else {
                gchar *uid = modest_tny_folder_get_header_unique_id (header);
                
index 990bd2f..3ac90cc 100644 (file)
@@ -43,6 +43,8 @@
 #include <modest-defs.h>
 #include "modest-utils.h"
 #include "modest-platform.h"
+#include "modest-account-mgr-helpers.h"
+#include "modest-text-utils.h"
 #include <modest-local-folder-info.h>
 #include "widgets/modest-header-view.h"
 #include "widgets/modest-main-window.h"
@@ -735,3 +737,41 @@ modest_images_cache_get_id (const gchar *account, const gchar *uri)
  
        return result;
 }
+
+gchar *
+modest_utils_get_account_name_from_recipient (const gchar *from_header)
+{
+       gchar *account_name = NULL;
+       ModestAccountMgr *mgr = NULL;
+       GSList *accounts = NULL, *node = 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 = 
+                       modest_account_mgr_get_from_string (mgr, node->data);
+                       
+               if (from) {
+                       gchar *from_email = 
+                               modest_text_utils_get_email_address (from);
+                               
+                       if (from_email) {
+                               if (!modest_text_utils_utf8_strcmp (from_header, from_email, TRUE)) {
+                                       account_name = g_strdup (node->data);
+                                       g_free (from);
+                                       g_free (from_email);
+                                       break;
+                               }
+                               g_free (from_email);
+                       }
+                       g_free (from);
+               }
+       }
+       g_slist_foreach (accounts, (GFunc) g_free, NULL);
+       g_slist_free (accounts);
+
+       return account_name;
+}
index bf2dbed..b496a7f 100644 (file)
@@ -172,4 +172,16 @@ guint64 modest_utils_get_available_space (const gchar *maildir_path);
  */
 gchar *modest_images_cache_get_id (const gchar *account, const gchar *uri);
 
+
+/**
+ * modest_utils_get_account_name_from_recipient:
+ * @from: the result of a call to tny_header_dup_from
+ *
+ * returns the account name that corresponds to the given from address
+ *
+ * Returns: a newly allocated string containing the account name or
+ * %NULL in case of error
+ */
+gchar *modest_utils_get_account_name_from_recipient (const gchar *from);
+
 #endif /*__MODEST_MAEMO_UTILS_H__*/