[Xfce4-commits] <postler:master> Retain and expose message body parts as get_parts

Christian Dywan noreply at xfce.org
Fri Jun 4 23:28:03 CEST 2010


Updating branch refs/heads/master
         to c266328fcee3b82380f82d7a8eebd56438589625 (commit)
       from d2aa4ba996f1cfe962ce642ba7f8d177a90b13eb (commit)

commit c266328fcee3b82380f82d7a8eebd56438589625
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Jun 4 22:35:49 2010 +0200

    Retain and expose message body parts as get_parts

 postler/postler-content.vala |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index c70dac2..df8d780 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -17,6 +17,10 @@ struct Postler.EmoticonMapping {
 }
 
 public class Postler.Content : WebKit.WebView {
+    GLib.StringBuilder[] body = {};
+    string[] mime_types = {};
+    int body_parts = -1;
+
     public string default_charset { get; set; default = "ISO-8859-1"; }
 
     public string? last_location { get; set; }
@@ -24,6 +28,11 @@ public class Postler.Content : WebKit.WebView {
     public string? reply_to { get; set; }
     public string? reply_to_all { get; set; }
 
+    public string[] get_parts () {
+        return mime_types;
+    }
+    public int n_parts { get { return body_parts + 1; } }
+
     public bool view_source { get; set; }
 
     const string style_sheet = """
@@ -177,7 +186,12 @@ public class Postler.Content : WebKit.WebView {
     }
 
     public bool display (string location) {
+        last_location = location;
         subject = _("(No subject)");
+        body = {};
+        mime_types = {};
+        body_parts = -1;
+
         var contents = File.new_for_path (location);
         try {
             var stream = new DataInputStream (contents.read (null));
@@ -347,13 +361,10 @@ public class Postler.Content : WebKit.WebView {
             }
 
             /* Message body starts here */
-            GLib.StringBuilder[] body = {};
-            string[] mime_types = {};
-            int slice = -1;
             if (multipart == 0) {
                 body += new GLib.StringBuilder ();
                 mime_types += mime_type;
-                slice++;
+                body_parts++;
             }
             while ((line = stream.read_line (null, null)) != null) {
                 if (multipart > 0) {
@@ -362,7 +373,7 @@ public class Postler.Content : WebKit.WebView {
                             body += new GLib.StringBuilder ();
                             mime_types += "text/plain";
                             plain_text = true;
-                            slice++;
+                            body_parts++;
                             multipart = 2;
                             continue;
                         }
@@ -374,8 +385,8 @@ public class Postler.Content : WebKit.WebView {
                             if (field == "content-type") {
                                 string ctype = parts[1].strip ();
                                 parts = ctype.split_set ("; ");
-                                mime_types[slice] = parts[0].strip ().down ();
-                                if (mime_types[slice] != "text/plain")
+                                mime_types[body_parts] = parts[0].strip ().down ();
+                                if (mime_types[body_parts] != "text/plain")
                                     plain_text = false;
                                 continue;
                             }
@@ -405,15 +416,15 @@ public class Postler.Content : WebKit.WebView {
                 /* Render signature gray, beginning with "--=20" */
                 /* Looks like quoting */
                 if (line.has_prefix (">"))
-                    body[slice].append ("<span style=\"color: GrayText\">");
+                    body[body_parts].append ("<span style=\"color: GrayText\">");
                 string appendage;
                 if (plain_text && content_encoding != "base64")
                     appendage = line + "\n";
                 else
                     appendage = line;
-                body[slice].append (appendage);
+                body[body_parts].append (appendage);
                 if (line.has_prefix (">"))
-                    body[slice].append ("</span>");
+                    body[body_parts].append ("</span>");
                 }
 
             string body_chunk;
@@ -476,7 +487,6 @@ public class Postler.Content : WebKit.WebView {
                         plain_text ? "font-family: Monospace;" : "",
                         body_chunk),
                 mime_type, "UTF-8", "about:blank");
-            last_location = location;
         } catch (GLib.Error contents_error) {
             load_string ("""
                 <title>%s</title>
@@ -491,6 +501,7 @@ public class Postler.Content : WebKit.WebView {
             GLib.critical (_("Failed to read message \"%s\": %s"),
                 contents.get_path (), contents_error.message);
         }
+        notify_property ("n-parts");
         return false;
     }
 



More information about the Xfce4-commits mailing list