[Xfce4-commits] <postler:master> Read filename from content-disposition or content-type

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


Updating branch refs/heads/master
         to 9041c17246c32110025d6a0ca6d6244a9b79e908 (commit)
       from 75c9e2991c6370adc792a7066aa5346b21599da7 (commit)

commit 9041c17246c32110025d6a0ca6d6244a9b79e908
Author: Bernd Prünster <bernd.pruenster at gmail.com>
Date:   Sat Nov 27 01:29:48 2010 +0100

    Read filename from content-disposition or content-type

 postler/postler-content.vala |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 50998e0..d27da24 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -395,13 +395,13 @@ public class Postler.Content : WebKit.WebView {
     }
 
     static void parse_content_type (string? content_type, ref string charset,
-        ref string boundary, ref string mime_type) {
+        ref string boundary, ref string mime_type, ref string filename) {
 
         if (content_type == null)
             return;
 
         string[] parts = content_type.replace (" = ", "=").split_set ("; \t");
-        string filename = null;
+        filename = null;
         for (int i = 0; i < parts.length; i++) {
             string part = parts[i];
             unowned string? next = parts[i + 1];
@@ -414,6 +414,8 @@ public class Postler.Content : WebKit.WebView {
                 charset = part.substring (8, part.length - 8).replace ("\"", "");
             else if (part.has_prefix ("name="))
                 filename = part.substring (5, part.length - 5).replace ("\"", "");
+            else if (part.has_prefix ("filename="))
+                filename = part.substring (9, part.length - 9).replace ("\"", "");
             else if (part.down ().has_prefix ("boundary="))
                 boundary = part.substring (9, part.length - 9).replace ("\"", "");
             else if (part != "" && !part.contains ("="))
@@ -461,8 +463,9 @@ public class Postler.Content : WebKit.WebView {
                 }
 
                 string? boundary = null;
+                string? fname = null;
                 parse_content_type (content_type, ref charset, ref boundary,
-                                    ref mime_type);
+                                    ref mime_type, ref fname);
 
                 /* FIXME view_source_mode requires WebKitGTK+ 1.1.something */
                 set_view_source_mode (true);
@@ -573,7 +576,9 @@ public class Postler.Content : WebKit.WebView {
                 reply = linkify_address (reply, arguments);
 
             string? boundary = null;
-            parse_content_type (content_type, ref charset, ref boundary, ref mime_type);
+            string? fname = null;
+            parse_content_type (content_type, ref charset, ref boundary,
+                                ref mime_type, ref fname);
 
             uint multipart = mime_type.has_prefix ("multipart/") ? 1 : 0;
             if (multipart > 0 && boundary != null)
@@ -637,18 +642,28 @@ public class Postler.Content : WebKit.WebView {
                         if (field == "content-type") {
                             string cset = default_charset;
                             string mtype = "text/plain";
+                            fname = null;
                             parse_content_type (parts[1].strip (), ref cset,
-                                ref inner_boundary, ref mtype);
+                                ref inner_boundary, ref mtype, ref fname);
 
                             if (line.chomp ().has_suffix (";"))
                                 mtype += ";";
                             if (mtype != "text/plain")
                                 plain_text = false;
+                            message_part.filename = fname;
                             message_part.mime_type = mtype;
                         }
                         else if (field == "content-transfer-encoding") {
                             content_encoding = parts[1].strip ();
                         }
+                        else if (field == "content-disposition" ) {
+                            string cset = default_charset;
+                            string mtype = "text/plain";
+                            fname = null;
+                            parse_content_type (parts[1].strip (), ref cset,
+                                ref inner_boundary, ref mtype, ref fname);
+                            message_part.filename = fname;
+                        }
                         continue;
                     }
                     else if (multipart == 1)



More information about the Xfce4-commits mailing list