Esempio n. 1
0
  def ImportMail(self, user_name, mail_message, mail_item_properties,
                 mail_labels):
    """Import a single mail message.

    Args:
      user_name: The username to import messages to.
      mail_message: An RFC822 format email message.
      mail_item_properties: A list of Gmail properties to apply to the message.
      mail_labels: A list of labels to apply to the message.

    Returns:
      A MailEntry representing the successfully imported message.

    Raises:
      AppsForYourDomainException: An error occurred importing the message.
    """
    uri = '%s/%s/mail' % (self._BaseURL(), user_name)

    mail_entry = migration.MailEntry()
    mail_entry.rfc822_msg = migration.Rfc822Msg(text=(base64.b64encode(
        mail_message)))
    mail_entry.rfc822_msg.encoding = 'base64'
    mail_entry.mail_item_property = map(
        lambda x: migration.MailItemProperty(value=x), mail_item_properties)
    mail_entry.label = map(lambda x: migration.Label(label_name=x),
                           mail_labels)

    try:
      return migration.MailEntryFromString(str(self.Post(mail_entry, uri)))
    except gdata.service.RequestError, e:
      raise gdata.apps.service.AppsForYourDomainException(e.args[0])
Esempio n. 2
0
        Args:
          user_name: The username to import messages to.
          mail_message: An RFC822 format email message.
          mail_item_properties: A list of Gmail properties to apply to the message.
          mail_labels: A list of labels to apply to the message.

        Returns:
          A MailEntry representing the successfully imported message.

        Raises:
          AppsForYourDomainException: An error occurred importing the message.
        """
        uri = '%s/%s/mail' % (self._BaseURL(), user_name)

        mail_entry = migration.MailEntry()
        mail_entry.rfc822_msg = migration.Rfc822Msg(text=(base64.b64encode(
            mail_message)))
        mail_entry.rfc822_msg.encoding = 'base64'
        mail_entry.mail_item_property = [migration.MailItemProperty(value=x) for x in mail_item_properties]
        mail_entry.label = [migration.Label(label_name=x) for x in mail_labels]

        try:
            return migration.MailEntryFromString(str(self.Post(mail_entry, uri)))
        except gdata.service.RequestError as e:
            # Store the number of failed imports when importing several at a time
            self.exceptions += 1
            raise gdata.apps.service.AppsForYourDomainException(e.args[0])

    def AddBatchEntry(self, mail_message, mail_item_properties,
                      mail_labels):