Regularize usage of ReplyFromAccount#name

b/11334332
b/11292541

Change-Id: I0394ea2caf86bbf200a3027f288aa078d965503c
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 720ab35..2426c6d 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -940,10 +940,10 @@
         message.accountUri = null;
         final String email = selectedReplyFromAccount != null ? selectedReplyFromAccount.address
                 : mAccount != null ? mAccount.getEmailAddress() : null;
-        // TODO: this behavior is wrong. Pull the name from selectedReplyFromAccount.name
-        final String senderName = mAccount != null ? mAccount.getSenderName() : null;
+        final String senderName = selectedReplyFromAccount != null ? selectedReplyFromAccount.name
+                : mAccount != null ? mAccount.getSenderName() : null;
         final Address address = new Address(senderName, email);
-        message.setFrom(address.pack());
+        message.setFrom(address.toHeader());
         message.draftType = getDraftType(mode);
         return message;
     }
@@ -1092,18 +1092,18 @@
                 return from;
             }
         }
-        return new ReplyFromAccount(account, account.uri, account.getEmailAddress(), account.name,
-                account.getEmailAddress(), true, false);
+        return new ReplyFromAccount(account, account.uri, account.getEmailAddress(),
+                account.getSenderName(), account.getEmailAddress(), true, false);
     }
 
-    private ReplyFromAccount getReplyFromAccountFromDraft(Account account, Message msg) {
-        String sender = msg.getFrom();
+    private ReplyFromAccount getReplyFromAccountFromDraft(final Account account,
+            final Message msg) {
+        final Address[] draftFroms = Address.parse(msg.getFrom());
+        final String sender = draftFroms.length > 0 ? draftFroms[0].getAddress() : "";
         ReplyFromAccount replyFromAccount = null;
         List<ReplyFromAccount> replyFromAccounts = mFromSpinner.getReplyFromAccounts();
         if (TextUtils.equals(account.getEmailAddress(), sender)) {
-            replyFromAccount = new ReplyFromAccount(mAccount, mAccount.uri,
-                    mAccount.getEmailAddress(), mAccount.name, mAccount.getEmailAddress(),
-                    true, false);
+            replyFromAccount = getDefaultReplyFromAccount(account);
         } else {
             for (ReplyFromAccount fromAccount : replyFromAccounts) {
                 if (TextUtils.equals(fromAccount.address, sender)) {