Geary.RFC822.Message: Always re-determine the encoding for body parts

When attaching body parts to a message from a composed email, don't
re-use the transfer encoding used from the plain part for the HTML part,
since the latter may be different if e.g. the HTML contains no line
breaks and hence is a single long line.

See #771
This commit is contained in:
Michael Gratton 2020-03-29 16:29:30 +11:00
parent f3c02c7800
commit 2eb597fec1
2 changed files with 21 additions and 20 deletions

View file

@ -210,10 +210,12 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
Gee.List<GMime.Object> body_parts = new Gee.LinkedList<GMime.Object>();
// Share the body charset and encoding between plain and HTML
// parts, so we don't need to work it out twice.
// Share the body charset between plain and HTML parts, so we
// don't need to work it out twice. This doesn't work for the
// content encoding however since the HTML encoding may need
// to be different, e.g. if it contains lines longer than
// allowed by RFC822/SMTP.
string? body_charset = null;
GMime.ContentEncoding? body_encoding = null;
// Body: text format (optional)
if (email.body_text != null) {
@ -222,7 +224,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
body_text = yield body_data_to_part(
email.body_text.data,
null,
null,
"text/plain",
true,
cancellable
@ -234,7 +235,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
body_charset = body_text.get_content_type().get_parameter(
"charset"
);
body_encoding = body_text.get_content_encoding();
body_parts.add(body_text);
}
}
@ -324,7 +324,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
body_html = yield body_data_to_part(
email.body_html.data,
body_charset,
body_encoding,
"text/html",
false,
cancellable
@ -1146,7 +1145,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
*/
private async GMime.Part body_data_to_part(uint8[] content,
string? charset,
GMime.ContentEncoding? encoding,
string content_type,
bool is_flowed,
GLib.Cancellable? cancellable)
@ -1157,13 +1155,13 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
}
GMime.StreamFilter filter_stream = new GMime.StreamFilter(content_stream);
filter_stream.add(new GMime.FilterCharset(UTF8_CHARSET, charset));
if (encoding == null) {
encoding = yield Utils.get_best_encoding(
filter_stream,
GMime.EncodingConstraint.7BIT,
cancellable
);
}
GMime.ContentEncoding encoding = yield Utils.get_best_encoding(
filter_stream,
GMime.EncodingConstraint.7BIT,
cancellable
);
if (is_flowed && encoding == GMime.ContentEncoding.BASE64) {
// Base64-encoded text needs to have CR's added after LF's
// before encoding, otherwise it breaks format=flowed. See

View file

@ -236,7 +236,6 @@ This is the second line.
Geary.RFC822.Message message = message_from_composed_email.end(async_result());
string message_data = message.get_network_buffer(true).to_string();
print("\n'%s'\n", message_data);
assert_true(message_data.has_suffix("..newline\r\n..\r\n"));
}
@ -251,10 +250,14 @@ This is the second line.
new GLib.DateTime.now_local(),
new Geary.RFC822.MailboxAddresses.single(from)
).set_to(new Geary.RFC822.MailboxAddresses.single(to));
composed.body_text = """
long long long long long long long long long long long long long long long long long
""";
composed.body_html = "<p>%s<p>".printf(composed.body_text);
GLib.StringBuilder buf = new GLib.StringBuilder();
for (int i = 0; i < 2000; i++) {
buf.append("long ");
}
//composed.body_text = buf.str;
composed.body_html = "<p>%s<p>".printf(buf.str);
this.message_from_composed_email.begin(
composed,
@ -264,7 +267,7 @@ long long long long long long long long long long long long long long long long
string message_data = message.get_network_buffer(true).to_string();
foreach (var line in message_data.split("\n")) {
assert_true(line.length < 80, line);
assert_true(line.length < 1000, line);
}
}