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.
This commit is contained in:
Michael Gratton 2019-11-08 10:14:04 +11:00 committed by Michael James Gratton
parent 455eb770fd
commit 9b4edf5726
2 changed files with 40 additions and 21 deletions

View file

@ -1640,7 +1640,7 @@ public class Application.Controller : Geary.BaseObject {
// string substitution is a list of recipients of the email. // string substitution is a list of recipients of the email.
string message = _( string message = _(
"Successfully sent mail to %s." "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 = Components.InAppNotification notification =
new Components.InAppNotification(message); new Components.InAppNotification(message);
this.main_window.add_notification(notification); this.main_window.add_notification(notification);

View file

@ -108,29 +108,48 @@ namespace Util.Email {
* list contains more mailboxes then an indication of how many * list contains more mailboxes then an indication of how many
* additional are present. * additional are present.
*/ */
public string to_short_recipient_display(Geary.RFC822.MailboxAddresses mailboxes) { public string to_short_recipient_display(Geary.EmailHeaderSet headers) {
if (mailboxes.size == 0) { Geary.RFC822.MailboxAddresses? mailboxes = null;
// Translators: This is shown for displaying a list of int total = 0;
// email recipients that happens to be empty, if (headers.to != null) {
// i.e. contains no email addresses. mailboxes = headers.to;
return _("(No recipients)"); 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 /// Translators: This is shown for displaying a list of email
string first_recipient = mailboxes.get(0).to_short_display(); /// recipients that happens to be empty, i.e. contains no
if (mailboxes.size == 1) /// email addresses.
return first_recipient; 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 if (total > 1) {
// email recipients lists with two or more addresses. The /// Translators: This is used for displaying a short
// first (string) substitution is address of the first, the /// list of email recipients lists with two or more
// second substitution is the number of n - 1 remaining /// addresses. The first (string) substitution is
// recipients. /// address of the first, the second substitution is
return GLib.ngettext( /// the number of n - 1 remaining recipients.
"%s and %d other", display = GLib.ngettext(
"%s and %d others", "%s and %d other",
mailboxes.size - 1 "%s and %d others",
).printf(first_recipient, mailboxes.size - 1); total - 1
).printf(display, total - 1);
}
}
return display;
} }
/** /**