[Xfce4-commits] <postler:master> Separate signature/ quote rendering from parsing

Christian Dywan noreply at xfce.org
Sat Feb 12 16:44:04 CET 2011


Updating branch refs/heads/master
         to 9d8836226302b78ac71dd26a525d9cca43e016b9 (commit)
       from 8637d01828b14d6a59e20df967f42456feaf61d7 (commit)

commit 9d8836226302b78ac71dd26a525d9cca43e016b9
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Feb 12 16:37:40 2011 +0100

    Separate signature/ quote rendering from parsing
    
    If a message is encoded, line endings may not match real
    line endings in the message source.

 postler/postler-content.vala |  102 ++++++++++++++++++++++-------------------
 1 files changed, 55 insertions(+), 47 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index fea6419..e14025a 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -808,8 +808,6 @@ public class Postler.Content : WebKit.WebView {
                 message_parts.append (message_part);
             }
 
-            int in_quote = 0;
-            bool in_signature = false;
             string inner_boundary = "";
             string line;
             string previous_line = "";
@@ -893,50 +891,6 @@ public class Postler.Content : WebKit.WebView {
                         line = GLib.convert (line, -1, "UTF-8", cset, null);
                 }
                 catch (GLib.ConvertError error) { }
-                if (message_part.plain_text) {
-                    /* Looks like a signature */
-                    if (in_signature && line[0] == '\0') {
-                        message_part.body.append ("</span>");
-                        in_signature = false;
-                    } else if (!in_signature && line[0] == '-' && line[1] == '-'
-                            && line[2] == ' ' && line[3] == '\0') {
-                        message_part.body.append ("<span class=\"signature\">");
-                        in_signature = true;
-                        line = "";
-                    }
-                    /* Looks like quoting */
-                    if (in_quote > 0 || line.has_prefix ("> ") || line.has_prefix (">>")) {
-                        /* Determine level of nesting */
-                        int quote_mark = 0;
-                        int position = 0;
-                        do {
-                            if (line[position] == '>')
-                                quote_mark++;
-                            else if (line[position] != ' ')
-                                break;
-                            position++;
-                        } while (true);
-
-                        if (quote_mark < in_quote)
-                            message_part.body.append ("</blockquote>");
-                        else if (quote_mark > in_quote)
-                            message_part.body.append ("<blockquote>");
-                        in_quote = quote_mark;
-                    }
-
-                    if (in_quote > 0 && line[0] == '>' && line[1] == ' ') {
-                        line = line.substring (2);
-                        int position = 0;
-                        do {
-                            if (line[position] != '>' && line[position] != ' ')
-                                break;
-                            position++;
-                        } while (true);
-                        line = line.substring (position);
-                    }
-                    else if (in_quote > 0 && line[0] == '>' && line[1] == '\0')
-                        line = line.substring (1);
-                }
                 if (content_encoding == "base64") {
                     if (message_part.plain_text)
                         line = line.replace ("\n", "<br>");
@@ -1001,6 +955,60 @@ public class Postler.Content : WebKit.WebView {
         return false;
     }
 
+    string render_plain_text (string body) {
+        bool in_signature = false;
+        int in_quote = 0;
+
+        var new_body = new StringBuilder ("<span class=\"plain_text\">");
+        foreach (string line in body.split ("<br>")) {
+            /* Looks like a signature */
+            if (in_signature && line[0] == '\0') {
+                new_body.append ("</span>");
+                in_signature = false;
+            } else if (!in_signature && line[0] == '-' && line[1] == '-'
+                    && line[2] == ' ' && line[3] == '\0') {
+                new_body.append ("<span class=\"signature\">");
+                in_signature = true;
+                line = "";
+            }
+            /* Looks like quoting */
+            if (in_quote > 0 || line.has_prefix ("> ") || line.has_prefix (">>")) {
+                /* Determine level of nesting */
+                int quote_mark = 0;
+                int position = 0;
+                do {
+                    if (line[position] == '>')
+                        quote_mark++;
+                    else if (line[position] != ' ')
+                        break;
+                    position++;
+                } while (true);
+
+                if (quote_mark < in_quote)
+                    new_body.append ("</blockquote>");
+                else if (quote_mark > in_quote)
+                    new_body.append ("<blockquote>");
+                in_quote = quote_mark;
+            }
+
+            if (in_quote > 0 && line[0] == '>' && line[1] == ' ') {
+                line = line.substring (2);
+                int position = 0;
+                do {
+                    if (line[position] != '>' && line[position] != ' ')
+                        break;
+                    position++;
+                } while (true);
+                line = line.substring (position);
+            }
+            else if (in_quote > 0 && line[0] == '>' && line[1] == '\0')
+                line = line.substring (1);
+            new_body.append (line + "<br>");
+        }
+        new_body.append ("</span>");
+        return new_body.str;
+    }
+
     public void display_part (MessagePart message_part) {
         if (current_part != message_part) {
             current_part = message_part;
@@ -1011,7 +1019,7 @@ public class Postler.Content : WebKit.WebView {
         if (message_part == html_part)
             body_chunk = message_part.body.str;
         else if (message_part == text_part) {
-            body_chunk = "<span class=\"plain_text\">" + message_part.body.str + "</span>";
+            body_chunk = render_plain_text (message_part.body.str);
         }
         else {
             body_chunk = """



More information about the Xfce4-commits mailing list