Repository: thundernest/k-9
Issue: Crash when sending to address with an umlaut

I haven't done any variation testing, as I just finally found out. What I had was:

A contact which I accidentially typed an `ü` instead of `ue`, used the contact suggestion feature for recepient. As soon as I hit send, Android's "Application has stopped working" window popped up, after a restart it's as if nothing had happened.

Replacing the character in my contacts helped, but It took me probably a month to figure out what the issue was.

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java
index e2cf5893e..d9ca0307c 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java
@@ -28,6 +28,7 @@ import com.fsck.k9.ui.R;
 import com.fsck.k9.mail.Address;
 import com.fsck.k9.view.RecipientSelectView.Recipient;
 import com.fsck.k9.view.RecipientSelectView.RecipientCryptoStatus;
+import org.apache.james.mime4j.util.CharsetUtil;
 import timber.log.Timber;
 
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
@@ -240,13 +241,14 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
             Address[] addresses = Address.parseUnencoded(uid);
 
             for (Address address : addresses) {
-                if (recipientMap.containsKey(address.getAddress())) {
+                String emailAddress = address.getAddress();
+                if (!isSupportedEmailAddress(emailAddress) || recipientMap.containsKey(emailAddress)) {
                     continue;
                 }
 
                 Recipient recipient = new Recipient(address);
                 recipients.add(recipient);
-                recipientMap.put(address.getAddress(), recipient);
+                recipientMap.put(emailAddress, recipient);
             }
         }
 
@@ -256,10 +258,12 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
     private void fillContactDataFromAddresses(Address[] addresses, List<Recipient> recipients,
             Map<String, Recipient> recipientMap) {
         for (Address address : addresses) {
-            // TODO actually query contacts - not sure if this is possible in a single query tho :(
-            Recipient recipient = new Recipient(address);
-            recipients.add(recipient);
-            recipientMap.put(address.getAddress(), recipient);
+            if (isSupportedEmailAddress(address.getAddress())) {
+                // TODO actually query contacts - not sure if this is possible in a single query tho :(
+                Recipient recipient = new Recipient(address);
+                recipients.add(recipient);
+                recipientMap.put(address.getAddress(), recipient);
+            }
         }
     }
 
@@ -438,7 +442,7 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
             String email = cursor.getString(INDEX_EMAIL);
 
             // already exists? just skip then
-            if (email == null || recipientMap.containsKey(email)) {
+            if (email == null || !isSupportedEmailAddress(email) || recipientMap.containsKey(email)) {
                 // TODO We should probably merging contacts with the same email address
                 continue;
             }
@@ -583,4 +587,7 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
         }
     }
 
+    private boolean isSupportedEmailAddress(String address) {
+        return CharsetUtil.isASCII(address);
+    }
 }