B2G/gecko/dom/mobilemessage/src/ril/MmsService.js
/**
   * A utility function to convert the MmsParameters dictionary object
   * to a database-savable message.
   *
   * @param aParams
   *        The MmsParameters dictionay object.
   * @param aMessage (output)
   *        The database-savable message.
   * Return the error code by veryfying if the |aParams| is valid or not.
   *
   * Notes:
   *
   * OMA-TS-MMS-CONF-V1_3-20110913-A section 10.2.2 "Message Content Encoding":
   *
   * A name for multipart object SHALL be encoded using name-parameter for Content-Type
   * header in WSP multipart headers. In decoding, name-parameter of Content-Type SHALL
   * be used if available. If name-parameter of Content-Type is not available, filename
   * parameter of Content-Disposition header SHALL be used if available. If neither
   * name-parameter of Content-Type header nor filename parameter of Content-Disposition
   * header is available, Content-Location header SHALL be used if available.
   */
A utility function to convert the MmsParameters dictionary object
to a database-savable message.

@param aParams
The MmsParameters dictionay object.
@param aMessage (output)
The database-savable message.
Return the error code by veryfying if the |aParams| is valid or not.





A name for multipart object SHALL be encoded using name-parameter for Content-Type
header in WSP multipart headers. In decoding, name-parameter of Content-Type SHALL
be used if available. If name-parameter of Content-Type is not available, filename
parameter of Content-Disposition header SHALL be used if available. If neither
name-parameter of Content-Type header nor filename parameter of Content-Disposition
header is available, Content-Location header SHALL be used if available.
A utility function to convert the MmsParameters dictionary object to a database - savable message . @param aParams The MmsParameters dictionay object . @param aMessage ( output ) The database - savable message . Return the error code by veryfying if the |aParams| is valid or not . A name for multipart object SHALL be encoded using name - parameter for Content - Type header in WSP multipart headers . In decoding name - parameter of Content - Type SHALL be used if available . If name - parameter of Content - Type is not available filename parameter of Content - Disposition header SHALL be used if available . If neither name - parameter of Content - Type header nor filename parameter of Content - Disposition header is available Content - Location header SHALL be used if available .
function createSavableFromParams(aParams, aMessage) {
    if (DEBUG) debug("createSavableFromParams: aParams: " + JSON.stringify(aParams));
    let isAddrValid = true;
    let smil = aParams.smil;
    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"});
        if (!PhoneNumberUtils.isPlainPhoneNumber(normalizedAddress)) {
          if (DEBUG) debug("Error! Address is invalid to send MMS: " +
                           normalizedAddress);
          isAddrValid = false;
        }
      }
    }
    if (aParams.subject) {
      headers["subject"] = aParams.subject;
    }
    let attachments = aParams.attachments;
    if (attachments.length != 0 || smil) {
      let parts = aMessage["parts"] = [];
      if (smil) {
        let part = {
          "headers": {
            "content-type": {
              "media": "application/smil",
              "params": {
                "name": "smil.xml",
                "charset": {
                  "charset": "utf-8"
                }
              }
            },
            "content-location": "smil.xml",
            "content-id": "<smil>"
          },
          "content": smil
        };
        parts.push(part);
      }
      for (let i = 0; i < attachments.length; i++) {
        let attachment = attachments[i];
        let content = attachment.content;
        let location = attachment.location;
        let params = {
          "name": location
        };
        if (content.type && content.type.indexOf("text/") == 0) {
          params.charset = {
            "charset": "utf-8"
          };
        }
        let part = {
          "headers": {
            "content-type": {
              "media": content.type,
              "params": params
            },
            "content-location": location,
            "content-id": attachment.id
          },
          "content": content
        };
        parts.push(part);
      }
    }
    aMessage["type"] = "mms";
    aMessage["deliveryStatusRequested"] = true;
    aMessage["timestamp"] = Date.now();
    aMessage["receivers"] = receivers;
    if (DEBUG) debug("createSavableFromParams: aMessage: " +
                     JSON.stringify(aMessage));
    return isAddrValid ? Ci.nsIMobileMessageCallback.SUCCESS_NO_ERROR
                       : Ci.nsIMobileMessageCallback.INVALID_ADDRESS_ERROR;
  }
function createSavableFromParams ( aParams , aMessage ) { if ( DEBUG ) debug ( "createSavableFromParams: aParams: " + JSON . stringify ( aParams ) ) ; let isAddrValid = true ; let smil = aParams . smil ; 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" } ) ; if ( ! PhoneNumberUtils . isPlainPhoneNumber ( normalizedAddress ) ) { if ( DEBUG ) debug ( "Error! Address is invalid to send MMS: " + normalizedAddress ) ; isAddrValid = false ; } } } if ( aParams . subject ) { headers [ "subject" ] = aParams . subject ; } let attachments = aParams . attachments ; if ( attachments . length != 0 || smil ) { let parts = aMessage [ "parts" ] = [ ] ; if ( smil ) { let part = { "headers" : { "content-type" : { "media" : "application/smil" , "params" : { "name" : "smil.xml" , "charset" : { "charset" : "utf-8" } } } , "content-location" : "smil.xml" , "content-id" : "<smil>" } , "content" : smil } ; parts . push ( part ) ; } for ( let i = 0 ; i < attachments . length ; i ++ ) { let attachment = attachments [ i ] ; let content = attachment . content ; let location = attachment . location ; let params = { "name" : location } ; if ( content . type && content . type . indexOf ( "text/" ) == 0 ) { params . charset = { "charset" : "utf-8" } ; } let part = { "headers" : { "content-type" : { "media" : content . type , "params" : params } , "content-location" : location , "content-id" : attachment . id } , "content" : content } ; parts . push ( part ) ; } } aMessage [ "type" ] = "mms" ; aMessage [ "deliveryStatusRequested" ] = true ; aMessage [ "timestamp" ] = Date . now ( ) ; aMessage [ "receivers" ] = receivers ; if ( DEBUG ) debug ( "createSavableFromParams: aMessage: " + JSON . stringify ( aMessage ) ) ; return isAddrValid ? Ci . nsIMobileMessageCallback . SUCCESS_NO_ERROR : Ci . nsIMobileMessageCallback . INVALID_ADDRESS_ERROR ; }
A utility function to convert the MmsParameters dictionary object
 to a database-savable message.
A utility function to convert the MmsParameters dictionary object to a database - savable message .
// |aMessage.headers| // Check if the address is valid to send MMS. // |aMessage.parts| // Set the SMIL part if needed. // Set other parts for attachments if needed. // The following attributes are needed for saving message into DB.