Modified webpage: now tinymail repository is in gitorious.
[modest] / src / modest-tny-account-store.c
index f78d7bb..b560a8e 100644 (file)
@@ -62,6 +62,8 @@
 #include <modest-platform.h>
 #include "modest-ui-actions.h"
 #include <widgets/modest-account-settings-dialog.h>
+#include <tny-camel-bs-msg-receive-strategy.h>
+#include <modest-tny-msg.h>
 
 #ifdef MODEST_PLATFORM_MAEMO
 #include <tny-maemo-conic-device.h>
@@ -456,11 +458,29 @@ on_account_changed (ModestAccountMgr *acc_mgr,
 }
 
 static void
-show_wrong_password_dialog (TnyAccount *account,
+show_wrong_password_dialog (TnyAccountStore *self,
+                           TnyAccount *account,
                            gboolean show_banner)
 {
+       TnyDevice *device;
+       gboolean is_online;
+
        g_debug ("%s: %s", __FUNCTION__, tny_account_get_id (account));
 
+       device = tny_account_store_get_device (self);
+       is_online = tny_device_is_online (device);
+       g_object_unref (device);
+
+       if (!is_online) {
+               g_debug ("%s: not showing the acc settings dialog. Device OFFLINE", __FUNCTION__);
+               return;
+       }
+
+       if (modest_window_mgr_get_num_windows (modest_runtime_get_window_mgr ()) == 0) {
+               g_debug ("%s: not showing the account settings dialog. NO windows", __FUNCTION__);
+               return;
+       }
+
        if (g_object_get_data (G_OBJECT (account), "connection_specific") != NULL) {
                modest_ui_actions_on_smtp_servers (NULL, NULL);
        } else {
@@ -478,17 +498,18 @@ show_wrong_password_dialog (TnyAccount *account,
 
                /* Create and show the dialog */
                if (proto && MODEST_IS_ACCOUNT_PROTOCOL (proto)) {
-                       GtkWindow *parent;
-                       ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
                        ModestAccountSettingsDialog *dialog =
                                modest_account_protocol_get_account_settings_dialog (proto, modest_account_name);
 
-                       parent = modest_window_mgr_get_modal (mgr);
-                       if (!parent)
-                               parent = (GtkWindow *) modest_window_mgr_get_current_top (mgr);
+                       if (dialog) {
+                               ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
+                               GtkWindow *parent = modest_window_mgr_get_modal (mgr);
+                               if (!parent)
+                                       parent = (GtkWindow *) modest_window_mgr_get_current_top (mgr);
 
-                       modest_window_mgr_set_modal (mgr, GTK_WINDOW (dialog), parent);
-                       gtk_widget_show (GTK_WIDGET (dialog));
+                               modest_window_mgr_set_modal (mgr, GTK_WINDOW (dialog), parent);
+                               gtk_widget_show (GTK_WIDGET (dialog));
+                       }
                }
        }
        /* Show an explanatory temporary banner: */
@@ -639,7 +660,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
                                                                                             server_account_name);
                                /* If the login has ever succeeded then show a specific message */
                                if (username_known)
-                                       msg = _CS ("ecdg_ib_set_password_incorrect");
+                                       msg = _CS_SET_PASSWORD_INCORRECT;
                                else
                                        msg = _("mcen_ib_username_pw_incorrect");
                                if (modest_window_mgr_get_num_windows (modest_runtime_get_window_mgr ()))
@@ -649,16 +670,11 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
 
                if (settings_have_password) {
                        if (pwd) {
-
-                               /* Never show it if the UI is not launched */
-                               if (modest_window_mgr_get_num_windows (modest_runtime_get_window_mgr ())) {
-                                       g_debug ("%s: going to show the dialog (%d windows)", __FUNCTION__,
-                                                modest_window_mgr_get_num_windows (modest_runtime_get_window_mgr ()));
-                                       /* The password must be wrong, so show the account settings dialog so it can be corrected: */
-                                       show_wrong_password_dialog (account, TRUE);
-                               } else {
-                                       g_debug ("%s: not showing the dialog (no windows)", __FUNCTION__);
-                               }
+                               /* The password must be wrong, so show
+                                  the account settings dialog so it
+                                  can be corrected: */
+                               g_debug ("%s: going to show the settings dialog", __FUNCTION__);
+                               show_wrong_password_dialog ((TnyAccountStore *) self, account, TRUE);
 
                                if (cancel)
                                        *cancel = TRUE;
@@ -666,8 +682,9 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
                                return NULL;
                        } else {
                                /* Get the password from the account settings */
-                                return modest_account_mgr_get_server_account_password (priv->account_mgr, server_account_name);
-                        }
+                               return modest_account_mgr_get_server_account_password (priv->account_mgr,
+                                                                                      server_account_name);
+                       }
                }
 
                /* we don't have it yet. Get the password from the user */
@@ -864,6 +881,36 @@ volume_path_is_mounted (const gchar* path)
        return result;
 }
 
