import method

Future<Message> import(
  1. Message request,
  2. String userId, {
  3. bool? deleted,
  4. String? internalDateSource,
  5. bool? neverMarkSpam,
  6. bool? processForCalendar,
  7. String? $fields,
  8. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  9. Media? uploadMedia,
})

Imports a message into only this user's mailbox, with standard email delivery scanning and classification similar to receiving via SMTP.

This method doesn't perform SPF checks, so it might not work for some spam messages, such as those attempting to perform domain spoofing. This method does not send a message.

request - The metadata request object.

Request parameters:

userId - The user's email address. The special value me can be used to indicate the authenticated user.

deleted - Mark the email as permanently deleted (not TRASH) and only visible in Google Vault to a Vault administrator. Only used for Google Workspace accounts.

internalDateSource - Source for Gmail's internal date of the message. Possible string values are:

  • "receivedTime" : Internal message date set to current time when received by Gmail.
  • "dateHeader" : Internal message time based on 'Date' header in email, when valid.

neverMarkSpam - Ignore the Gmail spam classifier decision and never mark this email as SPAM in the mailbox.

processForCalendar - Process calendar invites in the email and add any extracted meetings to the Google Calendar for this user.

$fields - Selector specifying which fields to include in a partial response.

uploadMedia - The media to upload.

uploadOptions - Options for the media upload. Streaming Media without the length being known ahead of time is only supported via resumable uploads.

Completes with a Message.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<Message> import(
  Message request,
  core.String userId, {
  core.bool? deleted,
  core.String? internalDateSource,
  core.bool? neverMarkSpam,
  core.bool? processForCalendar,
  core.String? $fields,
  commons.UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  commons.Media? uploadMedia,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (deleted != null) 'deleted': ['${deleted}'],
    if (internalDateSource != null)
      'internalDateSource': [internalDateSource],
    if (neverMarkSpam != null) 'neverMarkSpam': ['${neverMarkSpam}'],
    if (processForCalendar != null)
      'processForCalendar': ['${processForCalendar}'],
    if ($fields != null) 'fields': [$fields],
  };

  core.String url_;
  if (uploadMedia == null) {
    url_ = 'gmail/v1/users/' +
        commons.escapeVariable('$userId') +
        '/messages/import';
  } else if (uploadOptions is commons.ResumableUploadOptions) {
    url_ = '/resumable/upload/gmail/v1/users/' +
        commons.escapeVariable('$userId') +
        '/messages/import';
  } else {
    url_ = '/upload/gmail/v1/users/' +
        commons.escapeVariable('$userId') +
        '/messages/import';
  }

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
    uploadMedia: uploadMedia,
    uploadOptions: uploadOptions,
  );
  return Message.fromJson(response_ as core.Map<core.String, core.dynamic>);
}