[geary/cherry-pick-d89ee326] Merge branch 'mjog/composer-fixes' into 'mainline'




commit 2de149aaeb67917bb08af1bc718c68820e05116a
Author: Michael Gratton <mike vee net>
Date:   Sun Sep 27 13:37:03 2020 +0000

    Merge branch 'mjog/composer-fixes' into 'mainline'
    
    Misc composer fixes
    
    See merge request GNOME/geary!587
    
    (cherry picked from commit d89ee3262909c4a211182f12551a92ede4c84f01)
    
    bd85c4f1 Composer.Widget: Fix criticals when "mailto:"; has empty body
    70186163 Composer.Widget: Fix critical when immediately detaching a new composer

 src/client/application/application-main-window.vala |  2 +-
 src/client/composer/composer-widget.vala            | 19 +++++++++++--------
 test/client/composer/composer-widget-test.vala      | 10 ++++++++++
 3 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index e8428459c..73b50e335 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -875,7 +875,7 @@ public class Application.MainWindow :
      */
     internal void show_composer(Composer.Widget composer) {
         if (this.has_composer) {
-            composer.detach();
+            composer.detach(this.application);
         } else {
             // See if the currently displayed conversation contains
             // any of the composer's referred emails (preferring the
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index ecc3fbfdc..37e93fb43 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -575,8 +575,11 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
         Gee.HashMultiMap<string, string> headers = new Gee.HashMultiMap<string, string>();
         if (mailto.has_prefix(MAILTO_URI_PREFIX)) {
             // Parse the mailto link.
+            string? email = null;
             string[] parts = mailto.substring(MAILTO_URI_PREFIX.length).split("?", 2);
-            string email = Uri.unescape_string(parts[0]);
+            if (parts.length > 0) {
+                email = Uri.unescape_string(parts[0]);
+            }
             string[] params = parts.length == 2 ? parts[1].split("&") : new string[0];
             foreach (string param in params) {
                 string[] param_parts = param.split("=", 2);
@@ -587,14 +590,16 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
             }
 
             // Assemble the headers.
-            if (email.length > 0 && headers.contains("to"))
+            if (!Geary.String.is_empty_or_whitespace(email) &&
+                headers.contains("to")) {
                 this.to = "%s,%s".printf(
                     email, Geary.Collection.first(headers.get("to"))
                 );
-            else if (email.length > 0)
+            } else if (!Geary.String.is_empty_or_whitespace(email)) {
                 this.to = email;
-            else if (headers.contains("to"))
+            } else if (headers.contains("to")) {
                 this.to = Geary.Collection.first(headers.get("to"));
+            }
 
             if (headers.contains("cc"))
                 this.cc = Geary.Collection.first(headers.get("cc"));
@@ -780,10 +785,8 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
     }
 
     /** Detaches the composer and opens it in a new window. */
-    public void detach() {
+    public void detach(Application.Client application) {
         Gtk.Widget? focused_widget = null;
-        var application = this.container.top_window.application as Application.Client;
-
         if (this.container != null) {
             focused_widget = this.container.top_window.get_focus();
             this.container.close();
@@ -2369,7 +2372,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
     }
 
     private void on_detach() {
-        detach();
+        detach(this.container.top_window.application as Application.Client);
     }
 
     private void on_add_attachment() {
diff --git a/test/client/composer/composer-widget-test.vala b/test/client/composer/composer-widget-test.vala
index c35b52e44..6b31c9435 100644
--- a/test/client/composer/composer-widget-test.vala
+++ b/test/client/composer/composer-widget-test.vala
@@ -92,6 +92,7 @@ public class Composer.WidgetTest : TestCase {
         add_test("load_empty_body", load_empty_body);
         add_test("load_empty_body_to", load_empty_body_to);
         add_test("load_mailto", load_mailto);
+        add_test("load_mailto_empty", load_mailto_empty);
         add_test("load_context_edit", load_context_edit);
         add_test("load_context_reply_sender", load_context_reply_sender);
         add_test("load_context_reply_sender_with_reply_to", load_context_reply_sender_with_reply_to);
@@ -164,6 +165,15 @@ public class Composer.WidgetTest : TestCase {
         assert_equal(widget.to, "mailto example com");
     }
 
+    public void load_mailto_empty() throws GLib.Error {
+        var widget = new Widget(this.application, this.config, this.account);
+
+        widget.load_mailto.begin("mailto:";, this.async_completion);
+        widget.load_mailto.end(async_result());
+
+        assert_equal(widget.to, "");
+    }
+
     public void load_context_edit() throws GLib.Error {
         var widget = new Widget(this.application, this.config, this.account);
         var email = load_email(MESSAGE_WITH_REPLY_TO);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]