Repository: thundernest/k-9
Issue: Composer crashes when an invalid mail address is about to be shown in recipient selector 

### Steps to reproduce
1. create a contact with a name and an invalid mail address, e. g. "(none)"
2. click '+' to compose new message
3. type first letters of the contact name until it should be shown
### Logcat

```
09-09 22:12:26.740 10531 10531 E AndroidRuntime: FATAL EXCEPTION: main
09-09 22:12:26.740 10531 10531 E AndroidRuntime: Process: com.fsck.k9, PID: 10531
09-09 22:12:26.740 10531 10531 E AndroidRuntime: Theme: themes:{default=overlay:com.brit.swiftdark, fontPkg:com.brit.swiftdark, com.android.systemui=overlay:com.brit.s
wiftdark, com.android.systemui.navbar=overlay:com.brit.swiftdark}
09-09 22:12:26.740 10531 10531 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null obj
ect reference
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.text.SpannableString.<init>(SpannableString.java:30)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.text.Spannable$Factory.newSpannable(Spannable.java:67)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at com.fsck.k9.activity.compose.RecipientAdapter.highlightText(RecipientAdapter.java:182)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at com.fsck.k9.activity.compose.RecipientAdapter.bindView(RecipientAdapter.java:92)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at com.fsck.k9.activity.compose.RecipientAdapter.getView(RecipientAdapter.java:72)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.AbsListView.obtainView(AbsListView.java:2346)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1734)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.ListView.measureHeightOfChildren(ListView.java:1281)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1209)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.ListPopupWindow.show(ListPopupWindow.java:584)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1106)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at com.fsck.k9.view.RecipientSelectView.showDropDown(RecipientSelectView.java:226)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:975)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.AutoCompleteTextView.-wrap2(AutoCompleteTextView.java)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.widget.AutoCompleteTextView$PopupDataSetObserver$1.run(AutoCompleteTextView.java:1300)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:739)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:95)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:148)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:5463)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
09-09 22:12:26.740 10531 10531 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-09 22:12:26.741  1716  4127 W ActivityManager:   Force finishing activity com.fsck.k9/.activity.MessageCompose
```
### Environment

K-9 Mail version: 5.111 (master)

Android version:
6.0.1


Changed files:
k9mail/src/main/java/com/fsck/k9/view/RecipientSelectView.java, k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java

diff --git a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java
index bd359924f..60df445fd 100644
--- a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java
+++ b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientLoader.java
@@ -238,12 +238,14 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
                 }
             }
 
-            Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI));
             Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey);
-            recipient.photoThumbnailUri = photoUri;
+            if (recipient.isValidEmailAddress()) {
+              Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI));
 
-            recipientMap.put(email, recipient);
-            recipients.add(recipient);
+              recipient.photoThumbnailUri = photoUri;
+              recipientMap.put(email, recipient);
+              recipients.add(recipient);
+            }
         }
 
         cursor.close();
diff --git a/k9mail/src/main/java/com/fsck/k9/view/RecipientSelectView.java b/k9mail/src/main/java/com/fsck/k9/view/RecipientSelectView.java
index 34066918c..28ca83b25 100644
--- a/k9mail/src/main/java/com/fsck/k9/view/RecipientSelectView.java
+++ b/k9mail/src/main/java/com/fsck/k9/view/RecipientSelectView.java
@@ -550,6 +550,10 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
             return address.getAddress();
         }
 
+        public boolean isValidEmailAddress() {
+            return (address.getAddress() != null);
+        }
+
         public String getDisplayNameOrUnknown(Context context) {
             String displayName = getDisplayName();
             if (displayName != null) {