* fix some of the fallout of the last commit
[modest] / src / widgets / modest-gtkhtml-msg-view.c
index 2151371..bb8e8a6 100644 (file)
 #include <widgets/modest-gtkhtml-msg-view.h>
 #include <widgets/modest-isearch-view.h>
 
+/* FIXNE: we should have no maemo-deps in widgets/ */
+#ifdef MODEST_PLATFORM_MAEMO
+#include "maemo/modest-hildon-includes.h"
+#endif /*MODEST_PLATFORM_MAEMO*/
+
 
 /* 'private'/'protected' functions */
 static void     modest_gtkhtml_msg_view_class_init   (ModestGtkhtmlMsgViewClass *klass);
@@ -969,6 +974,10 @@ html_adjustment_changed (GtkAdjustment *adj,
 gboolean
 idle_readjust_scroll (ModestGtkhtmlMsgView *self)
 {
+
+       /* We're out the main lock */
+       gdk_threads_enter ();
+
        if (GTK_WIDGET_DRAWABLE (self)) {
                ModestGtkhtmlMsgViewPrivate *priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE (self);
                GtkAdjustment *html_vadj;
@@ -985,6 +994,9 @@ idle_readjust_scroll (ModestGtkhtmlMsgView *self)
                gtk_adjustment_set_value (priv->vadj, 0.0);
        }
        g_object_unref (G_OBJECT (self));
+
+       gdk_threads_leave ();
+
        return FALSE;
 }
 
@@ -1315,6 +1327,13 @@ find_cid_image (TnyMsg *msg, const gchar *cid)
                part = TNY_MIME_PART(tny_iterator_get_current(iter));
                part_cid = tny_mime_part_get_content_id (part);
 
+               /* if there is no content id, try the content location;
+                * this is what Outlook seems to use when it converts
+                * it's internal richtext to html
+                */
+               if (!part_cid)
+                       part_cid = tny_mime_part_get_content_location (part);
+               
                if (part_cid && strcmp (cid, part_cid) == 0)
                        break;
 
@@ -1364,26 +1383,34 @@ on_fetch_url (GtkWidget *widget, const gchar *uri,
              TnyStream *stream, ModestGtkhtmlMsgView *self)
 {
        ModestGtkhtmlMsgViewPrivate *priv;
+       const gchar* my_uri;
+       TnyMimePart *part = NULL;
+       
        priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE (self);
-       gboolean result = FALSE;
        
-       if (g_str_has_prefix (uri, "cid:")) {
-               /* +4 ==> skip "cid:" */
-               TnyMimePart *part = find_cid_image (priv->msg, uri + 4);
-               if (!part) {
-                       g_printerr ("modest: '%s' not found\n", uri + 4);
-                       result = FALSE;
-               } else {
-                       tny_mime_part_decode_to_stream ((TnyMimePart*)part,
-                                                       stream);
-                       g_object_unref (G_OBJECT(part));
-                       result = TRUE;
-               }
-       } else {
-               return TRUE;
+       /*
+        * we search for either something starting with cid:, or something
+        * with no prefix at all; this latter case occurs when sending mails
+        * with MS Outlook in rich-text mode, and 'attach-as-object
+        */
+       if (g_str_has_prefix (uri, "cid:"))  
+               my_uri = uri + 4;  /* +4 ==> skip "cid:" */
+       else if (g_strstr_len (uri, strlen(uri), ":") == NULL)
+               my_uri = uri;      /* for outlook, no cid:, we check for ':',
+                                   * so external locations are excluded */
+       else
+               return FALSE; /* we don't support non-embedded images */
+       
+       /* now try to find the embedded image */
+       part = find_cid_image (priv->msg, my_uri);
+       if (!part) {
+               g_printerr ("modest: %s: '%s' not found\n", __FUNCTION__, my_uri);
+               return FALSE;   
        }
 
-       return result;
+       tny_mime_part_decode_to_stream ((TnyMimePart*)part, stream);
+       g_object_unref (G_OBJECT(part));
+       return TRUE;
 }
 
 static void
@@ -1399,6 +1426,12 @@ set_message (ModestGtkhtmlMsgView *self, TnyMsg *msg)
        priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE(self);
        gtk_widget_set_no_show_all (priv->mail_header_view, FALSE);
 
+       html_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->html_scroll));
+       html_vadj->upper = 0;
+       html_vadj->page_size = 0;
+       g_signal_emit_by_name (G_OBJECT (html_vadj), "changed");
+
+
        if (msg != priv->msg) {
                if (priv->msg)
                        g_object_unref (G_OBJECT(priv->msg));
@@ -1452,8 +1485,6 @@ set_message (ModestGtkhtmlMsgView *self, TnyMsg *msg)
        if (priv->vadj != NULL)
                priv->vadj->value = 0.0;
 
-       html_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->html_scroll));
-
        g_signal_emit_by_name (G_OBJECT (html_vadj), "changed");
 
        /* This is a hack to force reallocation of scroll after drawing all the stuff. This