@@ -385,6 +385,8 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
385385 fromAddressesArrayAdapter .clear ();
386386 fromAddressesArrayAdapter .addAll (aliases );
387387
388+ prepareAliasForReplyIfNeed (aliases );
389+
388390 if (fromAddressesArrayAdapter .getCount () > 1 ) {
389391 editTextFrom .setCompoundDrawablesWithIntrinsicBounds (0 , 0 , R .mipmap .ic_arrow_drop_down_grey , 0 );
390392 } else {
@@ -507,6 +509,40 @@ public boolean isMessageSendingNow() {
507509 return isMessageSendingNow ;
508510 }
509511
512+ /**
513+ * Prepare an alias for the reply. Will be used the email address that the email was received. Will be used the
514+ * first found matched email.
515+ *
516+ * @param aliases A list of Gmail aliases.
517+ */
518+ private void prepareAliasForReplyIfNeed (List <String > aliases ) {
519+ if (incomingMessageInfo != null ) {
520+ ArrayList <String > toAddresses = incomingMessageInfo .getTo ();
521+ if (toAddresses != null ) {
522+ String firstFoundedAlias = null ;
523+ for (String toAddress : toAddresses ) {
524+ if (firstFoundedAlias == null ) {
525+ for (String alias : aliases ) {
526+ if (alias .equalsIgnoreCase (toAddress )) {
527+ firstFoundedAlias = alias ;
528+ break ;
529+ }
530+ }
531+ } else {
532+ break ;
533+ }
534+ }
535+
536+ if (firstFoundedAlias != null ) {
537+ int position = fromAddressesArrayAdapter .getPosition (firstFoundedAlias );
538+ if (position != -1 ) {
539+ spinnerFrom .setSelection (position );
540+ }
541+ }
542+ }
543+ }
544+ }
545+
510546 /**
511547 * Remove not valid emails from the recipients list.
512548 *
0 commit comments