[geary/wip/714317-hide-html-in-preview: 3/4] Don't generate a preview from non-text parts, e.g. multipart/signed.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/714317-hide-html-in-preview: 3/4] Don't generate a preview from non-text parts, e.g. multipart/signed.
- Date: Mon, 19 Dec 2016 07:48:32 +0000 (UTC)
commit 7d111d907f04772ad4c8a6e4acc21aa52221983b
Author: Michael James Gratton <mike vee net>
Date: Mon Dec 19 02:19:25 2016 +1100
Don't generate a preview from non-text parts, e.g. multipart/signed.
Bug 714317.
* src/engine/rfc822/rfc822-message-data.vala (PreviewText::with_header):
Check to see if the part is text/plain or text/html before generating a
preview for it.
src/engine/rfc822/rfc822-message-data.vala | 42 ++++++++++++++++------------
1 files changed, 24 insertions(+), 18 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message-data.vala b/src/engine/rfc822/rfc822-message-data.vala
index 2f232b0..7459c02 100644
--- a/src/engine/rfc822/rfc822-message-data.vala
+++ b/src/engine/rfc822/rfc822-message-data.vala
@@ -353,12 +353,13 @@ public class Geary.RFC822.PreviewText : Geary.RFC822.Text {
public PreviewText(Memory.Buffer _buffer) {
base (_buffer);
}
-
+
public PreviewText.with_header(Memory.Buffer preview, Memory.Buffer preview_header) {
string? charset = null;
string? encoding = null;
+ bool is_plain = false;
bool is_html = false;
-
+
// Parse the header.
GMime.Stream header_stream = Utils.create_stream_mem(preview_header);
GMime.Parser parser = new GMime.Parser.with_stream(header_stream);
@@ -367,31 +368,36 @@ public class Geary.RFC822.PreviewText : Geary.RFC822.Text {
Mime.ContentType? content_type = null;
if (part.get_content_type() != null) {
content_type = new Mime.ContentType.from_gmime(part.get_content_type());
+ is_plain = content_type.is_type("text", "plain");
is_html = content_type.is_type("text", "html");
charset = content_type.params.get_value("charset");
}
-
+
encoding = part.get_header("Content-Transfer-Encoding");
}
- // Parse the preview
- GMime.StreamMem input_stream = Utils.create_stream_mem(preview);
- ByteArray output = new ByteArray();
- GMime.StreamMem output_stream = new GMime.StreamMem.with_byte_array(output);
- output_stream.set_owner(false);
-
- // Convert the encoding and character set.
- GMime.StreamFilter filter = new GMime.StreamFilter(output_stream);
- if (encoding != null)
- filter.add(new GMime.FilterBasic(GMime.content_encoding_from_string(encoding), false));
+ string preview_text = "";
+ if (is_plain || is_html) {
+ // Parse the preview
+ GMime.StreamMem input_stream = Utils.create_stream_mem(preview);
+ ByteArray output = new ByteArray();
+ GMime.StreamMem output_stream = new GMime.StreamMem.with_byte_array(output);
+ output_stream.set_owner(false);
+
+ // Convert the encoding and character set.
+ GMime.StreamFilter filter = new GMime.StreamFilter(output_stream);
+ if (encoding != null)
+ filter.add(new GMime.FilterBasic(GMime.content_encoding_from_string(encoding), false));
- filter.add(Geary.RFC822.Utils.create_utf8_filter_charset(charset));
+ filter.add(Geary.RFC822.Utils.create_utf8_filter_charset(charset));
- input_stream.write_to_stream(filter);
- uint8[] data = output.data;
- data += (uint8) '\0';
+ input_stream.write_to_stream(filter);
+ uint8[] data = output.data;
+ data += (uint8) '\0';
+
+ preview_text = Geary.RFC822.Utils.to_preview_text((string) data, is_html ? TextFormat.HTML :
TextFormat.PLAIN);
+ }
- string preview_text = Geary.RFC822.Utils.to_preview_text((string) data, is_html ? TextFormat.HTML :
TextFormat.PLAIN);
base(new Geary.Memory.StringBuffer(preview_text));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]