processApiRequest = function(port, request) {
    var args = request.args;
    switch (request.call) {
      case 'ready':
        break; // Ignore. Gmonkey does not initiate requests.
      case 'getCurrentMessage':
        var result = null;
        var message = gmonkeyApi.getCurrentMessage();
        if (message) {
          var escapedId = message.getContentElement().id
              .replace(/(\\|")/g, '\\$1');
          result = {
            'selector': '[id="' + escapedId + '"]',
            'body': message.getPlainTextContent()
          };
        }
        sendResult(port, request, result);
        break;
      case 'getActiveDraft':
        getDraft(function(draft) {
          var result = {
            'to': draft.getToEmails(),
            'cc': draft.getCcEmails(),
            'body': draft.getPlainTextBody()
          };
          if (gmonkeyApi.SUBJECTS_ENABLED_FOR_TESTS_ONLY) {
            result.subject = draft.getSubject();
          }
          sendResult(port, request, result);
        });
        break;
      case 'hasActiveDraft':
        sendResult(port, request, hasDraft());
        break;
      case 'setActiveDraft':
        getDraft(function(draft) {
          if (args['to']) {
            draft.setToEmails(args['to']);
          }

          if ('body' in args) {
            draft.setBody(args['body']);
          }

          if (gmonkeyApi.SUBJECTS_ENABLED_FOR_TESTS_ONLY &&
              ('subject' in args)) {
            draft.setSubject(args['subject']);
          }

          if (args['send']) {
            draft.send();
          }

          sendResult(port, request, true);
        });
        break;
      default:
        sendError(port, request, 'Unsupported API call.');
    }
  }
Processes request to E2E Website API.
@param  {MessagePort} port port to send the response to
@param  {{id:string,call:string,args}} request incoming request