[Xfce4-commits] <postler:master> Lowercase header names and iterate flags as ASCII

Christian Dywan noreply at xfce.org
Tue Jun 8 03:06:02 CEST 2010


Updating branch refs/heads/master
         to b6f23fb36d6fa7ddcabbf015ccd2b9f204f32cee (commit)
       from 69b9ed389b57d15c22daa262af745b29c956398d (commit)

commit b6f23fb36d6fa7ddcabbf015ccd2b9f204f32cee
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Jun 7 22:41:21 2010 +0200

    Lowercase header names and iterate flags as ASCII

 postler/postler-content.vala  |   12 ++++++------
 postler/postler-messages.vala |   19 ++++++++++---------
 postler/postler.vapi          |    2 ++
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 378c7c5..0517283 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -242,7 +242,7 @@ public class Postler.Content : WebKit.WebView {
                 while ((line = stream.read_line (null, null)) != null) {
                     parts = line.split (":", 2);
                     if (parts != null && parts[0] != null) {
-                        string field = parts[0].down ();
+                        string field = ascii_strdown (parts[0]);
                         if (field == "content-type")
                             content_type = parts[1].strip ();
                         else if (field == "subject")
@@ -257,7 +257,7 @@ public class Postler.Content : WebKit.WebView {
                         if (part.has_prefix ("charset="))
                             charset = part.substring (8, part.length - 8);
                         else if (part != "" && !part.contains ("="))
-                            mime_type = part.down ();
+                            mime_type = ascii_strdown (part);
                     }
                 }
                 if (charset == null)
@@ -297,7 +297,7 @@ public class Postler.Content : WebKit.WebView {
                 if (parts == null || parts[0] == null)
                     continue;
 
-                string field = parts[0].down ();
+                string field = ascii_strdown (parts[0]);
                 if (field == "content-type")
                     content_type = parts[1].strip ();
                 else if (field == "content-transfer-encoding")
@@ -361,7 +361,7 @@ public class Postler.Content : WebKit.WebView {
                     else if (part.has_prefix ("boundary="))
                         boundary = part.substring (9, part.length - 9);
                     else if (part != "" && !part.contains ("="))
-                        mime_type = part.down ();
+                        mime_type = ascii_strdown (part);
                 }
 
                 if (mime_type == "application/octet-stream" && filename != null) {
@@ -413,11 +413,11 @@ public class Postler.Content : WebKit.WebView {
                     else if (multipart == 2) {
                         parts = line.split (":", 2);
                         if (parts[0] != null) {
-                            string field = parts[0].down ();
+                            string field = ascii_strdown (parts[0]);
                             if (field == "content-type") {
                                 string ctype = parts[1].strip ();
                                 parts = ctype.split_set ("; ");
-                                mime_types[body_parts] = parts[0].strip ().down ();
+                                mime_types[body_parts] = ascii_strdown (parts[0].strip ());
                                 if (mime_types[body_parts] != "text/plain")
                                     plain_text = false;
                                 continue;
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index d8b050f..5a97655 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -321,12 +321,13 @@ public class Postler.Messages : Gtk.TreeView {
 
     static string parse_flags (string name, out string flagged, out int weight) {
         /* format "unique:2,DFPRST", ordered alphabetically */
-        int flag = 0;
-        while (name[flag] != ':' && name[flag] != '\0')
-            flag++;
-        string status = Gtk.STOCK_NEW;
-        while (name[flag++] != '\0') {
-            switch (name[flag]) {
+        unowned string status = Gtk.STOCK_NEW;
+        unowned string flagstart = name.chr (-1, ':');
+        if (flagstart == null)
+            return status;
+
+        foreach (var character in name.to_utf8 ()) {
+            switch (character) {
             case 'D':
                 status = STOCK_EMBLEM_DRAFT;
                 break;
@@ -411,7 +412,7 @@ public class Postler.Messages : Gtk.TreeView {
                 bool folder_new = folder_dir.get_path ().has_suffix ("new");
                 while ((info = folder_enumerator.next_file (null)) != null) {
                     Gtk.TreeIter account_iter;
-                    string name = info.get_name ();
+                    unowned string name = info.get_name ();
                     if (name[0] == '.')
                         continue;
 
@@ -440,9 +441,9 @@ public class Postler.Messages : Gtk.TreeView {
                             string[] parts = line.split (":", 2);
                             if (parts == null || parts[0] == null)
                                 continue;
-                            string field = parts[0].down ();
+                            string field = ascii_strdown (parts[0]);
                             if (filters[0] != null && parts[1] != null) {
-                                string lowercased = parts[1].down ();
+                                string lowercased = ascii_strdown (parts[1]);
                                 if (headers[0] == field
                                  && !(filters[0] in lowercased)) {
                                     skip = true;
diff --git a/postler/postler.vapi b/postler/postler.vapi
index 54d9478..0a22602 100644
--- a/postler/postler.vapi
+++ b/postler/postler.vapi
@@ -11,6 +11,8 @@
 
 [CCode (cprefix = "GLib", lower_case_cprefix = "g_")]
 namespace GLib {
+    [CCode (cname = "g_ascii_strdown", cheader_filename = "glib.h")]
+    public static string ascii_strdown (string str, ssize_t len = -1);
     [CCode (cname = "g_base64_encode", cheader_filename = "glib.h")]
         public static string base64_encode (string data, size_t length);
     }



More information about the Xfce4-commits mailing list