* modest-tny-msg.c:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 5 Nov 2007 10:32:42 +0000 (10:32 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 5 Nov 2007 10:32:42 +0000 (10:32 +0000)
- fix leak when searching through multipart/ messages
  (modest_tny_msg_find_body_part_from_mime_part)
* modest-account-mgr.c:
- fix possible NULL dereference
* modest-ui-actions.c:
- remove some dead code
- fix possible NULL dereference
* modest-platform.c:
- small cleanup

pmo-trunk-r3631

src/maemo/modest-platform.c
src/modest-account-mgr.c
src/modest-tny-msg.c
src/modest-ui-actions.c

index 7a71612..50718b9 100644 (file)
@@ -1518,17 +1518,14 @@ typedef struct
 #define NUMBER_OF_TRIES 10 /* Try approx every second, ten times. */
 
 static gboolean 
-on_timeout_check_account_is_online(gpointer user_data)
+on_timeout_check_account_is_online(CheckAccountIdleData* data)
 {
-       printf ("DEBUG: %s:\n", __FUNCTION__);
-       CheckAccountIdleData *data = (CheckAccountIdleData*)user_data;
-
+       gboolean stop_trying = FALSE;
        g_return_val_if_fail (data && data->account, FALSE);
        
        printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n", __FUNCTION__,
                tny_account_get_connection_status (data->account));     
        
-       gboolean stop_trying = FALSE;
        if (data && data->account && 
                /* We want to wait until TNY_CONNECTION_STATUS_INIT has changed to something else,
                 * after which the account is likely to be usable, or never likely to be usable soon: */
@@ -1537,14 +1534,11 @@ on_timeout_check_account_is_online(gpointer user_data)
                data->is_online = TRUE;
                
                stop_trying = TRUE;
-       }
-       else {
+       } else {
                /* Give up if we have tried too many times: */
-               if (data->count_tries >= NUMBER_OF_TRIES)
-               {
+               if (data->count_tries >= NUMBER_OF_TRIES) {
                        stop_trying = TRUE;
-               }
-               else {
+               } else {
                        /* Wait for another timeout: */
                        ++(data->count_tries);
                }
@@ -1611,7 +1605,7 @@ modest_platform_check_and_wait_for_account_is_online(TnyAccount *account)
        GMainContext *context = NULL; /* g_main_context_new (); */
        data->loop = g_main_loop_new (context, FALSE /* not running */);
 
-       g_timeout_add (1000, on_timeout_check_account_is_online, data);
+       g_timeout_add (1000, (GSourceFunc)(on_timeout_check_account_is_online), data);
 
        /* This main loop will run until the idle handler has stopped it: */
        g_main_loop_run (data->loop);
index d37c498..0999a90 100644 (file)
@@ -1167,8 +1167,9 @@ _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar*
                retval = g_strconcat (namespace, "/", escaped_account_name, NULL);
 
        /* Sanity check: */
-       if (!modest_conf_key_is_valid (retval)) {
-               g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__, retval);
+       if (!retval || !modest_conf_key_is_valid (retval)) {
+               g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__,
+                          retval ? retval: "<empty>");
                g_free (retval);
                retval = NULL;
        }
index 857d065..3cec8ad 100644 (file)
@@ -359,11 +359,11 @@ modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html, gboolean *is_html)
 TnyMimePart*
 modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_html)
 {
-       const gchar *mime_type = want_html ? "text/html" : "text/plain";
+       const gchar *desired_mime_type = want_html ? "text/html" : "text/plain";
        TnyMimePart *part = NULL;
        TnyList *parts = NULL;
        TnyIterator *iter = NULL;
-
+       
        if (!msg)
                return NULL;
 
@@ -377,45 +377,53 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
                g_object_unref (G_OBJECT(iter));
                return TNY_MIME_PART (g_object_ref(G_OBJECT(msg)));
        } else {
-               gchar *content_type = NULL;
                do {
+                       gchar *content_type = NULL;
+                       
                        part = TNY_MIME_PART(tny_iterator_get_current (iter));
+
+                       if (!part) {
+                               g_warning ("%s: not a valid mime part", __FUNCTION__);
+                               continue;
+                       }
+
+                       /* it's a message --> ignore */
                        if (part && TNY_IS_MSG (part)) {
                                g_object_unref (part);
                                tny_iterator_next (iter);
                                continue;
                        }
+                       
 
                        /* we need to strdown the content type, because
                         * tny_mime_part_has_content_type does not do it...
                         */
-                       if (part) {
-                               content_type = g_ascii_strdown
-                                       (tny_mime_part_get_content_type (part), -1);
-                       }
-                                                       
-                       if (g_str_has_prefix (content_type, mime_type) &&
-                           !tny_mime_part_is_attachment (part))
+                       content_type = g_ascii_strdown (tny_mime_part_get_content_type (part), -1);
+
+                       if (g_str_has_prefix (content_type, desired_mime_type) && !tny_mime_part_is_attachment (part)) {
+                               /* we found the desired mime-type! */
+                               g_free (content_type);
                                break;
-                       
-                       if (g_str_has_prefix(content_type, "multipart")) {
+
+                       } else  if (g_str_has_prefix(content_type, "multipart")) {
+
+                               /* multipart? recurse! */
+                               g_object_unref (part);
+                               g_free (content_type);
                                part = modest_tny_msg_find_body_part_from_mime_part (part, want_html);
                                if (part)
                                        break;
-                       }
-
-                       if (part)
+                       } else
+                               g_free (content_type);
+                       
+                       if (part) {
                                g_object_unref (G_OBJECT(part));
-
-                       part = NULL;
+                               part = NULL;
+                       }
                        
-                       g_free (content_type);
-                       content_type = NULL;
-
                        tny_iterator_next (iter);
                        
                } while (!tny_iterator_is_done(iter));
-               g_free (content_type);
        }
        
        g_object_unref (G_OBJECT(iter));
index 5f7c8e3..3f83b27 100644 (file)
@@ -493,7 +493,6 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                GtkTreeRowReference *prev_row_reference = NULL;
                GtkTreePath *next_path = NULL;
                GtkTreePath *prev_path = NULL;
-               GError *err = NULL;
 
                /* Find last selected row */                    
                if (MODEST_IS_MAIN_WINDOW (win)) {
@@ -555,11 +554,6 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                        if (prev_path != NULL) 
                                gtk_tree_path_free (prev_path);                         
                }
-
-               if (err != NULL) {
-                       printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, err->code, err->message);
-                       g_error_free(err);
-               }
                
                /* Update toolbar dimming state */
                modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
@@ -2834,7 +2828,6 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
                                         ModestMainWindow *main_window)
 {
        g_return_if_fail(server_account_name);
-       /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
        
        /* Initalize output parameters: */
        if (cancel)
@@ -2872,7 +2865,8 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
                modest_runtime_get_account_mgr(), server_account_name);
        if (!server_name) {/* This happened once, though I don't know why. murrayc. */
                g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
-               *cancel = TRUE;
+               if (cancel)
+                       *cancel = TRUE;
                return;
        }