Skip to content

Commit

Permalink
Don't store two copies in Sent for Office 365 and Google (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
marbetschar committed Jul 28, 2021
1 parent 11746ea commit 20edc30
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions data/io.elementary.mail.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<li>Preserve conversation subjects when replying or forwarding</li>
<li>Disable the composer while messages are being sent</li>
<li>Edit saved draft messages</li>
<li>Make sure we don't save sent messages twice for some account types</li>
<li>Stability improvements</li>
<li>Updated translations</li>
</ul>
Expand Down
35 changes: 32 additions & 3 deletions src/Backend/Session.vala
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,19 @@ public class Mail.Backend.Session : Camel.Session {
return null;
}

private Camel.Transport? get_camel_transport_from_mail_submission_source (E.Source mail_submission_source) throws GLib.Error {
private E.Source? get_transport_source_from_mail_submission_source (E.Source mail_submission_source) throws GLib.Error {
if (!mail_submission_source.has_extension (E.SOURCE_EXTENSION_MAIL_SUBMISSION)) {
return null;
}

unowned E.SourceMailSubmission mail_submission = (E.SourceMailSubmission) mail_submission_source.get_extension (E.SOURCE_EXTENSION_MAIL_SUBMISSION);
var transport_source = registry.ref_source (mail_submission.transport_uid);
return registry.ref_source (mail_submission.transport_uid);
}

private Camel.Transport? get_camel_transport_from_transport_source (E.Source transport_source) throws GLib.Error {
if (!transport_source.has_extension (E.SOURCE_EXTENSION_MAIL_TRANSPORT)) {
return null;
}
unowned E.SourceMailTransport mail_transport = (E.SourceMailTransport) transport_source.get_extension (E.SOURCE_EXTENSION_MAIL_TRANSPORT);

return add_service (transport_source.uid, mail_transport.backend_name, Camel.ProviderType.TRANSPORT) as Camel.Transport;
Expand All @@ -372,7 +378,12 @@ public class Mail.Backend.Session : Camel.Session {
throw new Camel.Error.ERROR_GENERIC ("Unable to retrieve source for mail submission.");
}

Camel.Transport? transport = get_camel_transport_from_mail_submission_source (mail_submission_source);
E.Source? transport_source = get_transport_source_from_mail_submission_source (mail_submission_source);
if (transport_source == null) {
throw new Camel.Error.ERROR_GENERIC ("Unable to retrieve source for transport.");
}

Camel.Transport? transport = get_camel_transport_from_transport_source (transport_source);
if (transport == null) {
throw new Camel.ServiceError.UNAVAILABLE ("No camel service for sending email found.");
}
Expand All @@ -382,8 +393,26 @@ public class Mail.Backend.Session : Camel.Session {
yield transport.send_to (message, from, recipients, GLib.Priority.LOW, null, out sent_message_saved);
yield transport.disconnect (true, GLib.Priority.LOW, null);

if (transport_source.has_extension (E.SOURCE_EXTENSION_AUTHENTICATION)) {
unowned var transport_auth_extension = (E.SourceAuthentication) transport_source.get_extension (E.SOURCE_EXTENSION_AUTHENTICATION);

if (
E.util_utf8_strstrcase (transport_auth_extension.host, ".gmail.com") != null ||
E.util_utf8_strstrcase (transport_auth_extension.host, ".googlemail.com") != null ||
E.util_utf8_strstrcase (transport_auth_extension.host, ".office365.com") != null
) {
/*
* Skip appending to Sent folder for GMail and Office 365, because both store sent messages
* automatically, thus it would make doubled copies on the server.
* https://gitlab.gnome.org/GNOME/evolution-data-server/-/blob/master/src/camel/providers/imapx/camel-imapx-store.c#L2811
*/
sent_message_saved = true;
}
}

if (!sent_message_saved) {
var provider = transport.get_provider ();

if (provider != null && Camel.ProviderFlags.DISABLE_SENT_FOLDER in provider.flags) {
debug ("Sent folder is disabled - sent message is not saved.");

Expand Down

0 comments on commit 20edc30

Please sign in to comment.