[Xfce4-commits] <postler:master> Offer opening of non-text attachments

Christian Dywan noreply at xfce.org
Sat Nov 27 04:34:06 CET 2010


Updating branch refs/heads/master
         to a88775195787209ff6187c1b32ae92d0a115161e (commit)
       from d45152a5a372c11f691d4edb137b3e5975eb37bb (commit)

commit a88775195787209ff6187c1b32ae92d0a115161e
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Nov 27 02:02:40 2010 +0100

    Offer opening of non-text attachments

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

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 7f6277b..41c7a17 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -685,7 +685,8 @@ public class Postler.Content : WebKit.WebView {
 
                 if (content_encoding == "quoted-printable")
                     line = quoted_printable_decode (line);
-                else if (content_encoding == "base64")
+                else if (content_encoding == "base64"
+                      && mime_type_is_text (message_part.mime_type))
                     line = line != "" ? (string)GLib.Base64.decode (line) : "";
                 try {
                     if (charset != null)
@@ -774,13 +775,24 @@ public class Postler.Content : WebKit.WebView {
         string body_chunk;
         string mime_type = message_part.mime_type;
         bool plain_text = false;
-        if (mime_type == "text/plain") {
+        if (mime_type == "text/html")
+            body_chunk = message_part.body.str;
+        else if (mime_type_is_text (mime_type)) {
             mime_type = "text/html";
             plain_text = true;
             body_chunk = "<span class=\"plain_text\">" + message_part.body.str + "</span>";
         }
-        else
-            body_chunk = message_part.body.str;
+        else {
+            mime_type = "text/html";
+            body_chunk = """
+                <b>%s</b>
+                <p><a href="message-part:open:%d">%s</a>
+                """.
+                printf (
+                message_part.filename ?? message_part.mime_type,
+                message_parts.position (message_parts.find (message_part)),
+                _("Open file"));
+        }
 
         try {
             /* Linkify */
@@ -870,6 +882,36 @@ public class Postler.Content : WebKit.WebView {
             return false;
 
         decision.ignore ();
+        if (uri.has_prefix ("message-part:")) {
+            int index;
+            if (uri.has_prefix ("message-part:open:"))
+                index = uri.substring (18, -1).to_int ();
+            else {
+                /* FIXME: Show error dialogue */
+                GLib.message (_("Erroneous attachment: %s"), uri);
+                return false;
+            }
+            var message_part = message_parts.nth_data (index);
+            string filename;
+            if (uri.has_prefix ("message-part:open:")) {
+                filename = "/tmp/%sXXXXXX".printf (message_part.filename ?? "");
+                if (FileUtils.mkstemp (filename) == -1) {
+                    /* FIXME: Show error dialogue */
+                    GLib.message (_("Failed to create temporary file: %s"), filename);
+                    return false;
+                }
+            } else
+                assert_not_reached ();
+            try {
+                FileUtils.set_data (filename, GLib.Base64.decode (message_part.body.str));
+                uri = Filename.to_uri (filename, null);
+            } catch (GLib.Error error) {
+                /* FIXME: Show error dialogue */
+                GLib.message (_("Failed to write file: %s"), filename);
+                return false;
+            }
+        }
+
         return Postler.App.show_uri (get_screen (), uri);
     }
 



More information about the Xfce4-commits mailing list