Eliminate redundant methods in Address class

THIS DOES NOT CHANGE ANY EXISTING FUNCTIONALITY.

Address.pack() has been removed and all calls replaced with its synonym Address.toHeader().
Address.unpack() has been renamed to Address.fromHeader() to follow the new naming convention.

In days of yore, pack() and toHeader() used to do different things. Now they are identical and
thus one is superfluous. We have standardized on toHeader() and fromHeader().

Change-Id: I199d7718e6816385c9433c3bd7201f80f2287f10
diff --git a/src/com/android/emailcommon/mail/Address.java b/src/com/android/emailcommon/mail/Address.java
index ccd18a3..307c1a0 100644
--- a/src/com/android/emailcommon/mail/Address.java
+++ b/src/com/android/emailcommon/mail/Address.java
@@ -85,7 +85,7 @@
 
     private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0];
 
-    // delimiters are chars that do not appear in an email address, used by pack/unpack
+    // delimiters are chars that do not appear in an email address, used by fromHeader
     private static final char LIST_DELIMITER_EMAIL = '\1';
     private static final char LIST_DELIMITER_PERSONAL = '\2';
 
@@ -423,45 +423,46 @@
     }
 
     /**
-     * Returns exactly the same result as Address.toString(Address.unpack(packedList)).
+     * Returns exactly the same result as Address.toString(Address.fromHeader(addressList)).
      */
