Bug 907140 - [B2G][MMS] Block sending email from MMS until we supported this feature. r=vyang
authorChia-hung Tai <ctai@mozilla.com>
Wed, 04 Sep 2013 14:50:27 +0800
changeset 158417 c9a5a622b27bea181a19f94dca8842da3d8ce203
parent 158416 80dccbfde2e8f947bb2112640b3108bc6db2a47a
child 158418 66870fbe0a8ef1572a38b46590df5d5883dc3ff5
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang
bugs907140
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 907140 - [B2G][MMS] Block sending email from MMS until we supported this feature. r=vyang
dom/mobilemessage/src/gonk/MmsPduHelper.jsm
dom/mobilemessage/src/gonk/MmsService.js
--- a/dom/mobilemessage/src/gonk/MmsPduHelper.jsm
+++ b/dom/mobilemessage/src/gonk/MmsPduHelper.jsm
@@ -6,16 +6,18 @@
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 let WSP = {};
 Cu.import("resource://gre/modules/WspPduHelper.jsm", WSP);
 
 Cu.import("resource://gre/modules/mms_consts.js");
 
+Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
+
 let DEBUG; // set to true to see debug messages
 
 this.MMS_VERSION = (function () {
   Cu.import("resource://gre/modules/Services.jsm");
 
   try {
     return Services.prefs.getIntPref("dom.mms.version");
   } catch(ex) {}
@@ -173,29 +175,60 @@ this.Address = {
     }
 
     if (!str) {
       throw new WSP.CodeError("Address: invalid value: " + JSON.stringify(value));
     }
 
     EncodedStringValue.encode(data, str);
   },
+
+  /**
+   * @param address
+   *        Address string which want to find the type.
+   *
+   * @return Address type.
+   */
+  resolveType: function resolveType(address) {
+    if (address.match(this.REGEXP_EMAIL)) {
+      return "email";
+    }
+
+    if (address.match(this.REGEXP_IPV4)) {
+      return "IPv4";
+    }
+
+    if (address.match(this.REGEXP_IPV6)) {
+      return "IPv6";
+    }
+
+    let normalizedAddress = PhoneNumberUtils.normalize(address, false);
+    if (PhoneNumberUtils.isPlainPhoneNumber(normalizedAddress)) {
+      return "PLMN";
+    }
+
+    return "Others";
+  },
 };
 
 defineLazyRegExp(Address, "REGEXP_DECODE_PLMN",        "^(\\+?[\\d.-]+)\\/TYPE=(PLMN)$");
 defineLazyRegExp(Address, "REGEXP_DECODE_IPV4",        "^(\\d{1,3}(?:\\.\\d{1,3}){3})\\/TYPE=(IPv4)$");
 defineLazyRegExp(Address, "REGEXP_DECODE_IPV6",        "^([\\da-fA-F]{4}(?::[\\da-fA-F]{4}){7})\\/TYPE=(IPv6)$");
 defineLazyRegExp(Address, "REGEXP_DECODE_CUSTOM",      "^([\\w\\+\\-.%]+)\\/TYPE=(\\w+)$");
 defineLazyRegExp(Address, "REGEXP_ENCODE_PLMN",        "^\\+?[\\d.-]+$");
 defineLazyRegExp(Address, "REGEXP_ENCODE_IPV4",        "^\\d{1,3}(?:\\.\\d{1,3}){3}$");
 defineLazyRegExp(Address, "REGEXP_ENCODE_IPV6",        "^[\\da-fA-F]{4}(?::[\\da-fA-F]{4}){7}$");
 defineLazyRegExp(Address, "REGEXP_ENCODE_CUSTOM_TYPE", "^\\w+$");
 defineLazyRegExp(Address, "REGEXP_ENCODE_CUSTOM_ADDR", "^[\\w\\+\\-.%]+$");
 defineLazyRegExp(Address, "REGEXP_NUM",                "^[\\+*#]\\d+$");
 defineLazyRegExp(Address, "REGEXP_ALPHANUM",           "^\\w+$");
+defineLazyRegExp(Address, "REGEXP_PLMN",               "^\\?[\\d.-]$");
+defineLazyRegExp(Address, "REGEXP_IPV4",               "^\\d{1,3}(?:\\.\\d{1,3}){3}$");
+defineLazyRegExp(Address, "REGEXP_IPV6",               "^[\\da-fA-F]{4}(?::[\\da-fA-F]{4}){7}$");
+defineLazyRegExp(Address, "REGEXP_EMAIL",              "@");
 
 /**
  * Header-field = MMS-header | Application-header
  *
  * @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.2
  */
 this.HeaderField = {
   /**
--- a/dom/mobilemessage/src/gonk/MmsService.js
+++ b/dom/mobilemessage/src/gonk/MmsService.js
@@ -1682,28 +1682,32 @@ MmsService.prototype = {
     let smil = aParams.smil;
 
     // |aMessage.headers|
     let headers = aMessage["headers"] = {};
     let receivers = aParams.receivers;
     if (receivers.length != 0) {
       let headersTo = headers["to"] = [];
       for (let i = 0; i < receivers.length; i++) {
-        let normalizedAddress = PhoneNumberUtils.normalize(receivers[i], false);
-        if (DEBUG) debug("createSavableFromParams: normalize phone number " +
-                         "from " + receivers[i] + " to " + normalizedAddress);
-
-        headersTo.push({"address": normalizedAddress, "type": "PLMN"});
-
-        // Check if the address is valid to send MMS.
-        if (!PhoneNumberUtils.isPlainPhoneNumber(normalizedAddress)) {
-          if (DEBUG) debug("Error! Address is invalid to send MMS: " +
-                           normalizedAddress);
+        let receiver = receivers[i];
+        let type = MMS.Address.resolveType(receiver);
+        let address;
+        if (type == "PLMN") {
+          address = PhoneNumberUtils.normalize(receiver, false);
+          if (!PhoneNumberUtils.isPlainPhoneNumber(address)) {
+            isAddrValid = false;
+          }
+          if (DEBUG) debug("createSavableFromParams: normalize phone number " +
+                           "from " + receiver + " to " + address);
+        } else {
+          address = receiver;
           isAddrValid = false;
+          if (DEBUG) debug("Error! Address is invalid to send MMS: " + address);
         }
+        headersTo.push({"address": address, "type": type});
       }
     }
     if (aParams.subject) {
       headers["subject"] = aParams.subject;
     }
 
     // |aMessage.parts|
     let attachments = aParams.attachments;