Bug 761069: B2G MMS: support email addressing model, r=philikon
authorVicamo Yang <vyang@mozilla.com>
Thu, 26 Jul 2012 10:07:56 +0800
changeset 100520 fec33ba83a185b59186d89bb4eed95d8852725f3
parent 100519 01fd43320aefda48d232ab08778aa1c8dd13d6d1
child 100521 05852ba29df2a14fbade7e4fb8a6db02ccde4aac
push idunknown
push userunknown
push dateunknown
reviewersphilikon
bugs761069
milestone17.0a1
Bug 761069: B2G MMS: support email addressing model, r=philikon
dom/mms/src/ril/MmsPduHelper.jsm
dom/mms/tests/test_mms_pdu_helper.js
--- a/dom/mms/src/ril/MmsPduHelper.jsm
+++ b/dom/mms/src/ril/MmsPduHelper.jsm
@@ -87,18 +87,23 @@ let Address = {
       return {address: result[1], type: result[2]};
     }
 
     let type;
     if (str.match(/^[\+*#]\d+$/)) {
       type = "num";
     } else if (str.match(/^\w+$/)) {
       type = "alphanum";
+    } else if (str.indexOf("@") > 0) {
+      // E-mail should match the definition of `mailbox` as described in section
+      // 3.4 of RFC2822, but excluding the obsolete definitions as indicated by
+      // the "obs-" prefix. Here we match only a `@` character.
+      type = "email";
     } else {
-      type = "unknown";
+      throw new WSP.CodeError("Address: invalid address");
     }
 
     return {address: str, type: type};
   },
 };
 
 /**
  * Header-field = MMS-header | Application-header
--- a/dom/mms/tests/test_mms_pdu_helper.js
+++ b/dom/mms/tests/test_mms_pdu_helper.js
@@ -66,19 +66,22 @@ add_test(function test_Address_decode() 
                       {address: "+123", type: "num"});
   wsp_decode_test(MMS.Address, strToCharCodeArray("*123"),
                       {address: "*123", type: "num"});
   wsp_decode_test(MMS.Address, strToCharCodeArray("#123"),
                       {address: "#123", type: "num"});
   // Test for alphanum-shortcode
   wsp_decode_test(MMS.Address, strToCharCodeArray("H0wD0Y0uTurnTh1s0n"),
                       {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"});
-  // Test for other unknown typed sequence
+  // Test for email address
   wsp_decode_test(MMS.Address, strToCharCodeArray("Joe User <joe@user.org>"),
-                      {address: "Joe User <joe@user.org>", type: "unknown"});
+                      {address: "Joe User <joe@user.org>", type: "email"});
+  // Test for invalid address
+  wsp_decode_test(MMS.Address, strToCharCodeArray("@@@@@"),
+                  null, "CodeError");
 
   run_next_test();
 });
 
 //
 // Test target: HeaderField
 //