B2G/gaia/apps/email/js/ext/mailapi/fake/configurator.js
/**
   * Given a set definition, produce a list of synthetic messages.
   *
   * The set definition supports the following attributes:
   *  count: The number of messages to create.
   *  age: As used by makeMessage.
   *  age_incr: Similar to age, but used to increment the values in the age
   *      dictionary (assuming a value of zero if omitted).
   *  age_incr_every: How often to apply age_incr.  If omitted, treated like 1
   *      is specified.  Use this to cluster messages during the middle of the
   *      day so you aren't betrayed by timezone issues.
   *  @param [aSetDef.msgsPerThread=1] The number of messages per thread.  If
   *      you want to create direct-reply threads, you can pass a value for this
   *      and have it not be one.  If you need fancier reply situations,
   *      directly use a scenario or hook us up to support that.
   *
   * Also supported are the following attributes as defined by makeMessage:
   *  attachments, body, from, inReplyTo, subject, to, clobberHeaders, junk
   *
   * If omitted, the following defaults are used, but don't depend on this as we
   *  can change these at any time:
   * - count: 10
   */
Given a set definition, produce a list of synthetic messages.
The set definition supports the following attributes:
count: The number of messages to create.
age: As used by makeMessage.
age_incr: Similar to age, but used to increment the values in the age
dictionary (assuming a value of zero if omitted).

Also supported are the following attributes as defined by makeMessage:
attachments, body, from, inReplyTo, subject, to, clobberHeaders, junk

If omitted, the following defaults are used, but don't depend on this as we
can change these at any time:
- count: 10
Given a set definition produce a list of synthetic messages . The set definition supports the following attributes : count : The number of messages to create . age : As used by makeMessage . age_incr : Similar to age but used to increment the values in the age dictionary ( assuming a value of zero if omitted ) . Also supported are the following attributes as defined by makeMessage : attachments body from inReplyTo subject to clobberHeaders junk If omitted the following defaults are used but don ' t depend on this as we can change these at any time : - count : 10
function MessageGenerator_makeMessages(aSetDef) {
    var messages = [];
    var args = {
      age_incr_every: 1,
    }, unit, delta;
    if (aSetDef.age_incr) {
      args.age = { seconds: 0 };
      for (unit in aSetDef.age_incr) {
        args.age[unit] = 0;
      }
    }
    if (aSetDef.age) {
      args.age = args.age || {};
      for (unit in aSetDef.age) {
        var value = aSetDef.age[unit];
        args.age[unit] = value;
      }
    }
    for (var iPropName = 0;
         iPropName < this.MAKE_MESSAGES_PROPAGATE.length;
         iPropName++) {
      var propAttrName = this.MAKE_MESSAGES_PROPAGATE[iPropName];
      if (aSetDef[propAttrName])
        args[propAttrName] = aSetDef[propAttrName];
    }
    var count = aSetDef.hasOwnProperty('count') ? aSetDef.count :
                this.MAKE_MESSAGES_DEFAULTS.count;
    var messagesPerThread = aSetDef.msgsPerThread || 1;
    var rawBodies = aSetDef.hasOwnProperty('rawBodies') ? aSetDef.rawBodies
                                                        : null,
        replaceHeaders = aSetDef.hasOwnProperty('replaceHeaders') ?
                           aSetDef.replaceHeaders : null;
    var lastMessage = null;
    for (var iMsg = 0; iMsg < count; iMsg++) {
      if (lastMessage && (iMsg % messagesPerThread != 0))
        args.inReplyTo = lastMessage;
      else if (!("inReplyTo" in aSetDef))
        args.inReplyTo = null;
      if (rawBodies)
        args.rawBody = rawBodies[iMsg];
      if (replaceHeaders)
        args.replaceHeaders = replaceHeaders[iMsg];
      lastMessage = this.makeMessage(args);
      if (this._mode === 'info') {
        lastMessage.headerInfo.id = '' + iMsg;
        lastMessage.headerInfo.suid = aSetDef.folderId + '/' + iMsg;
      }
      messages.push(lastMessage);
      if (aSetDef.age_incr) {
        if (!aSetDef.age_incr_every ||
            (messages.length % aSetDef.age_incr_every === 0)) {
          args.age.seconds = 0;
          for (unit in aSetDef.age_incr) {
            delta = aSetDef.age_incr[unit];
            args.age[unit] += delta;
          }
        }
        else {
          args.age.seconds++;
        }
      }
    }
    return messages;
  }
function MessageGenerator_makeMessages ( aSetDef ) { var messages = [ ] ; var args = { age_incr_every : 1 , } , unit , delta ; if ( aSetDef . age_incr ) { args . age = { seconds : 0 } ; for ( unit in aSetDef . age_incr ) { args . age [ unit ] = 0 ; } } if ( aSetDef . age ) { args . age = args . age || { } ; for ( unit in aSetDef . age ) { var value = aSetDef . age [ unit ] ; args . age [ unit ] = value ; } } for ( var iPropName = 0 ; iPropName < this . MAKE_MESSAGES_PROPAGATE . length ; iPropName ++ ) { var propAttrName = this . MAKE_MESSAGES_PROPAGATE [ iPropName ] ; if ( aSetDef [ propAttrName ] ) args [ propAttrName ] = aSetDef [ propAttrName ] ; } var count = aSetDef . hasOwnProperty ( 'count' ) ? aSetDef . count : this . MAKE_MESSAGES_DEFAULTS . count ; var messagesPerThread = aSetDef . msgsPerThread || 1 ; var rawBodies = aSetDef . hasOwnProperty ( 'rawBodies' ) ? aSetDef . rawBodies : null , replaceHeaders = aSetDef . hasOwnProperty ( 'replaceHeaders' ) ? aSetDef . replaceHeaders : null ; var lastMessage = null ; for ( var iMsg = 0 ; iMsg < count ; iMsg ++ ) { if ( lastMessage && ( iMsg % messagesPerThread != 0 ) ) args . inReplyTo = lastMessage ; else if ( ! ( "inReplyTo" in aSetDef ) ) args . inReplyTo = null ; if ( rawBodies ) args . rawBody = rawBodies [ iMsg ] ; if ( replaceHeaders ) args . replaceHeaders = replaceHeaders [ iMsg ] ; lastMessage = this . makeMessage ( args ) ; if ( this . _mode === 'info' ) { lastMessage . headerInfo . id = '' + iMsg ; lastMessage . headerInfo . suid = aSetDef . folderId + '/' + iMsg ; } messages . push ( lastMessage ) ; if ( aSetDef . age_incr ) { if ( ! aSetDef . age_incr_every || ( messages . length % aSetDef . age_incr_every === 0 ) ) { args . age . seconds = 0 ; for ( unit in aSetDef . age_incr ) { delta = aSetDef . age_incr [ unit ] ; args . age [ unit ] += delta ; } } else { args . age . seconds ++ ; } } } return messages ; }
Given a set definition, produce a list of synthetic messages.
Given a set definition produce a list of synthetic messages .
// zero out all the age_incr fields in age (if present) // copy over the initial values from age (if present) // just copy over any attributes found from MAKE_MESSAGES_PROPAGATE // primitive threading support...