[geary/mjog/493-undo-send: 3/20] Util.Email.to_short_recipient_display: Consider all of to/cc/bcc



commit b66cad11d32e700645bdd697c762510979877316
Author: Michael Gratton <mike vee net>
Date:   Fri Nov 8 10:14:04 2019 +1100

    Util.Email.to_short_recipient_display: Consider all of to/cc/bcc
    
    Rather than just using an email's to field, also use cc and bcc when
    generating the string.

 src/client/application/application-controller.vala |  2 +-
 src/client/util/util-email.vala                    | 59 ++++++++++++++--------
 2 files changed, 40 insertions(+), 21 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index c17066e5..5340cb0a 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -1640,7 +1640,7 @@ public class Application.Controller : Geary.BaseObject {
         // string substitution is a list of recipients of the email.
         string message = _(
             "Successfully sent mail to %s."
-        ).printf(Util.Email.to_short_recipient_display(sent.to));
+        ).printf(Util.Email.to_short_recipient_display(sent));
         Components.InAppNotification notification =
             new Components.InAppNotification(message);
         this.main_window.add_notification(notification);
diff --git a/src/client/util/util-email.vala b/src/client/util/util-email.vala
index 17b2bcb5..d86e0cca 100644
--- a/src/client/util/util-email.vala
+++ b/src/client/util/util-email.vala
@@ -108,29 +108,48 @@ namespace Util.Email {
      * list contains more mailboxes then an indication of how many
      * additional are present.
      */
-    public string to_short_recipient_display(Geary.RFC822.MailboxAddresses mailboxes) {
-        if (mailboxes.size == 0) {
-            // Translators: This is shown for displaying a list of
-            // email recipients that happens to be empty,
-            // i.e. contains no email addresses.
-            return _("(No recipients)");
+    public string to_short_recipient_display(Geary.EmailHeaderSet headers) {
+        Geary.RFC822.MailboxAddresses? mailboxes = null;
+        int total = 0;
+        if (headers.to != null) {
+            mailboxes = headers.to;
+            total += headers.to.size;
+        }
+        if (headers.cc != null) {
+            if (mailboxes == null) {
+                mailboxes = headers.cc;
+            }
+            total += headers.cc.size;
+        }
+        if (headers.bcc != null) {
+            if (mailboxes == null) {
+                mailboxes = headers.bcc;
+            }
+            total += headers.bcc.size;
         }
 
-        // Always mention the first recipient
-        string first_recipient = mailboxes.get(0).to_short_display();
-        if (mailboxes.size == 1)
-            return first_recipient;
+        /// Translators: This is shown for displaying a list of email
+        /// recipients that happens to be empty, i.e. contains no
+        /// email addresses.
+        string display = _("(No recipients)");
+        if (total > 0) {
+            // Always mention the first recipient
+            display = mailboxes.get(0).to_short_display();
 
-        // Translators: This is used for displaying a short list of
-        // email recipients lists with two or more addresses. The
-        // first (string) substitution is address of the first, the
-        // second substitution is the number of n - 1 remaining
-        // recipients.
-        return GLib.ngettext(
-            "%s and %d other",
-            "%s and %d others",
-            mailboxes.size - 1
-        ).printf(first_recipient, mailboxes.size - 1);
+            if (total > 1) {
+                /// Translators: This is used for displaying a short
+                /// list of email recipients lists with two or more
+                /// addresses. The first (string) substitution is
+                /// address of the first, the second substitution is
+                /// the number of n - 1 remaining recipients.
+                display = GLib.ngettext(
+                    "%s and %d other",
+                    "%s and %d others",
+                    total - 1
+                ).printf(display, total - 1);
+            }
+        }
+        return display;
     }
 
     /**


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