def _build_message(self, message):
if not message.recipients():<EOL><INDENT>return False<EOL><DEDENT>recipients = '<STR_LIT:U+002C>'.join(message.to)<EOL>recipients_cc = '<STR_LIT:U+002C>'.join(message.cc)<EOL>recipients_bcc = '<STR_LIT:U+002C>'.join(message.bcc)<EOL>text_body = message.body<EOL>html_body = None<EOL>if isinstance(message, EmailMultiAlternatives):<EOL><INDENT>for alt in message.alternatives:<EOL><INDENT>if alt[<NUM_LIT:1>] == "<STR_LIT>":<EOL><INDENT>html_body = alt[<NUM_LIT:0>]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>elif getattr(message, '<STR_LIT>', None) == '<STR_LIT:html>':<EOL><INDENT>text_body = None<EOL>html_body = message.body<EOL><DEDENT>reply_to = '<STR_LIT:U+002C>'.join(message.reply_to)<EOL>custom_headers = {}<EOL>if message.extra_headers and isinstance(message.extra_headers, dict):<EOL><INDENT>if '<STR_LIT>' in message.extra_headers:<EOL><INDENT>reply_to = message.extra_headers.pop('<STR_LIT>')<EOL><DEDENT>if len(message.extra_headers):<EOL><INDENT>custom_headers = message.extra_headers<EOL><DEDENT><DEDENT>attachments = []<EOL>if message.attachments and isinstance(message.attachments, list):<EOL><INDENT>if len(message.attachments):<EOL><INDENT>for item in message.attachments:<EOL><INDENT>if isinstance(item, tuple):<EOL><INDENT>(f, content, m) = item<EOL>content = base64.b64encode(content)<EOL>if not isinstance(content, str):<EOL><INDENT>content = content.decode()<EOL><DEDENT>attachments.append((f, content, m))<EOL><DEDENT>else:<EOL><INDENT>attachments.append(item)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>postmark_message = PMMail(api_key=self.api_key,<EOL>subject=message.subject,<EOL>sender=message.from_email,<EOL>to=recipients,<EOL>cc=recipients_cc,<EOL>bcc=recipients_bcc,<EOL>text_body=text_body,<EOL>html_body=html_body,<EOL>reply_to=reply_to,<EOL>custom_headers=custom_headers,<EOL>attachments=attachments)<EOL>postmark_message.tag = getattr(message, '<STR_LIT>', None)<EOL>postmark_message.track_opens = getattr(message, '<STR_LIT>', False)<EOL>return postmark_message<EOL>
A helper method to convert a PMEmailMessage to a PMMail