B2G/gaia/apps/email/js/ext/mailapi/worker-bootstrap.js
/**
   * Add a message body to the system; you must provide the header associated
   * with the body.
   */
Add a message body to the system; you must provide the header associated
with the body.
Add a message body to the system ; you must provide the header associated with the body .
function ifs_addMessageBody(header, bodyInfo, callback) {
    if (this._pendingLoads.length) {
      this._deferredCalls.push(this.addMessageBody.bind(
                                 this, header, bodyInfo, callback));
      return;
    }
    this._LOG.addMessageBody(header.date, header.id, header.srvid);
    var sizeEst = OBJ_OVERHEAD_EST + NUM_ATTR_OVERHEAD_EST +
                    4 * NULL_ATTR_OVERHEAD_EST;
    function sizifyAddrs(addrs) {
      sizeEst += LIST_ATTR_OVERHEAD_EST;
      if (!addrs)
        return;
      for (var i = 0; i < addrs.length; i++) {
        var addrPair = addrs[i];
        sizeEst += OBJ_OVERHEAD_EST + 2 * STR_ATTR_OVERHEAD_EST +
                     (addrPair.name ? addrPair.name.length : 0) +
                     (addrPair.address ? addrPair.address.length : 0);
      }
    }
    function sizifyAttachments(atts) {
      sizeEst += LIST_ATTR_OVERHEAD_EST;
      if (!atts)
        return;
      for (var i = 0; i < atts.length; i++) {
        var att = atts[i];
        sizeEst += OBJ_OVERHEAD_EST + 2 * STR_ATTR_OVERHEAD_EST +
                     att.name.length + att.type.length +
                     NUM_ATTR_OVERHEAD_EST;
      }
    }
    function sizifyStr(str) {
      sizeEst += STR_ATTR_OVERHEAD_EST + str.length;
    }
    function sizifyStringList(strings) {
      sizeEst += LIST_OVERHEAD_EST;
      if (!strings)
        return;
      for (var i = 0; i < strings.length; i++) {
        sizeEst += STR_ATTR_OVERHEAD_EST + strings[i].length;
      }
    }
    function sizifyBodyRep(rep) {
      sizeEst += LIST_OVERHEAD_EST +
                   NUM_OVERHEAD_EST * (rep.length / 2) +
                   STR_OVERHEAD_EST * (rep.length / 2);
      for (var i = 1; i < rep.length; i += 2) {
        if (rep[i])
          sizeEst += rep[i].length;
      }
    };
    function sizifyBodyReps(reps) {
      if (!reps)
        return;
      sizeEst += STR_OVERHEAD_EST * (reps.length / 2);
      for (var i = 0; i < reps.length; i++) {
        var rep = reps[i];
        if (rep.type === 'html') {
          sizeEst += STR_OVERHEAD_EST + rep.amountDownloaded;
        } else {
          rep.content && sizifyBodyRep(rep.content);
        }
      }
    };
    if (bodyInfo.to)
      sizifyAddrs(bodyInfo.to);
    if (bodyInfo.cc)
      sizifyAddrs(bodyInfo.cc);
    if (bodyInfo.bcc)
      sizifyAddrs(bodyInfo.bcc);
    if (bodyInfo.replyTo)
      sizifyStr(bodyInfo.replyTo);
    sizifyAttachments(bodyInfo.attachments);
    sizifyAttachments(bodyInfo.relatedParts);
    sizifyStringList(bodyInfo.references);
    sizifyBodyReps(bodyInfo.bodyReps);
    bodyInfo.size = sizeEst;
    this._insertIntoBlockUsingDateAndUID(
      'body', header.date, header.id, header.srvid, bodyInfo.size, bodyInfo,
      callback);
  }
function ifs_addMessageBody ( header , bodyInfo , callback ) { if ( this . _pendingLoads . length ) { this . _deferredCalls . push ( this . addMessageBody . bind ( this , header , bodyInfo , callback ) ) ; return ; } this . _LOG . addMessageBody ( header . date , header . id , header . srvid ) ; var sizeEst = OBJ_OVERHEAD_EST + NUM_ATTR_OVERHEAD_EST + 4 * NULL_ATTR_OVERHEAD_EST ; function sizifyAddrs ( addrs ) { sizeEst += LIST_ATTR_OVERHEAD_EST ; if ( ! addrs ) return ; for ( var i = 0 ; i < addrs . length ; i ++ ) { var addrPair = addrs [ i ] ; sizeEst += OBJ_OVERHEAD_EST + 2 * STR_ATTR_OVERHEAD_EST + ( addrPair . name ? addrPair . name . length : 0 ) + ( addrPair . address ? addrPair . address . length : 0 ) ; } } function sizifyAttachments ( atts ) { sizeEst += LIST_ATTR_OVERHEAD_EST ; if ( ! atts ) return ; for ( var i = 0 ; i < atts . length ; i ++ ) { var att = atts [ i ] ; sizeEst += OBJ_OVERHEAD_EST + 2 * STR_ATTR_OVERHEAD_EST + att . name . length + att . type . length + NUM_ATTR_OVERHEAD_EST ; } } function sizifyStr ( str ) { sizeEst += STR_ATTR_OVERHEAD_EST + str . length ; } function sizifyStringList ( strings ) { sizeEst += LIST_OVERHEAD_EST ; if ( ! strings ) return ; for ( var i = 0 ; i < strings . length ; i ++ ) { sizeEst += STR_ATTR_OVERHEAD_EST + strings [ i ] . length ; } } function sizifyBodyRep ( rep ) { sizeEst += LIST_OVERHEAD_EST + NUM_OVERHEAD_EST * ( rep . length / 2 ) + STR_OVERHEAD_EST * ( rep . length / 2 ) ; for ( var i = 1 ; i < rep . length ; i += 2 ) { if ( rep [ i ] ) sizeEst += rep [ i ] . length ; } } ; function sizifyBodyReps ( reps ) { if ( ! reps ) return ; sizeEst += STR_OVERHEAD_EST * ( reps . length / 2 ) ; for ( var i = 0 ; i < reps . length ; i ++ ) { var rep = reps [ i ] ; if ( rep . type === 'html' ) { sizeEst += STR_OVERHEAD_EST + rep . amountDownloaded ; } else { rep . content && sizifyBodyRep ( rep . content ) ; } } } ; if ( bodyInfo . to ) sizifyAddrs ( bodyInfo . to ) ; if ( bodyInfo . cc ) sizifyAddrs ( bodyInfo . cc ) ; if ( bodyInfo . bcc ) sizifyAddrs ( bodyInfo . bcc ) ; if ( bodyInfo . replyTo ) sizifyStr ( bodyInfo . replyTo ) ; sizifyAttachments ( bodyInfo . attachments ) ; sizifyAttachments ( bodyInfo . relatedParts ) ; sizifyStringList ( bodyInfo . references ) ; sizifyBodyReps ( bodyInfo . bodyReps ) ; bodyInfo . size = sizeEst ; this . _insertIntoBlockUsingDateAndUID ( 'body' , header . date , header . id , header . srvid , bodyInfo . size , bodyInfo , callback ) ; }
Add a message body to the system; you must provide the header associated
 with the body.
Add a message body to the system ; you must provide the header associated with the body .
// crappy size estimates where we assume the world is ASCII and so a UTF-8 // encoding will take exactly 1 byte per character.