engine: Detect mime encoding constraint from server EHLO

Fix #1416
This commit is contained in:
Cédric Bellegarde 2023-08-30 17:19:39 +02:00 committed by Niels De Graef
parent a43a1a0275
commit 42c5b6248a
8 changed files with 30 additions and 5 deletions

View file

@ -1723,7 +1723,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
Geary.ComposedEmail draft = yield to_composed_email(null, true); Geary.ComposedEmail draft = yield to_composed_email(null, true);
yield this.draft_manager.update( yield this.draft_manager.update(
yield new Geary.RFC822.Message.from_composed_email( yield new Geary.RFC822.Message.from_composed_email(
draft, null, null draft, null, GMime.EncodingConstraint.7BIT, null
), ),
null, null,
null null

View file

@ -326,7 +326,7 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
var processor = new Processor(this.template); var processor = new Processor(this.template);
var composed = processor.merge(fields); var composed = processor.merge(fields);
var message = yield new Geary.RFC822.Message.from_composed_email( var message = yield new Geary.RFC822.Message.from_composed_email(
composed, null, cancellable composed, null, GMime.EncodingConstraint.7BIT, cancellable
); );
var id = new EmailIdentifier(next_id++); var id = new EmailIdentifier(next_id++);

View file

@ -236,6 +236,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
public async Message.from_composed_email(Geary.ComposedEmail email, public async Message.from_composed_email(Geary.ComposedEmail email,
string? message_id, string? message_id,
GMime.EncodingConstraint constraint,
GLib.Cancellable? cancellable) GLib.Cancellable? cancellable)
throws Error { throws Error {
this.message = new GMime.Message(true); this.message = new GMime.Message(true);
@ -338,6 +339,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
null, null,
"text/plain", "text/plain",
true, true,
constraint,
cancellable cancellable
); );
} catch (GLib.Error err) { } catch (GLib.Error err) {
@ -438,6 +440,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
body_charset, body_charset,
"text/html", "text/html",
false, false,
constraint,
cancellable cancellable
); );
} catch (GLib.Error err) { } catch (GLib.Error err) {
@ -1200,6 +1203,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
string? charset, string? charset,
string content_type, string content_type,
bool is_flowed, bool is_flowed,
GMime.EncodingConstraint constraint,
GLib.Cancellable? cancellable) GLib.Cancellable? cancellable)
throws GLib.Error { throws GLib.Error {
GMime.Stream content_stream = new GMime.StreamMem.with_buffer(content); GMime.Stream content_stream = new GMime.StreamMem.with_buffer(content);
@ -1211,7 +1215,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
GMime.ContentEncoding encoding = yield Utils.get_best_encoding( GMime.ContentEncoding encoding = yield Utils.get_best_encoding(
filter_stream, filter_stream,
GMime.EncodingConstraint.7BIT, constraint,
cancellable cancellable
); );

View file

@ -12,6 +12,7 @@ public class Geary.Smtp.Capabilities : Geary.GenericCapabilities {
public const string AUTH_PLAIN = "plain"; public const string AUTH_PLAIN = "plain";
public const string AUTH_LOGIN = "login"; public const string AUTH_LOGIN = "login";
public const string AUTH_OAUTH2 = "xoauth2"; public const string AUTH_OAUTH2 = "xoauth2";
public const string 8BITMIME = "8bitmime";
public const string NAME_SEPARATOR = " "; public const string NAME_SEPARATOR = " ";
public const string VALUE_SEPARATOR = " "; public const string VALUE_SEPARATOR = " ";

View file

@ -120,6 +120,21 @@ public class Geary.Smtp.ClientService : Geary.ClientService {
throws GLib.Error { throws GLib.Error {
debug("Saving composed email: %s", email_subject(composed)); debug("Saving composed email: %s", email_subject(composed));
// Detect server encoding constraint
GMime.EncodingConstraint constraint = GMime.EncodingConstraint.7BIT;
try {
ClientConnection smtp = new ClientConnection(this.remote);
yield smtp.connect_async(cancellable);
yield smtp.say_hello_async(cancellable);
if (smtp.capabilities.has_capability(Capabilities.8BITMIME)) {
constraint = GMime.EncodingConstraint.8BIT;
}
yield smtp.disconnect_async(cancellable);
} catch (Error err) {
// Oh well
}
// XXX work out what our public IP address is somehow and use // XXX work out what our public IP address is somehow and use
// that in preference to the originator's domain // that in preference to the originator's domain
var from = composed.from; var from = composed.from;
@ -128,7 +143,10 @@ public class Geary.Smtp.ClientService : Geary.ClientService {
: this.account.primary_mailbox.domain; : this.account.primary_mailbox.domain;
Geary.RFC822.Message rfc822 = Geary.RFC822.Message rfc822 =
yield new Geary.RFC822.Message.from_composed_email( yield new Geary.RFC822.Message.from_composed_email(
composed, GMime.utils_generate_message_id(domain), cancellable composed,
GMime.utils_generate_message_id(domain),
constraint,
cancellable
); );
EmailIdentifier id = yield this.outbox.create_email_async( EmailIdentifier id = yield this.outbox.create_email_async(

View file

@ -44,7 +44,7 @@ async void main_async() throws Error {
} }
msg = yield new Geary.RFC822.Message.from_composed_email( msg = yield new Geary.RFC822.Message.from_composed_email(
composed_email, null, null composed_email, null, GMime.EncodingConstraint.7BIT, null
); );
} }

View file

@ -446,6 +446,7 @@ This is the second line.
return yield new Geary.RFC822.Message.from_composed_email( return yield new Geary.RFC822.Message.from_composed_email(
composed, composed,
GMime.utils_generate_message_id(composed.from.get(0).domain), GMime.utils_generate_message_id(composed.from.get(0).domain),
GMime.EncodingConstraint.7BIT,
null null
); );
} }

View file

@ -133,6 +133,7 @@ class Integration.Smtp.ClientSession : TestCase {
return yield new Geary.RFC822.Message.from_composed_email( return yield new Geary.RFC822.Message.from_composed_email(
composed, composed,
GMime.utils_generate_message_id(from.domain), GMime.utils_generate_message_id(from.domain),
GMime.EncodingConstraint.7BIT,
null null
); );
} }