[Xfce4-commits] <postler:master> Propagate message charset and add part charset
Christian Dywan
noreply at xfce.org
Tue Jan 25 20:02:05 CET 2011
Updating branch refs/heads/master
to cfde7fff91834e91a5f395d4387fe4a9d1a6c0f3 (commit)
from 5f9459c73365059002495316b5bbdc74f9ca9777 (commit)
commit cfde7fff91834e91a5f395d4387fe4a9d1a6c0f3
Author: Christian Dywan <christian at twotoasts.de>
Date: Tue Jan 25 20:01:03 2011 +0100
Propagate message charset and add part charset
postler/postler-content.vala | 33 +++++++++++++--------------------
1 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index cb34f95..dfff72c 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -12,6 +12,7 @@
public class Postler.MessagePart {
public StringBuilder? body;
public string? mime_type;
+ public string? charset;
public bool plain_text;
public string? filename;
public int partnum { get; set; default = 0; }
@@ -75,6 +76,7 @@ struct Postler.EmoticonMapping {
public class Postler.Content : WebKit.WebView {
AccountInfo? selected_account;
+ string charset;
string content_encoding;
string date;
string carbon_copy;
@@ -512,7 +514,6 @@ 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 filename) {
-
if (content_type == null)
return;
@@ -608,6 +609,7 @@ public class Postler.Content : WebKit.WebView {
void parse_message (string location) throws GLib.FileError {
last_location = location;
+ charset = null;
subject = _("(No subject)");
message_parts = new List<MessagePart> ();
@@ -616,7 +618,6 @@ public class Postler.Content : WebKit.WebView {
var stream = new DataInputStream (contents.read (null));
string line;
string content_type = null;
- string charset = null;
string[] parts;
content_encoding = "";
@@ -735,7 +736,7 @@ public class Postler.Content : WebKit.WebView {
if (list_unsubscribe != "")
list_unsubscribe = linkify_address (list_unsubscribe, null);
- parse_body (stream, content_type, ref charset);
+ parse_body (stream, content_type);
} catch (GLib.Error contents_error) {
throw new GLib.FileError.FAILED (_("Failed to read message: %s").
printf (contents_error.message));
@@ -744,8 +745,7 @@ public class Postler.Content : WebKit.WebView {
notify_property ("message-parts");
}
- void parse_body (DataInputStream stream, string? content_type,
- ref string charset) throws GLib.Error {
+ void parse_body (DataInputStream stream, string? content_type) throws GLib.Error {
try {
string? boundary = null;
@@ -807,32 +807,24 @@ public class Postler.Content : WebKit.WebView {
line = previous_line + " " + line.chug ();
previous_line = line;
- /* Content-Type can span over multiple lines */
- string[] parts;
- if (message_part.mime_type.has_suffix (";"))
- parts = { "content-type",
- message_part.mime_type + line };
- else
- parts = line.split (":", 2);
-
+ string[] parts = line.split (":", 2);
string field = ascii_strdown (parts[0] ?? "");
if (field == "content-type") {
- string cset = default_charset;
+ string ctype = charset;
string mtype = "text/plain";
fname = null;
- parse_content_type (parts[1].strip (), ref cset,
+ parse_content_type (parts[1].strip (), ref ctype,
ref inner_boundary, ref mtype, ref fname);
message_part.filename = fname;
message_part.mime_type = mtype;
+ message_part.charset = ctype;
message_part.plain_text = mtype == "text/plain";
- if (line.chomp ().has_suffix (";"))
- mtype += ";";
}
else if (field == "content-transfer-encoding") {
content_encoding = parts[1].strip ();
}
else if (field == "content-disposition" ) {
- string cset = default_charset;
+ string cset = charset;
string mtype = "text/plain";
fname = null;
parse_content_type (parts[1].strip (), ref cset,
@@ -851,8 +843,9 @@ public class Postler.Content : WebKit.WebView {
&& mime_type_is_text (message_part.mime_type))
line = line != "" ? (string)GLib.Base64.decode (line) : "";
try {
- if (charset != null && charset != "UTF-8")
- line = GLib.convert (line, -1, "UTF-8", charset, null);
+ string cset = message_part.charset ?? charset;
+ if (cset != "UTF-8")
+ line = GLib.convert (line, -1, "UTF-8", cset, null);
}
catch (GLib.ConvertError error) { }
if (message_part.plain_text) {
More information about the Xfce4-commits
mailing list