[Xfce4-commits] <postler:master> Decode folder names from modified UTF-7
Christian Dywan
noreply at xfce.org
Fri Jan 7 09:44:02 CET 2011
Updating branch refs/heads/master
to bcde54ea236a1900bdf38273665a501e46962ce1 (commit)
from 0c28ec12edf145e6a6fac999993ed01ac16df78c (commit)
commit bcde54ea236a1900bdf38273665a501e46962ce1
Author: Christian Dywan <christian at twotoasts.de>
Date: Thu Jan 6 20:09:49 2011 +0100
Decode folder names from modified UTF-7
postler/postler-folders.vala | 17 ++++++++++++++++-
tests/parsing.vala | 23 +++++++++++++++++++++--
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index d0551be..3068777 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -119,6 +119,21 @@ public class Postler.Folders : Gtk.TreeView {
return false;
}
+ public static string decode_foldername (string name) {
+ /* Modified UTF-7 according to RFC 2060 */
+ string decoded = name.replace ("&", "+").replace (",", "/");
+ try {
+ return GLib.convert (decoded, -1, "UTF-8", "UTF-7", null);
+ }
+ catch (Error error) {
+ if (error is ConvertError.ILLEGAL_SEQUENCE)
+ GLib.warning ("Incomplete folder name conversion: %s", name);
+ else
+ GLib.warning ("Failed to convert folder name: %s", error.message);
+ }
+ return name;
+ }
+
public bool populate_accounts (GLib.List<AccountInfo> infos, int count=-1) {
int num_accounts = 0;
if (count > -1)
@@ -275,7 +290,7 @@ public class Postler.Folders : Gtk.TreeView {
store.insert_with_values (out folder_iter,
folder.localized != null ? account_iter : parent_iter, -1,
Columns.ICON, folder.stock_id ?? Gtk.STOCK_DIRECTORY,
- Columns.NAME, folder.label ?? folder_name,
+ Columns.NAME, folder.label ?? decode_foldername (folder_name),
Columns.ELLIPSIZE, Pango.EllipsizeMode.MIDDLE,
Columns.LOCATION, account_info.path + "/" + name,
Columns.INFO, account_info,
diff --git a/tests/parsing.vala b/tests/parsing.vala
index c90c905..61f4b1d 100644
--- a/tests/parsing.vala
+++ b/tests/parsing.vala
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2011 Christian Dywan <christian at twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,25 @@ void assert_string_equal (string a, string b) {
struct TestCase {
public string data;
- public string expected;
+ public string? expected;
+}
+
+const TestCase[] folders = {
+ { "Sent Mail", null },
+ { "Messages envoy&AOk-s", "Messages envoyés" },
+ { "&ZeVnLIqe-", "日本語" },
+ { "&U,BTFw-", "台北" },
+ { "&BkUGMwZIBi8GJwYq-", "مسودات" }
+};
+
+void parsing_filename_folder () {
+ foreach (var foldername in folders) {
+ string decoded = Postler.Folders.decode_foldername (foldername.data);
+ string expected = foldername.expected;
+ if (expected == null)
+ expected = foldername.data;
+ assert_string_equal (decoded, expected);
+ }
}
const TestCase[] filenames = {
@@ -123,6 +141,7 @@ void parsing_headers_encoded () {
void main (string[] args) {
Test.init (ref args);
+ Test.add_func ("/parsing/filename/folder", parsing_filename_folder);
Test.add_func ("/parsing/filename/flags", parsing_filename_flags);
Test.add_func ("/parsing/headers/address", parsing_headers_address);
Test.add_func ("/parsing/headers/linkify", parsing_headers_linkify);
More information about the Xfce4-commits
mailing list