Repository: thundernest/k-9
Issue: Parsing email address list with invalid base64 encoded word crashes the app

Test case:
```java
Address.parse("=?utf-8?b?invalid#?= <oops@example.com>");
```

Exception:
```
java.lang.Error: java.io.IOException: Unexpected base64 byte

	at org.apache.james.mime4j.codec.DecoderUtil.decodeBase64(DecoderUtil.java:89)
	at org.apache.james.mime4j.codec.DecoderUtil.decodeB(DecoderUtil.java:106)
	at org.apache.james.mime4j.codec.DecoderUtil.tryDecodeEncodedWord(DecoderUtil.java:233)
	at org.apache.james.mime4j.codec.DecoderUtil.decodeEncodedWords(DecoderUtil.java:187)
	at org.apache.james.mime4j.codec.DecoderUtil.decodeEncodedWords(DecoderUtil.java:143)
	at org.apache.james.mime4j.field.address.Builder.buildAddress(Builder.java:71)
	at org.apache.james.mime4j.field.address.Builder.buildAddressList(Builder.java:51)
	at org.apache.james.mime4j.field.address.DefaultAddressParser.parseAddressList(DefaultAddressParser.java:69)
	at org.apache.james.mime4j.field.address.DefaultAddressParser.parseAddressList(DefaultAddressParser.java:73)
	at com.fsck.k9.mail.Address.parse(Address.java:145)
        [...]
Caused by: java.io.IOException: Unexpected base64 byte
	at org.apache.james.mime4j.codec.Base64InputStream.read0(Base64InputStream.java:193)
	at org.apache.james.mime4j.codec.Base64InputStream.read(Base64InputStream.java:87)
	at org.apache.james.mime4j.codec.DecoderUtil.decodeBase64(DecoderUtil.java:80)
        ... 39 more
```

I'm not sure what the best way to handle this is. Probably using the personal part as is. However, the options in MIME4J are somewhat limited. It's either crashing with an `Error` or ignoring invalid characters when decoding the base64 payload. Since we don't like crashes we should probably start out with the latter option.

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

diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java b/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
index 042fbbf44..eb8183768 100644
--- a/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
+++ b/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
@@ -2,12 +2,14 @@
 package com.fsck.k9.mail;
 
 import android.support.annotation.VisibleForTesting;
+
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Pattern;
 
 import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.codec.EncoderUtil;
 import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.dom.address.MailboxList;
@@ -30,7 +32,6 @@ public class Address implements Serializable {
 
     private String mPersonal;
 
-
     public Address(Address address) {
         mAddress = address.mAddress;
         mPersonal = address.mPersonal;
@@ -142,7 +143,7 @@ public class Address implements Serializable {
         }
         List<Address> addresses = new ArrayList<>();
         try {
-            MailboxList parsedList =  DefaultAddressParser.DEFAULT.parseAddressList(addressList).flatten();
+            MailboxList parsedList =  DefaultAddressParser.DEFAULT.parseAddressList(addressList, DecodeMonitor.SILENT).flatten();
 
             for (int i = 0, count = parsedList.size(); i < count; i++) {
                 Mailbox mailbox = parsedList.get(i);
diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java
index 82a48be51..1fa329163 100644
--- a/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java
+++ b/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java
@@ -180,4 +180,10 @@ public class AddressTest {
 
         assertNull(result);
     }
+
+    @Test
+    public void handlesInvalidBase64Encoding() throws Exception {
+        Address address = Address.parse("=?utf-8?b?invalid#?= <oops@example.com>")[0];
+        assertEquals("oops@example.com", address.getAddress());
+    }
 }