[evolution-rss] fix bug 562759 – replying does not preserve image source



commit 4e51df4966799f959791ebd1fd682cf1d9253ada
Author: Lucian Langa <lucilanga gnome org>
Date:   Fri Jul 3 23:23:39 2009 +0300

    fix bug 562759 â?? replying does not preserve image source

 TODO                                  |    4 +--
 src/misc.c                            |   42 ++++++++++----------------------
 src/org-gnome-evolution-rss.eplug.xml |    4 +++
 src/parser.c                          |   27 +++++++++++++++++++++
 src/parser.h                          |    1 +
 src/rss.c                             |   24 ++++++++++++++++++
 6 files changed, 70 insertions(+), 32 deletions(-)
---
diff --git a/TODO b/TODO
index afdebd3..3e12884 100644
--- a/TODO
+++ b/TODO
@@ -7,7 +7,6 @@
 	* jump to folder when adding through d-bus
 	* implement other engines besides soup
 	* implement USM (universal subscription mechanism)
-	* make auth dialog not intrusive (peek others)
 	* implement notify back of imported feed perhaps libnotify
 	* offline storage for article's home page
 	* implement web controls for diferent redering <Webkits> or <Gecko>
@@ -19,7 +18,6 @@
 	* fix annoying cursor jump when browsing through evo-rss folders
 	* provide predefined groups of feeds (OSS & co)
 	* evolution import rss add no. of retries
-	* fix images when replying
 	* provide expire option for images
 	* slow delete operation on large folders
 	* add handling parser error to setup_feed (check HIG for error msg)
@@ -38,7 +36,7 @@
 	* handle 404 for images in comments
 	* gtkhtml does not handle script tag properly
 	* gtkhtml does not handle &#xD; construct
-	* switch webkit -> gecko leeds to crash on pfree()
+	* switch webkit -> gecko leads to crash on pfree()
 	* show feed icons in send & receive dialog
 	* favicon is not displayed after it is fetched
 	* cancel fetching comments when summary display is changed
diff --git a/src/misc.c b/src/misc.c
index f41ea87..c75df29 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -191,14 +191,11 @@ strplchr(gchar *source)
  	gchar *string;
         const unsigned char *s = (const unsigned char *)source;
         guint len = strlen(source);
