From 6a76b073c3c9c5db55896c751d53fafa5ac177f5 Mon Sep 17 00:00:00 2001 From: Bernhard Redl Date: Wed, 2 Nov 2011 02:04:19 +0100 Subject: [PATCH 1/2] Improve handling of From: Headers without parseable email addresses (fixes 3814) --- src/com/fsck/k9/mail/Address.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/fsck/k9/mail/Address.java b/src/com/fsck/k9/mail/Address.java index b768caca0..63c59d0d4 100644 --- a/src/com/fsck/k9/mail/Address.java +++ b/src/com/fsck/k9/mail/Address.java @@ -149,6 +149,8 @@ public class Address { } } catch (MimeException pe) { Log.e(K9.LOG_TAG, "MimeException in Address.parse()", pe); + //but we do an silent failover : we just use the given string as name with empty address + addresses.add(new Address("", addressList)); } return addresses.toArray(EMPTY_ADDRESS_ARRAY); } From 68cecb168e21364b5015dea3f55b1d315f8202ae Mon Sep 17 00:00:00 2001 From: Bernhard Redl Date: Thu, 3 Nov 2011 01:35:43 +0100 Subject: [PATCH 2/2] added testcases for address#parse function,changed empty to null (conforms to existing code) --- src/com/fsck/k9/mail/Address.java | 2 +- tests/src/com/fsck/k9/helper/Address.java | 37 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/src/com/fsck/k9/helper/Address.java diff --git a/src/com/fsck/k9/mail/Address.java b/src/com/fsck/k9/mail/Address.java index 63c59d0d4..d2ce99d6c 100644 --- a/src/com/fsck/k9/mail/Address.java +++ b/src/com/fsck/k9/mail/Address.java @@ -150,7 +150,7 @@ public class Address { } catch (MimeException pe) { Log.e(K9.LOG_TAG, "MimeException in Address.parse()", pe); //but we do an silent failover : we just use the given string as name with empty address - addresses.add(new Address("", addressList)); + addresses.add(new Address(null, addressList,false)); } return addresses.toArray(EMPTY_ADDRESS_ARRAY); } diff --git a/tests/src/com/fsck/k9/helper/Address.java b/tests/src/com/fsck/k9/helper/Address.java new file mode 100644 index 000000000..250cad347 --- /dev/null +++ b/tests/src/com/fsck/k9/helper/Address.java @@ -0,0 +1,37 @@ +package com.fsck.k9.helper; +import junit.framework.TestCase; + +public class Address extends TestCase { + /** + * test the possibility to parse "From:" fields with no email. + * for example: From: News for Vector Limited - Google Finance + * http://code.google.com/p/k9mail/issues/detail?id=3814 + */ + public void testParseWithMissingEmail() { + com.fsck.k9.mail.Address[] addresses = com.fsck.k9.mail.Address.parse("NAME ONLY"); + assertEquals(1, addresses.length); + assertEquals(null, addresses[0].getAddress()); + assertEquals("NAME ONLY", addresses[0].getPersonal()); + } + + /** + * test name + valid email + */ + public void testPraseWithValidEmail() { + com.fsck.k9.mail.Address[] addresses = com.fsck.k9.mail.Address.parse("Max Mustermann "); + assertEquals(1, addresses.length); + assertEquals("maxmuster@mann.com", addresses[0].getAddress()); + assertEquals("Max Mustermann", addresses[0].getPersonal()); + } + /** + * test with multi email addresses + */ + public void testPraseWithValidEmailMulti() { + com.fsck.k9.mail.Address[] addresses = com.fsck.k9.mail.Address.parse("lorem@ipsum.us,mark@twain.com"); + assertEquals(2, addresses.length); + assertEquals("lorem@ipsum.us", addresses[0].getAddress()); + assertEquals(null, addresses[0].getPersonal()); + assertEquals("mark@twain.com", addresses[1].getAddress()); + assertEquals(null, addresses[1].getPersonal()); + } +}