+static void _bodies_filter (TnyMsg *msg, TnyList *list)
+{
+       TnyMimePart *html_part, *text_part, *calendar_part;
+
+       html_part = modest_tny_msg_find_body_part (msg, TRUE);
+       text_part = modest_tny_msg_find_body_part (msg, FALSE);
+       calendar_part = modest_tny_msg_find_calendar (msg);
+
+       if (text_part && TNY_IS_MIME_PART (text_part) && html_part == text_part) {
+               g_object_unref (text_part);
+               text_part = NULL;
+       }
+
+       if (html_part && TNY_IS_MIME_PART (html_part)) {
+               tny_list_prepend (list, G_OBJECT (html_part));
+               g_object_unref (html_part);
+       }
+
+       if (text_part && TNY_IS_MIME_PART (text_part)) {
+               tny_list_prepend (list, G_OBJECT (text_part));
+               g_object_unref (text_part);
+       }
+
+       if (calendar_part && TNY_IS_MIME_PART (calendar_part)) {
+               tny_list_prepend (list, G_OBJECT (calendar_part));
+               g_object_unref (calendar_part);
+       }
+}
+
+
 ModestTnyAccountStore*
 modest_tny_account_store_new (ModestAccountMgr *account_mgr,
                              TnyDevice *device)
@@ -874,10 +921,14 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr,
        TnyLockable *lockable;
        GnomeVFSVolumeMonitor* monitor = NULL;
        gboolean auto_update;
+       const gchar *mmc_path = NULL;
 
        g_return_val_if_fail (account_mgr, NULL);
        g_return_val_if_fail (device, NULL);
 
+       tny_camel_bs_msg_receive_strategy_set_global_bodies_filter (
+               (TnyCamelBsMsgReceiveStrategyBodiesFilter) _bodies_filter);
+
        obj  = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL));
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
@@ -949,7 +1000,8 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr,
                add_connection_specific_transport_accounts (MODEST_TNY_ACCOUNT_STORE(obj));
 
        /* This is a singleton, so it does not need to be unrefed. */
-       if (volume_path_is_mounted (g_getenv (MODEST_MMC1_VOLUMEPATH_ENV))) {
+       mmc_path = g_getenv (MODEST_MMC1_VOLUMEPATH_ENV);
+       if (mmc_path && volume_path_is_mounted (mmc_path)) {
                /* It is mounted: */
                add_mmc_account (MODEST_TNY_ACCOUNT_STORE (obj), FALSE /* don't emit the insert signal. */);
        }
@@ -1130,27 +1182,20 @@ modest_tny_account_store_alert (TnyAccountStore *self,
                                                                                        tny_account_get_id (account));
 
                if (!success) {
+                       gboolean show_banner;
+
                        g_debug ("%s: %s alert received (%s)", __FUNCTION__,
                                 (error->code == TNY_SERVICE_ERROR_CONNECT) ? "connect" : "aunthenticate",
                                 error->message);
 
-                       modest_platform_run_information_dialog (NULL, prompt, TRUE);
-
-                       /* Show the account dialog. Checking the
-                          online status allows us to minimize the
-                          number of times that we incorrectly show
-                          the dialog. Also do not show it if the UI
-                          is not launched */
                        if (tny_device_is_online (device) &&
-                           modest_window_mgr_get_num_windows (modest_runtime_get_window_mgr ())) {
-                               show_wrong_password_dialog (account,
-                                                           (error->code == TNY_SERVICE_ERROR_CONNECT) ? FALSE : TRUE);
-                       } else {
-                               if (tny_device_is_online (device))
-                                       g_debug ("%s: not showing the dialog (no windows)", __FUNCTION__);
-                               else
-                                       g_debug ("%s: not showing the dialog (no connection)", __FUNCTION__);
-                       }
+                           modest_window_mgr_get_num_windows (modest_runtime_get_window_mgr ()))
+                               modest_platform_run_information_dialog (NULL, prompt, TRUE);
+
+                       /* Show the account dialog */
+                       show_banner = (error->code == TNY_SERVICE_ERROR_CONNECT) ? FALSE : TRUE;
+                       g_debug ("%s: going to show settings dialog", __FUNCTION__);
+                       show_wrong_password_dialog (self, account, show_banner);
                        retval = TRUE;
                }
        }