[geary/mjog/771-html-not-wrapped-on-send: 2/3] Geary.RFC822.Utils: Ensure best encoding/charset not missing data
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/771-html-not-wrapped-on-send: 2/3] Geary.RFC822.Utils: Ensure best encoding/charset not missing data
- Date: Sun, 29 Mar 2020 05:32:54 +0000 (UTC)
commit f3c02c780080e76221db0ad29ad91a20d4ea15c3
Author: Michael Gratton <mike vee net>
Date: Sun Mar 29 16:24:58 2020 +1100
Geary.RFC822.Utils: Ensure best encoding/charset not missing data
By not closing/flushing the buffer, ::get_best_charset and
::get_best_encoding were not including the last line of the buffer, and
missing single very long lines when guessing the encoding.
Fixes #771
src/engine/rfc822/rfc822-utils.vala | 10 ++++------
test/engine/rfc822-utils-test.vala | 31 +++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-utils.vala b/src/engine/rfc822/rfc822-utils.vala
index d9278f64..f05c50a2 100644
--- a/src/engine/rfc822/rfc822-utils.vala
+++ b/src/engine/rfc822/rfc822-utils.vala
@@ -263,9 +263,7 @@ public string to_preview_text(string? text, TextFormat format) {
public async string get_best_charset(GMime.Stream in_stream,
GLib.Cancellable? cancellable)
throws GLib.Error {
- GMime.FilterBest filter = new GMime.FilterBest(
- GMime.FilterBestFlags.CHARSET
- );
+ GMime.FilterBest filter = new GMime.FilterBest(CHARSET);
GMime.StreamFilter out_stream = new GMime.StreamFilter(
new GMime.StreamNull()
);
@@ -274,6 +272,7 @@ public async string get_best_charset(GMime.Stream in_stream,
yield Nonblocking.Concurrent.global.schedule_async(() => {
in_stream.write_to_stream(out_stream);
in_stream.reset();
+ out_stream.close();
},
cancellable
);
@@ -290,9 +289,7 @@ public async GMime.ContentEncoding get_best_encoding(GMime.Stream in_stream,
GMime.EncodingConstraint constraint,
GLib.Cancellable? cancellable)
throws GLib.Error {
- GMime.FilterBest filter = new GMime.FilterBest(
- GMime.FilterBestFlags.ENCODING
- );
+ GMime.FilterBest filter = new GMime.FilterBest(ENCODING);
GMime.StreamFilter out_stream = new GMime.StreamFilter(
new GMime.StreamNull()
);
@@ -301,6 +298,7 @@ public async GMime.ContentEncoding get_best_encoding(GMime.Stream in_stream,
yield Nonblocking.Concurrent.global.schedule_async(() => {
in_stream.write_to_stream(out_stream);
in_stream.reset();
+ out_stream.close();
},
cancellable
);
diff --git a/test/engine/rfc822-utils-test.vala b/test/engine/rfc822-utils-test.vala
index d478cb48..d150b71f 100644
--- a/test/engine/rfc822-utils-test.vala
+++ b/test/engine/rfc822-utils-test.vala
@@ -10,6 +10,9 @@ class Geary.RFC822.Utils.Test : TestCase {
public Test() {
base("Geary.RFC822.Utils.Test");
add_test("to_preview_text", to_preview_text);
+ add_test("best_encoding_default", best_encoding_default);
+ add_test("best_encoding_long_line", best_encoding_long_line);
+ add_test("best_encoding_binary", best_encoding_binary);
}
public void to_preview_text() throws Error {
@@ -21,6 +24,34 @@ class Geary.RFC822.Utils.Test : TestCase {
HTML_BODY_EXPECTED);
}
+ public void best_encoding_default() throws GLib.Error {
+ string test = "abc";
+ var stream = new GMime.StreamMem.with_buffer(test.data);
+ get_best_encoding.begin(stream, 7BIT, null, async_complete_full);
+ var encoding = get_best_encoding.end(async_result());
+ assert_true(encoding == DEFAULT);
+ }
+
+ public void best_encoding_long_line() throws GLib.Error {
+ GLib.StringBuilder buf = new GLib.StringBuilder();
+ for (int i = 0; i < 2000; i++) {
+ buf.append("long ");
+ }
+ var stream = new GMime.StreamMem.with_buffer(buf.str.data);
+ get_best_encoding.begin(stream, 7BIT, null, async_complete_full);
+ var encoding = get_best_encoding.end(async_result());
+ assert_true(encoding == QUOTEDPRINTABLE);
+ }
+
+ public void best_encoding_binary() throws GLib.Error {
+ uint8 test[] = { 0x20, 0x00, 0x20 };
+ var stream = new GMime.StreamMem.with_buffer(test);
+ get_best_encoding.begin(stream, 7BIT, null, async_complete_full);
+ var encoding = get_best_encoding.end(async_result());
+ assert_true(encoding == BASE64);
+ }
+
+
public static string PLAIN_BODY_ENCODED = "-----BEGIN PGP SIGNED MESSAGE-----\nHash:
SHA512\n\n=============================================================================\nFreeBSD-EN-16:11.vmbus
Errata Notice\n
The FreeBSD Project\n\nTopic: Avoid using spin locks for channel message locks\n\nCategory:
core\nModule: vmbus\nAnnounced: 2016-08-12\nCredits: Microsoft OSTC\nAffects:
FreeBSD 10.3\nCorrected: 2016-06-15 09:52:01 UTC (stable/10, 10.3-STABLE)\n 2016-08-12
04:01:16 UTC (releng/10.3, 10.3-RELEASE-p7)\n\nFor general information regarding FreeBSD Errata Notices and
Security\nAdvisories, including descriptions of the fields above, security\nbranches, and the following
sections, please visit\n<URL:https://security.FreeBSD.org/>.\n";
public static string PLAIN_BODY_EXPECTED = "FreeBSD-EN-16:11.vmbus Errata Notice The FreeBSD Project
Topic: Avoid using spin locks for channel message locks Category: core Module: vmbus Announced: 2016-08-12
Credits: Microsoft OSTC Affects: FreeBSD 10.3 Corrected: 2016-06-15 09:52:01 UTC (stable/10, 10.3-STABLE)
2016-08-12 04:01:16 UTC (releng/10.3, 10.3-RELEASE-p7) For general information regarding FreeBSD Errata
Notices and Security Advisories, including descriptions of the fields above, security branches, and the
following sections, please visit <URL:https://security.FreeBSD.org/>.";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]