From ddcf1e257e43a9e08bb4bdcd237f93651c3651d5 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 29 Oct 2017 21:03:56 -0400 Subject: [PATCH] Fixed issue 2846 Skip invalid input; parse strictly otherwise. See [issue](https://github.com/k9mail/k-9/issues/2846) for details. --- k9mail-library/src/main/java/com/fsck/k9/mail/Address.java | 5 +++-- .../src/test/java/com/fsck/k9/mail/AddressTest.java | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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
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#?= ")[0]; + assertEquals("oops@example.com", address.getAddress()); + } }