Catch illegalargumentexception.

This is being thrown by default by the URLdecoder.decode method
when something "goes wrong" with an unencoded character.

Fixes b/6580123 java.lang.IllegalArgumentException in java.net.URLDecoder

Change-Id: Id45264d17b5f44071b18308e8e4e5b1009d08cd1
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index b26e05e..0dca32a 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -902,15 +902,23 @@
 
     @VisibleForTesting
     protected String decodeEmailInUri(String s) throws UnsupportedEncodingException {
-        // TODO: handle the case where there are spaces in the display name as well as the email
-        // such as "Guy with spaces <guy+with+spaces@gmail.com>" as they it could be encoded
-        // ambiguously.
-
+        // TODO: handle the case where there are spaces in the display name as
+        // well as the email such as "Guy with spaces <guy+with+spaces@gmail.com>"
+        // as they could be encoded ambiguously.
         // Since URLDecode.decode changes + into ' ', and + is a valid
         // email character, we need to find/ replace these ourselves before
         // decoding.
         String replacePlus = s.replace("+", "%2B");
-        return URLDecoder.decode(replacePlus, UTF8_ENCODING_NAME);
+        try {
+            return URLDecoder.decode(replacePlus, UTF8_ENCODING_NAME);
+        } catch (IllegalArgumentException e) {
+            if (LogUtils.isLoggable(LOG_TAG, LogUtils.VERBOSE)) {
+                LogUtils.e(LOG_TAG, "%s while decoding '%s'", e.getMessage(), s);
+            } else {
+                LogUtils.e(LOG_TAG, e, "Exception  while decoding mailto address");
+            }
+            return null;
+        }
     }
 
     /**
@@ -931,7 +939,9 @@
             } else {
                 to = decodeEmailInUri(mailToString.substring(length, index));
             }
-            addToAddresses(Arrays.asList(TextUtils.split(to, ",")));
+            if (!TextUtils.isEmpty(to)) {
+                addToAddresses(Arrays.asList(TextUtils.split(to, ",")));
+            }
         } catch (UnsupportedEncodingException e) {
             if (LogUtils.isLoggable(LOG_TAG, LogUtils.VERBOSE)) {
                 LogUtils.e(LOG_TAG, "%s while decoding '%s'", e.getMessage(), mailToString);