@@ -566,7 +566,11 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
566566 new UserIdEmailsKeysDaoSource ().getLongIdsByEmail (getContext (), email )));
567567 }
568568
569- prepareAliasForReplyIfNeed (aliases );
569+ if (incomingMessageInfo != null ) {
570+ prepareAliasForReplyIfNeed (aliases );
571+ } else if (onChangeMessageEncryptedTypeListener .getMessageEncryptionType () == MessageEncryptionType .ENCRYPTED ) {
572+ showFirstMatchedAliasWithPrvKey (aliases );
573+ }
570574
571575 if (fromAddressesArrayAdapter .getCount () == 1 ) {
572576 if (imageButtonAliases .getVisibility () == View .VISIBLE ) {
@@ -885,39 +889,62 @@ private List<PgpContact> runUpdatePgpContactsAction(List<PgpContact> pgpContacts
885889 * @param aliases A list of Gmail aliases.
886890 */
887891 private void prepareAliasForReplyIfNeed (List <String > aliases ) {
888- if (incomingMessageInfo != null ) {
889- ArrayList <String > toAddresses ;
890- if (folderType == FoldersManager .FolderType .SENT ) {
891- toAddresses = incomingMessageInfo .getFrom ();
892- } else {
893- toAddresses = incomingMessageInfo .getTo ();
894- }
892+ MessageEncryptionType messageEncryptionType = onChangeMessageEncryptedTypeListener .getMessageEncryptionType ();
895893
896- if (toAddresses != null ) {
897- String firstFoundedAlias = null ;
898- for (String toAddress : toAddresses ) {
899- if (firstFoundedAlias == null ) {
900- for (String alias : aliases ) {
901- if (alias .equalsIgnoreCase (toAddress )) {
894+ ArrayList <String > toAddresses ;
895+ if (folderType == FoldersManager .FolderType .SENT ) {
896+ toAddresses = incomingMessageInfo .getFrom ();
897+ } else {
898+ toAddresses = incomingMessageInfo .getTo ();
899+ }
900+
901+ if (toAddresses != null ) {
902+ String firstFoundedAlias = null ;
903+ for (String toAddress : toAddresses ) {
904+ if (firstFoundedAlias == null ) {
905+ for (String alias : aliases ) {
906+ if (alias .equalsIgnoreCase (toAddress )) {
907+ if (messageEncryptionType == MessageEncryptionType .ENCRYPTED ) {
908+ if (fromAddressesArrayAdapter .hasPrvKey (alias )) {
909+ firstFoundedAlias = alias ;
910+ }
911+ } else {
902912 firstFoundedAlias = alias ;
903- break ;
904913 }
914+ break ;
905915 }
906- } else {
907- break ;
908916 }
917+ } else {
918+ break ;
909919 }
920+ }
910921
911- if (firstFoundedAlias != null ) {
912- int position = fromAddressesArrayAdapter .getPosition (firstFoundedAlias );
913- if (position != -1 ) {
914- spinnerFrom .setSelection (position );
915- }
922+ if (firstFoundedAlias != null ) {
923+ int position = fromAddressesArrayAdapter .getPosition (firstFoundedAlias );
924+ if (position != -1 ) {
925+ spinnerFrom .setSelection (position );
916926 }
917927 }
918928 }
919929 }
920930
931+ private void showFirstMatchedAliasWithPrvKey (List <String > aliases ) {
932+ String firstFoundedAliasWithPrvKey = null ;
933+ for (String alias : aliases ) {
934+ if (fromAddressesArrayAdapter .hasPrvKey (alias )) {
935+ firstFoundedAliasWithPrvKey = alias ;
936+ break ;
937+ }
938+ }
939+
940+ if (firstFoundedAliasWithPrvKey != null ) {
941+ int position = fromAddressesArrayAdapter .getPosition (firstFoundedAliasWithPrvKey );
942+ if (position != -1 ) {
943+ spinnerFrom .setSelection (position );
944+ }
945+ }
946+ }
947+
921948 /**
922949 * Remove not valid emails from the recipients list.
923950 *
0 commit comments