-    public static String unpackToString(String packedList) {
-        return toString(unpack(packedList));
+    public static String fromHeaderToString(String addressList) {
+        return toString(fromHeader(addressList));
     }
 
     /**
-     * Returns exactly the same result as Address.pack(Address.parse(textList)).
+     * Returns exactly the same result as Address.toHeader(Address.parse(addressList)).
      */
-    public static String parseAndPack(String textList) {
-        return Address.pack(Address.parse(textList));
+    public static String parseToHeader(String addressList) {
+        return Address.toHeader(Address.parse(addressList));
     }
 
     /**
-     * Returns null if the packedList has 0 addresses, otherwise returns the first address.
-     * The same as Address.unpack(packedList)[0] for non-empty list.
+     * Returns null if the addressList has 0 addresses, otherwise returns the first address.
+     * The same as Address.fromHeader(addressList)[0] for non-empty list.
      * This is an utility method that offers some performance optimization opportunities.
      */
-    public static Address unpackFirst(String packedList) {
-        Address[] array = unpack(packedList);
+    public static Address firstAddress(String addressList) {
+        Address[] array = fromHeader(addressList);
         return array.length > 0 ? array[0] : null;
     }
 
     /**
-     * Convert a packed list of addresses to a form suitable for use in an RFC822 header.
+     * This method exists to convert an address list formatted in a deprecated legacy format to the
+     * standard RFC822 header format. {@link #fromHeader(String)} is capable of reading the legacy
+     * format and the RFC822 format. {@link #toHeader()} always produces the RFC822 format.
+     *
      * This implementation is brute-force, and could be replaced with a more efficient version
      * if desired.
      */
-    public static String packedToHeader(String packedList) {
-        return toHeader(unpack(packedList));
+    public static String reformatToHeader(String addressList) {
+        return toHeader(fromHeader(addressList));
     }
 
     /**
-     * Unpacks an address list that is either CSV of RFC822 addresses OR (for backward
-     * compatibility) previously packed with pack()
-     * @param addressList string packed with pack() or CSV of RFC822 addresses
-     * @return array of addresses resulting from unpack
+     * @param addressList a CSV of RFC822 addresses or the deprecated legacy string format
+     * @return array of addresses parsed from <code>addressList</code>
      */
-    public static Address[] unpack(String addressList) {
+    public static Address[] fromHeader(String addressList) {
         if (addressList == null || addressList.length() == 0) {
             return EMPTY_ADDRESS_ARRAY;
         }
@@ -505,21 +506,6 @@
         return addresses.toArray(new Address[addresses.size()]);
     }
 
-    /**
-     * Generate a String containing RFC822 addresses separated by commas
-     * NOTE: We used to "pack" these addresses in an app-specific format, but no longer do so
-     */
-    public static String pack(Address[] addresses) {
-        return Address.toHeader(addresses);
-    }
-
-    /**
-     * Produces the same result as pack(array), but only packs one (this) address.
-     */
-    public String pack() {
-        return toHeader();
-    }
-
     public static final Creator<Address> CREATOR = new Creator<Address>() {
         @Override
         public Address createFromParcel(Parcel parcel) {
diff --git a/src/com/android/mail/providers/Message.java b/src/com/android/mail/providers/Message.java
index 74935ed..35a543d 100644
--- a/src/com/android/mail/providers/Message.java
+++ b/src/com/android/mail/providers/Message.java
@@ -370,14 +370,14 @@
     public Message(Context context, MimeMessage mimeMessage, Uri emlFileUri)
             throws MessagingException {
         // Set message header values.
-        setFrom(Address.pack(mimeMessage.getFrom()));
-        setTo(Address.pack(mimeMessage.getRecipients(
+        setFrom(Address.toHeader(mimeMessage.getFrom()));
+        setTo(Address.toHeader(mimeMessage.getRecipients(
                 com.android.emailcommon.mail.Message.RecipientType.TO)));
-        setCc(Address.pack(mimeMessage.getRecipients(
+        setCc(Address.toHeader(mimeMessage.getRecipients(
                 com.android.emailcommon.mail.Message.RecipientType.CC)));
-        setBcc(Address.pack(mimeMessage.getRecipients(
+        setBcc(Address.toHeader(mimeMessage.getRecipients(
                 com.android.emailcommon.mail.Message.RecipientType.BCC)));
-        setReplyTo(Address.pack(mimeMessage.getReplyTo()));
+        setReplyTo(Address.toHeader(mimeMessage.getReplyTo()));
         subject = mimeMessage.getSubject();
 
         final Date sentDate = mimeMessage.getSentDate();
diff --git a/tests/src/com/android/emailcommon/mail/AddressUnitTests.java b/tests/src/com/android/emailcommon/mail/AddressUnitTests.java
index 13bf686..48186e4 100644
--- a/tests/src/com/android/emailcommon/mail/AddressUnitTests.java
+++ b/tests/src/com/android/emailcommon/mail/AddressUnitTests.java
@@ -44,15 +44,14 @@
             ;
     private static final int MULTI_ADDRESSES_COUNT = 10;
 
-    private static final Address PACK_ADDR_1 = new Address("john@gmail.com", "John Doe");
-    private static final Address PACK_ADDR_2 = new Address("foo@bar.com", null);
-    private static final Address PACK_ADDR_3 = new Address(
-            "mar.y+test@gmail.com", "Mar-y, B; B*arr");
-    private static final Address[][] PACK_CASES = {
-            {PACK_ADDR_2}, {PACK_ADDR_1},
-            {PACK_ADDR_1, PACK_ADDR_2}, {PACK_ADDR_2, PACK_ADDR_1},
-            {PACK_ADDR_1, PACK_ADDR_3}, {PACK_ADDR_2, PACK_ADDR_2},
-            {PACK_ADDR_1, PACK_ADDR_2, PACK_ADDR_3}, {PACK_ADDR_3, PACK_ADDR_1, PACK_ADDR_2}
+    private static final Address ADDR_1 = new Address("john@gmail.com", "John Doe");
+    private static final Address ADDR_2 = new Address("foo@bar.com", null);
+    private static final Address ADDR_3 = new Address("mar.y+test@gmail.com", "Mar-y, B; B*arr");
+    private static final Address[][] TO_HEADER_CASES = {
+            {ADDR_2}, {ADDR_1},
+            {ADDR_1, ADDR_2}, {ADDR_2, ADDR_1},
+            {ADDR_1, ADDR_3}, {ADDR_2, ADDR_2},
+            {ADDR_1, ADDR_2, ADDR_3}, {ADDR_3, ADDR_1, ADDR_2}
     };
 
     Address mAddress1;
@@ -557,34 +556,34 @@
      * NOTE:  This is not a claim that these edge cases are "correct", only to maintain consistent
      * behavior while I am changing some of the code in the function under test.
      */
-    public void testEmptyPack() {
+    public void testEmptyToHeader() {
         String result;
 
         // null input => null string
-        result = Address.pack(null);
+        result = Address.toHeader(null);
         assertNull("packing null", result);
 
         // zero-length input => null string
-        result = Address.pack(new Address[] { });
+        result = Address.toHeader(new Address[] { });
         assertNull("packing empty array", result);
     }
 
     /**
-     * Simple quick checks of empty-input edge conditions for unpack()
+     * Simple quick checks of empty-input edge conditions for fromHeader()
      *
      * NOTE:  This is not a claim that these edge cases are "correct", only to maintain consistent
      * behavior while I am changing some of the code in the function under test.
      */
-    public void testEmptyUnpack() {
+    public void testEmptyFromHeader() {
         Address[] result;
 
         /*
         // null input => empty array
-        result = Address.unpack(null);
+        result = Address.fromHeader(null);
         assertTrue("unpacking null address", result != null && result.length == 0);
         */
         // empty string input => empty array
-        result = Address.unpack("");
+        result = Address.fromHeader("");
         assertTrue("unpacking zero-length", result != null && result.length == 0);
     }
 
@@ -613,60 +612,60 @@
         return true;
     }
 
-    public void testPackUnpack() {
-        for (Address[] list : PACK_CASES) {
-            String packed = Address.pack(list);
-            assertTrue(packed, addressArrayEquals(list, Address.unpack(packed)));
+    public void testToHeaderFromHeader() {
+        for (Address[] list : TO_HEADER_CASES) {
+            String packed = Address.toHeader(list);
+            assertTrue(packed, addressArrayEquals(list, Address.fromHeader(packed)));
         }
     }
 
     /**
-     * Tests that unpackToString() returns the same result as toString(unpack()).
+     * Tests that fromHeaderToString() returns the same result as toString(fromHeader()).
      */
-    public void testUnpackToString() {
-        assertNull(Address.unpackToString(null));
-        assertNull(Address.unpackToString(""));
+    public void testFromHeaderToString() {
+        assertNull(Address.fromHeaderToString(null));
+        assertNull(Address.fromHeaderToString(""));
 
-        for (Address[] list : PACK_CASES) {
-            String packed = Address.pack(list);
-            String s1 = Address.unpackToString(packed);
-            String s2 = Address.toString(Address.unpack(packed));
+        for (Address[] list : TO_HEADER_CASES) {
+            String packed = Address.toHeader(list);
+            String s1 = Address.fromHeaderToString(packed);
+            String s2 = Address.toString(Address.fromHeader(packed));
             assertEquals(s2, s2, s1);
         }
     }
 
     /**
-     * Tests that parseAndPack() returns the same result as pack(parse()).
+     * Tests that parseToHeader() returns the same result as toHeader(parse()).
      */
     public void testParseAndPack() {
-        String s1 = Address.parseAndPack(MULTI_ADDRESSES_LIST);
-        String s2 = Address.pack(Address.parse(MULTI_ADDRESSES_LIST));
+        String s1 = Address.parseToHeader(MULTI_ADDRESSES_LIST);
+        String s2 = Address.toHeader(Address.parse(MULTI_ADDRESSES_LIST));
         assertEquals(s2, s1);
     }
 
     public void testSinglePack() {
         Address[] addrArray = new Address[1];
-        for (Address address : new Address[]{PACK_ADDR_1, PACK_ADDR_2, PACK_ADDR_3}) {
-            String packed1 = address.pack();
+        for (Address address : new Address[]{ADDR_1, ADDR_2, ADDR_3}) {
+            String packed1 = address.toHeader();
             addrArray[0] = address;
-            String packed2 = Address.pack(addrArray);
+            String packed2 = Address.toHeader(addrArray);
             assertEquals(packed1, packed2);
         }
     }
 
     /**
      * Tests that:
-     * 1. unpackFirst() with empty list returns null.
-     * 2. unpackFirst() with non-empty returns the same as unpack()[0]
+     * 1. firstAddress() with empty list returns null.
+     * 2. firstAddress() with non-empty returns the same as fromHeader()[0]
      */
-    public void testUnpackFirst() {
-        assertNull(Address.unpackFirst(null));
-        assertNull(Address.unpackFirst(""));
+    public void testFirstAddress() {
+        assertNull(Address.firstAddress(null));
+        assertNull(Address.firstAddress(""));
 
-        for (Address[] list : PACK_CASES) {
-            String packed = Address.pack(list);
-            Address[] array = Address.unpack(packed);
-            Address first = Address.unpackFirst(packed);
+        for (Address[] list : TO_HEADER_CASES) {
+            String packed = Address.toHeader(list);
+            Address[] array = Address.fromHeader(packed);
+            Address first = Address.firstAddress(packed);
             assertTrue(packed, addressEquals(array[0], first));
         }
     }