Repository: thundernest/k-9
Issue: Crash on open certain messages

Certain spam messages, not detected by German email provider GMX (false negative), causing k-9 to crash.

### Expected behavior
On tapping a message from folder list, the message should appear in detailed view.

### Actual behavior
On tapping a message from folder list, k-9 crashes

### Steps to reproduce
1. Try getting a spam message from GMX.
2. Account type doesn't matter.
3. Try to open the message.

### Environment
K-9 Mail version: 5.600

Android version: 8.1.0

Account type (IMAP, POP3, WebDAV/Exchange): IMAP/POP3

### Additional information
When opening the same message with Thunderbird, a blank page appears. The source view contains some crude HTML code. If needed, I can link the body's content.

Hope I hit the relevant error from **logcat**:

[logcat_10-08-2018_09-49-44.txt](https://github.com/k9mail/k-9/files/2455144/logcat_10-08-2018_09-49-44.txt)


Changed files:
mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java, mail/common/src/main/java/com/fsck/k9/mail/Address.java

diff --git a/mail/common/src/main/java/com/fsck/k9/mail/Address.java b/mail/common/src/main/java/com/fsck/k9/mail/Address.java
index 88c773913..7fd63782b 100644
--- a/mail/common/src/main/java/com/fsck/k9/mail/Address.java
+++ b/mail/common/src/main/java/com/fsck/k9/mail/Address.java
@@ -1,6 +1,7 @@
 
 package com.fsck.k9.mail;
 
+import android.support.annotation.NonNull;
 import android.support.annotation.VisibleForTesting;
 
 import java.io.Serializable;
@@ -28,6 +29,7 @@ public class Address implements Serializable {
      */
     private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0];
 
+    @NonNull
     private String mAddress;
 
     private String mPersonal;
@@ -46,10 +48,16 @@ public class Address implements Serializable {
     }
 
     private Address(String address, String personal, boolean parse) {
+        if (address == null) {
+            throw new IllegalArgumentException("address");
+        }
         if (parse) {
             Rfc822Token[] tokens =  Rfc822Tokenizer.tokenize(address);
             if (tokens.length > 0) {
                 Rfc822Token token = tokens[0];
+                if (token.getAddress() == null) {
+                    throw new IllegalArgumentException("token.getAddress()");
+                }
                 mAddress = token.getAddress();
                 String name = token.getName();
                 if (!TextUtils.isEmpty(name)) {
@@ -91,6 +99,9 @@ public class Address implements Serializable {
     }
 
     public void setAddress(String address) {
+        if (address == null) {
+            throw new IllegalArgumentException("address");
+        }
         this.mAddress = address;
     }
 
@@ -151,8 +162,7 @@ public class Address implements Serializable {
             }
         } catch (MimeException pe) {
             Timber.e(pe, "MimeException in Address.parse()");
-            //but we do an silent failover : we just use the given string as name with empty address
-            addresses.add(new Address(null, addressList, false));
+            // broken addresses are never added to the resulting array
         }
         return addresses.toArray(EMPTY_ADDRESS_ARRAY);
     }
diff --git a/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java b/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java
index 1fa329163..190bfc226 100644
--- a/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java
+++ b/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java
@@ -21,9 +21,7 @@ public class AddressTest {
     public void parse_withMissingEmail__shouldSetPersonal() {
         Address[] addresses = Address.parse("NAME ONLY");
 
-        assertEquals(1, addresses.length);
-        assertEquals(null, addresses[0].getAddress());
-        assertEquals("NAME ONLY", addresses[0].getPersonal());
+        assertEquals(0, addresses.length);
     }
 
     /**
@@ -116,10 +114,9 @@ public class AddressTest {
 
     @Test
     public void hashCode_withoutAddress() throws Exception {
-        Address address = Address.parse("name only")[0];
-        assertNull(address.getAddress());
-        
-        address.hashCode();
+        Address[] addresses = Address.parse("name only");
+
+        assertEquals(0, addresses.length);
     }
 
     @Test
@@ -130,27 +127,6 @@ public class AddressTest {
         address.hashCode();
     }
 
-    @Test
-    public void equals_withoutAddress_matchesSame() throws Exception {
-        Address address = Address.parse("name only")[0];
-        Address address2 = Address.parse("name only")[0];
-        assertNull(address.getAddress());
-
-        boolean result = address.equals(address2);
-
-        assertTrue(result);
-    }
-
-    @Test
-    public void equals_withoutAddress_doesNotMatchWithAddress() throws Exception {
-        Address address = Address.parse("name only")[0];
-        Address address2 = Address.parse("name <alice.example.com>")[0];
-
-        boolean result = address.equals(address2);
-
-        assertFalse(result);
-    }
-
     @Test
     public void equals_withoutPersonal_matchesSame() throws Exception {
         Address address = Address.parse("alice@example.org")[0];
@@ -172,15 +148,6 @@ public class AddressTest {
         assertFalse(result);
     }
 
-    @Test
-    public void getHostname_withoutAddress_isNull() throws Exception {
-        Address address = Address.parse("Alice")[0];
-
-        String result = address.getHostname();
-
-        assertNull(result);
-    }
-
     @Test
     public void handlesInvalidBase64Encoding() throws Exception {
         Address address = Address.parse("=?utf-8?b?invalid#?= <oops@example.com>")[0];