+modest_msg_view_window_new_from_uid (const gchar *modest_account_name,
+ const gchar *mailbox,
+ const gchar *msg_uid)
+{
+ ModestMsgViewWindow *window = NULL;
+ ModestMsgViewWindowPrivate *priv = NULL;
+ ModestWindowMgr *mgr = NULL;
+ gboolean is_merge;
+ TnyAccount *account = NULL;
+
+ mgr = modest_runtime_get_window_mgr ();
+ window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
+
+ modest_msg_view_window_construct (window, modest_account_name, mailbox, msg_uid);
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+
+
+
+ is_merge = g_str_has_prefix (msg_uid, "merge:");
+
+ /* Get the account */
+ if (!is_merge)
+ account = tny_account_store_find_account (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
+ msg_uid);
+
+
+ if (is_merge || account) {
+ TnyFolder *folder = NULL;
+
+ /* Try to get the message, if it's already downloaded
+ we don't need to connect */
+ if (account) {
+ folder = modest_tny_folder_store_find_folder_from_uri (TNY_FOLDER_STORE (account), msg_uid);
+ } else {
+ ModestTnyAccountStore *account_store;
+ ModestTnyLocalFoldersAccount *local_folders_account;
+
+ account_store = modest_runtime_get_account_store ();
+ local_folders_account = MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (
+ modest_tny_account_store_get_local_folders_account (account_store));
+ folder = modest_tny_local_folders_account_get_merged_outbox (local_folders_account);
+ g_object_unref (local_folders_account);
+ }
+ if (folder) {
+ TnyDevice *device;
+ gboolean device_online;
+
+ device = modest_runtime_get_device();
+ device_online = tny_device_is_online (device);
+ if (device_online) {
+ message_reader (window, priv, NULL, msg_uid, folder, NULL);
+ } else {
+ TnyMsg *msg = tny_folder_find_msg (folder, msg_uid, NULL);
+ if (msg) {
+ tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+ update_window_title (MODEST_MSG_VIEW_WINDOW (window));
+ update_branding (MODEST_MSG_VIEW_WINDOW (window));
+ g_object_unref (msg);
+ } else {
+ message_reader (window, priv, NULL, msg_uid, folder, NULL);
+ }
+ }
+ g_object_unref (folder);
+ }
+
+ }
+
+ /* Check dimming rules */
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+ modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
+
+ return MODEST_WINDOW(window);
+}
+
+ModestWindow *
+modest_msg_view_window_new_from_header_view (ModestHeaderView *header_view,
+ const gchar *modest_account_name,
+ const gchar *mailbox,
+ const gchar *msg_uid,
+ GtkTreeRowReference *row_reference)