-        while (*s != 0 || len)
-        {
-             if (*s == 0x3f)
-             {
+        while (*s != 0 || len) {
+             if (*s == 0x3f) {
                    g_string_append(str, "%3F");
                    s++;
-             }
-             else
+             } else
                    g_string_append_c (str, *s++);
              len--;
         }
@@ -226,35 +223,25 @@ markup_decode (gchar *str)
                         int jump = 0;
                         int i;
 
-                        if (g_ascii_strncasecmp (iterator, "&amp;", 5) == 0)
-                        {
+                        if (g_ascii_strncasecmp (iterator, "&amp;", 5) == 0) {
                                 g_string_append_c (result, '&');
                                 jump = 5;
-                        }
-                        else if (g_ascii_strncasecmp (iterator, "&lt;", 4) == 0)
-                        {
+                        } else if (g_ascii_strncasecmp (iterator, "&lt;", 4) == 0) {
                                 g_string_append_c (result, '<');
                                 jump = 4;
-                        }
-                        else if (g_ascii_strncasecmp (iterator, "&gt;", 4) == 0)
-                        {
+                        } else if (g_ascii_strncasecmp (iterator, "&gt;", 4) == 0) {
                                 g_string_append_c (result, '>');
                                 jump = 4;
-                        }
-                        else if (g_ascii_strncasecmp (iterator, "&quot;", 6) == 0)
-                        {
+                        } else if (g_ascii_strncasecmp (iterator, "&quot;", 6) == 0) {
                                 g_string_append_c (result, '\"');
                                 jump = 6;
                         }
-                        for (i = jump - 1; i > 0; i--)
-                        {
+                        for (i = jump - 1; i > 0; i--) {
                                 iterator++;
                                 if (*iterator == '\0')
                                         break;
                         }
-                }
-                else
-                {
+                } else {
                         g_string_append_c (result, *iterator);
                 }
         }
@@ -271,11 +258,9 @@ gen_crc(const char *msg)
          int i,j;
  
          poly = 0xEDB88320L;
-         for (i = 0; i < 256; i++)
-         {
+         for (i = 0; i < 256; i++) {
                  crc = i;
-                 for (j = 8; j > 0; j--)
-                 {
+                 for (j = 8; j > 0; j--) {
                          if (crc & 1)
                                  crc = (crc >> 1) ^ poly;
                          else
@@ -298,13 +283,12 @@ gen_md5(gchar *buffer)
         const char tohex[16] = "0123456789abcdef";
  
         md5_get_digest (buffer, strlen(buffer), md5sum);
-  	for (i=0, f = res; i<16;i++)
- 	{
+  	for (i=0, f = res; i<16;i++) {
                 unsigned int c = md5sum[i];
                 *f++ = tohex[c & 0xf];
          }
  	*f++ = 0;
-         return g_strdup((gchar *)res);
+        return g_strdup((gchar *)res);
 }
 
 void
diff --git a/src/org-gnome-evolution-rss.eplug.xml b/src/org-gnome-evolution-rss.eplug.xml
index 5df17f1..65ef02c 100644
--- a/src/org-gnome-evolution-rss.eplug.xml
+++ b/src/org-gnome-evolution-rss.eplug.xml
@@ -46,6 +46,10 @@ HTML can be displayed using the following engines: gtkHTML, Apple's Webkit or Fi
         	<event type="pass" target="folder" id="folder.refresh" handle="org_gnome_cooly_folder_refresh"/>
 	</hook>
 
+	<hook class="org.gnome.evolution.mail.events:1.0">
+                <event id="composer.presendchecks" handle="org_gnome_evolution_presend" target="message"/>
+	</hook>
+
 	<hook class="org.gnome.evolution.mail.format:1.0">
       <group id="EMFormatHTMLDisplay">
         <item flags="inline_disposition" mime_type="x-evolution/evolution-rss-feed"
diff --git a/src/parser.c b/src/parser.c
index 99039d7..807d6e2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -38,6 +38,33 @@ guint rsserror = FALSE;
 gchar *rssstrerror = NULL;
 extern rssfeed *rf;
 
+//
+// decodes url_encoded strings that might appear in a html body
+//
+xmlDoc *
+rss_html_url_decode(const char *html, int len)
+{
+        xmlDoc *src = NULL;
+        xmlDoc *doc = NULL;
+        gchar *url, *tmpurl;
+
+        src = (xmlDoc *)parse_html_sux(html, len);
+
+        if (!src)
+                return NULL;
+
+        doc = src;
+
+        while ((doc = html_find((xmlNode *)doc, "img"))) {
+                if ((url = (gchar *)xmlGetProp(doc, (xmlChar *)"src"))) {
+			tmpurl = camel_url_decode_path(strstr(url, "http:"));
+			xmlSetProp(doc, (xmlChar *)"src", (xmlChar *)tmpurl);
+			g_free(tmpurl);
+		}
+	}
+	return src;
+}
+
 void
 html_set_base(xmlNode *doc, char *base, char *tag, char *prop, char *basehref)
 {
diff --git a/src/parser.h b/src/parser.h
index f604d4b..d7f0904 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -28,6 +28,7 @@ xmlNodePtr layer_find_pos (xmlNodePtr node, char *match, char *submatch);
 char *layer_find_tag (xmlNodePtr node, char *match, char *fail);
 char * layer_find_url (xmlNodePtr node, char *match, char *fail);
 char *layer_find_tag_prop (xmlNodePtr node, char *match, char *search, char *fail);
+gchar *encode_html_entities(gchar *source);
 gchar *decode_entities(gchar *source);
 GList *layer_find_all (xmlNodePtr node, char *match, char *fail);
 xmlDoc *parse_html(char *url, const char *html, int len);
diff --git a/src/rss.c b/src/rss.c
index 53adc53..df2d190 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -1851,6 +1851,30 @@ pfree(EMFormatHTMLPObject *o)
 	browser_fetching = 0;
 }
 
+
+void
+org_gnome_evolution_presend (EPlugin *ep, EMEventTargetComposer *t)
+{
+	gchar *tmsg;
+	xmlChar *buff = NULL;
+	gint size, length;
+	gchar *text;
+
+	/* unfortunately e_msg_composer does not have raw get/set text body
+	 * so it is far easier using gtkhtml_editor_* functions rather than
+	 * procesing CamelMimeMessage or GByteArray
+	 */
+	text = gtkhtml_editor_get_text_html (t->composer, &length);
+
+	xmlDoc *doc = rss_html_url_decode(text, strlen(text));
+	if (doc) {
+		htmlDocDumpMemory(doc, &buff, &size);
+		xmlFree(doc);
+	}
+
+	gtkhtml_editor_set_text_html(t->composer, buff, size);
+}
+
 EMFormat *fom;
 CamelStream *som;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]