Updating branch refs/heads/master
         to 734c3ae2262499d2cfc44ec6be9b77233005326b (commit)
       from 31b22e071e18d11f05070463ef78b14bd509fec8 (commit)

commit 734c3ae2262499d2cfc44ec6be9b77233005326b
Author: Christian Dywan <christ...@twotoasts.de>
Date:   Mon May 31 19:29:07 2010 +0200

    Split MIME type and content type more carefully
    
    We also want to clearly show an error message if the body of
    the message can't be displayed.

 postler/postler-content.vala |   31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index ebdb40a..f36560c 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -247,10 +247,23 @@ public class Postler.Content : WebKit.WebView {
                 reply = linkify_address (reply, arguments);
 
             if (content_type != null) {
-                parts = content_type.split ("; charset=");
-                if (parts != null && parts[0] != null && parts[1] != null) {
-                    mime_type = parts[0];
-                    charset = parts[1].replace ("\"", " ").strip ();
+                parts = content_type.split_set ("; ");
+                string filename = null;
+                foreach (var part in parts) {
+                    if (part.has_prefix ("charset="))
+                        charset = part.substring (8, part.length - 8);
+                    else if (part.has_prefix ("name="))
+                        filename = part.substring (5, part.length - 5);
+                    else if (part != "" && !part.contains ("="))
+                        mime_type = part.down ();
+                }
+
+                if (mime_type == "application/octet-stream" && filename != 
null) {
+                    filename = filename.replace ("\"", " ").strip ();
+                    uchar[] data = {};
+                    bool uncertain;
+                    mime_type = g_content_type_guess (filename,
+                        data, out uncertain);
                 }
             }
 
@@ -264,6 +277,16 @@ public class Postler.Content : WebKit.WebView {
             /* Message body starts here */
             body = new GLib.StringBuilder ();
             while ((line = stream.read_line (null, null)) != null) {
+                if (!mime_type.has_prefix ("text/")) {
+                    body.append ("<h1>%s</h1><p>%s".printf (
+                        _("Error"),
+                        _("This message of type \"%s\" can't be displayed.").
+                            printf (mime_type)
+                        ));
+                    mime_type = "text/html";
+                    break;
+                }
+
                 if (content_encoding == "quoted-printable")
                     line = quoted_printable_decode (line);
                 else if (content_encoding == "base64")
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to