Exemple #1
0
    def ToProto(self):
        """Convert mail message to protocol message.

    Unicode strings are converted to UTF-8 for all fields.

    This method is overriden by EmailMessage to support the sender fields.

    Returns:
      MailMessage protocol version of mail message.
    """
        self.check_initialized()
        message = mail_service_pb.MailMessage()
        message.set_sender(_to_str(self.sender))

        if hasattr(self, 'reply_to'):
            message.set_replyto(_to_str(self.reply_to))
        message.set_subject(_to_str(self.subject))
        if hasattr(self, 'body'):
            message.set_textbody(_to_str(self.body))
        if hasattr(self, 'html'):
            message.set_htmlbody(_to_str(self.html))

        if hasattr(self, 'attachments'):
            for file_name, data in _attachment_sequence(self.attachments):
                attachment = message.add_attachment()
                attachment.set_filename(_to_str(file_name))
                attachment.set_data(_to_str(data))
        return message
Exemple #2
0
    def ToProto(self):
        """Converts an email message to a protocol message.

    Unicode strings are converted to UTF-8 for all fields.

    This method is overriden by `EmailMessage` to support the sender field.

    Returns:
      The `MailMessage` protocol version of the mail message.

    Raises:
      Decoding errors when using `EncodedPayload` objects.
    """
        self.check_initialized()
        message = mail_service_pb.MailMessage()
        message.set_sender(_to_str(self.sender))

        if hasattr(self, 'reply_to'):
            message.set_replyto(_to_str(self.reply_to))
        if hasattr(self, 'subject'):
            message.set_subject(_to_str(self.subject))
        else:
            message.set_subject('')

        if hasattr(self, 'body'):
            body = self.body
            if isinstance(body, EncodedPayload):
                body = body.decode()
            message.set_textbody(_to_str(body))

        if hasattr(self, 'html'):
            html = self.html
            if isinstance(html, EncodedPayload):
                html = html.decode()
            message.set_htmlbody(_to_str(html))

        if hasattr(self, 'amp_html'):
            amp_html = self.amp_html
            if isinstance(amp_html, EncodedPayload):
                amp_html = amp_html.decode()
            message.set_amphtmlbody(_to_str(amp_html))

        if hasattr(self, 'attachments'):
            for attachment in _attachment_sequence(self.attachments):
                if isinstance(attachment.payload, EncodedPayload):
                    attachment.payload = attachment.payload.decode()
                protoattachment = message.add_attachment()
                protoattachment.set_filename(_to_str(attachment.filename))
                protoattachment.set_data(_to_str(attachment.payload))
                if attachment.content_id:
                    protoattachment.set_contentid(attachment.content_id)
        return message
Exemple #3
0
    def ToProto(self):
        """Convert mail message to protocol message.

    Unicode strings are converted to UTF-8 for all fields.

    This method is overriden by EmailMessage to support the sender fields.

    Returns:
      MailMessage protocol version of mail message.

    Raises:
      Passes through decoding errors that occur when using when decoding
      EncodedPayload objects.
    """
        self.check_initialized()
        message = mail_service_pb.MailMessage()
        message.set_sender(_to_str(self.sender))

        if hasattr(self, 'reply_to'):
            message.set_replyto(_to_str(self.reply_to))
        if hasattr(self, 'subject'):
            message.set_subject(_to_str(self.subject))
        else:
            message.set_subject('')

        if hasattr(self, 'body'):
            body = self.body
            if isinstance(body, EncodedPayload):
                body = body.decode()
            message.set_textbody(_to_str(body))

        if hasattr(self, 'html'):
            html = self.html
            if isinstance(html, EncodedPayload):
                html = html.decode()
            message.set_htmlbody(_to_str(html))

        if hasattr(self, 'attachments'):
            for file_name, data in _attachment_sequence(self.attachments):
                if isinstance(data, EncodedPayload):
                    data = data.decode()
                attachment = message.add_attachment()
                attachment.set_filename(_to_str(file_name))
                attachment.set_data(_to_str(data))
        return message
    def ToProto(self):
        self.check_initialized()
        message = mail_service_pb.MailMessage()
        message.set_sender(self.sender)

        if hasattr(self, 'reply_to'):
            message.set_replyto(self.reply_to)
        message.set_subject(self.subject)
        if hasattr(self, 'body'):
            message.set_textbody(self.body)
        if hasattr(self, 'html'):
            message.set_htmlbody(self.html)

        if hasattr(self, 'attachments'):
            for file_name, data in _attachment_sequence(self.attachments):
                attachment = message.add_attachment()
                attachment.set_filename(file_name)
                attachment.set_data(data)
        return message