package com.fsck.k9.mail;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static org.junit.Assert.assertEquals;


@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 21)
public class AddressTest {
    /**
     * 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
     */
    @Test
    public void testParseWithMissingEmail() {
        Address[] addresses = Address.parse("NAME ONLY");
        assertEquals(1, addresses.length);
        assertEquals(null, addresses[0].getAddress());
        assertEquals("NAME ONLY", addresses[0].getPersonal());
    }

    /**
     * test name + valid email
     */
    @Test
    public void testPraseWithValidEmail() {
        Address[] addresses = Address.parse("Max Mustermann <maxmuster@mann.com>");
        assertEquals(1, addresses.length);
        assertEquals("maxmuster@mann.com", addresses[0].getAddress());
        assertEquals("Max Mustermann", addresses[0].getPersonal());
    }

    /**
     * test with multi email addresses
     */
    @Test
    public void testPraseWithValidEmailMulti() {
        Address[] addresses = 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());
    }
}

@@ -883,34 +883,34 @@
 ublic void testP
-r
 a
+r
 seWithValidEmail
@@ -1179,32 +1179,1381 @@
 onal());%0A    %7D%0A%0A
+    @Test%0A    public void testParseUnusualEmails() %7B%0A        String%5B%5D testEmails = new String %5B%5D %7B%0A                %22prettyandsimple@example.com%22,%0A                %22very.common@example.com%22,%0A                %22disposable.style.email.with+symbol@example.com%22,%0A                %22other.email-with-dash@example.com%22,%0A                //TODO: Handle addresses with quotes%0A                /*%0A                %22%5C%22much.more unusual%5C%22@example.com%22,%0A                %22%5C%22very.unusual.@.unusual.com%5C%22@example.com%22,%0A                //%22very.(),:;%3C%3E%5B%5D%5C%22.VERY.%5C%22very@%5C%5C %5C%22very%5C%22.unusual%22@strange.example.com%0A                %22%5C%22very.(),:;%3C%3E%5B%5D%5C%5C%5C%22.VERY.%5C%5C%5C%22very@%5C%5C%5C%5C %5C%5C%5C%22very%5C%5C%5C%22.unusual%5C%22@strange.example.com%22,%0A                %22%5C%22()%3C%3E%5B%5D:,;@%5C%5C%5C%5C%5C%5C%5C%22!#$%25&'*+-/=?%5E_%60%7B%7D%7C ~.a%5C%22@example.org%22,%0A                %22%5C%22 %5C%22@example.org%22,%0A                */%0A                %22admin@mailserver1%22,%0A                %22#!$%25&'*+-/=?%5E_%60%7B%7D%7C~@example.org%22,%0A                %22example@localhost%22,%0A                %22example@s.solutions%22,%0A                %22user@com%22,%0A                %22user@localserver%22,%0A                %22user@%5BIPv6:2001:db8::1%5D%22%0A        %7D;%0A        for(String testEmail: testEmails) %7B%0A            Address%5B%5D addresses = Address.parse(%22Anonymous %3C%22+testEmail+%22%3E%22);%0A            assertEquals(1, addresses.length);%0A            assertEquals(testEmail, addresses%5B0%5D.getAddress());%0A        %7D%0A    %7D%0A%0A
     /**%0A     * t
@@ -2622,18 +2622,18 @@
 id testP
-r
 a
+r
 seWithVa

Add tests for unusual email formats