[geary/wip/714922-multiple-addresses: 4/4] Proper reply/all handling



commit 33f736aff5b76551b0289f5b3a772e56b1a69801
Author: Charles Lindsay <chaz yorba org>
Date:   Thu Mar 20 18:07:05 2014 -0700

    Proper reply/all handling

 src/client/composer/composer-window.vala      |    7 ++---
 src/engine/api/geary-account-information.vala |   11 ++++++++
 src/engine/rfc822/rfc822-utils.vala           |   33 ++++++++++++++++++-------
 3 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index de2a476..636be6d 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -364,11 +364,10 @@ public class ComposerWindow : Gtk.Window {
                 
                 case ComposeType.REPLY:
                 case ComposeType.REPLY_ALL:
-                    // TODO: find alternate email address?
-                    string? sender_address = account.information.email;
-                    to = Geary.RFC822.Utils.create_to_addresses_for_reply(referred, sender_address);
+                    Gee.List<string> sender_addresses = account.information.get_all_email_addresses();
+                    to = Geary.RFC822.Utils.create_to_addresses_for_reply(referred, sender_addresses);
                     if (compose_type == ComposeType.REPLY_ALL)
-                        cc = Geary.RFC822.Utils.create_cc_addresses_for_reply_all(referred, sender_address);
+                        cc = Geary.RFC822.Utils.create_cc_addresses_for_reply_all(referred, 
sender_addresses);
                     subject = Geary.RFC822.Utils.create_subject_for_reply(referred);
                     in_reply_to = referred.message_id.value;
                     references = Geary.RFC822.Utils.reply_references(referred);
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 7c1022e..af23348 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -209,6 +209,17 @@ public class Geary.AccountInformation : BaseObject {
     }
     
     /**
+     * Return a list of the primary and all alternate email addresses.
+     */
+    public Gee.List<string> get_all_email_addresses() {
+        Gee.ArrayList<string> all = new Gee.ArrayList<string>();
+        all.add(email);
+        if (alternate_emails != null)
+            all.add_all(alternate_emails);
+        return all;
+    }
+    
+    /**
      * Return whether this account allows setting the save_sent_mail option.
      * If not, save_sent_mail will always be true and setting it will be
      * ignored.
diff --git a/src/engine/rfc822/rfc822-utils.vala b/src/engine/rfc822/rfc822-utils.vala
index 7d94d83..1fc6ac4 100644
--- a/src/engine/rfc822/rfc822-utils.vala
+++ b/src/engine/rfc822/rfc822-utils.vala
@@ -69,14 +69,22 @@ private void remove_address(Gee.List<Geary.RFC822.MailboxAddress> addresses,
     }
 }
 
+private bool email_is_from_sender(Geary.Email email, Gee.List<string>? sender_addresses) {
+    if (sender_addresses == null)
+        return false;
+    
+    return Geary.traverse<string>(sender_addresses).any(a =>
+        !String.is_empty(a) && email.from.contains(a));
+}
+
 public string create_to_addresses_for_reply(Geary.Email email,
-    string? sender_address = null) {
+    Gee.List<string>? sender_addresses = null) {
     Gee.List<Geary.RFC822.MailboxAddress> new_to =
         new Gee.ArrayList<Geary.RFC822.MailboxAddress>();
     
     // If we're replying to something we sent, send it to the same people we originally did.
     // Otherwise, we'll send to the reply-to address or the from address.
-    if (email.to != null && !String.is_empty(sender_address) && email.from.contains(sender_address))
+    if (email.to != null && email_is_from_sender(email, sender_addresses))
         new_to.add_all(email.to.get_all());
     else if (email.reply_to != null)
         new_to.add_all(email.reply_to.get_all());
@@ -84,29 +92,36 @@ public string create_to_addresses_for_reply(Geary.Email email,
         new_to.add_all(email.from.get_all());
     
     // Exclude the current sender.  No need to receive the mail they're sending.
-    if (!String.is_empty(sender_address))
-        remove_address(new_to, sender_address);
+    if (sender_addresses != null) {
+        foreach (string address in sender_addresses) {
+            if (!String.is_empty(address))
+                remove_address(new_to, address);
+        }
+    }
     
     return new_to.size > 0 ? new Geary.RFC822.MailboxAddresses(new_to).to_rfc822_string() : "";
 }
 
 public string create_cc_addresses_for_reply_all(Geary.Email email,
-    string? sender_address = null) {
+    Gee.List<string>? sender_addresses = null) {
     Gee.List<Geary.RFC822.MailboxAddress> new_cc = new Gee.ArrayList<Geary.RFC822.MailboxAddress>();
     
     // If we're replying to something we received, also add other recipients.  Don't do this for
     // emails we sent, since everyone we sent it to is already covered in
     // create_to_addresses_for_reply().
-    if (email.to != null && (String.is_empty(sender_address) ||
-        !email.from.contains(sender_address)))
+    if (email.to != null && !email_is_from_sender(email, sender_addresses))
         new_cc.add_all(email.to.get_all());
     
     if (email.cc != null)
         new_cc.add_all(email.cc.get_all());
     
     // Again, exclude the current sender.
-    if (!String.is_empty(sender_address))
-        remove_address(new_cc, sender_address, true);
+    if (sender_addresses != null) {
+        foreach (string address in sender_addresses) {
+            if (!String.is_empty(address))
+                remove_address(new_cc, address, true);
+        }
+    }
     
     return new_cc.size > 0 ? new Geary.RFC822.MailboxAddresses(new_cc).to_rfc822_string() : "";
 }


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