def write_html(output_dir: str, transaction_id: str, part: MIMEPart) -> None: """Write the HTML part of an email to disk. Args: output_dir (str): The directory to write the file to. transaction_id (str): The transaction ID of the email. part (MIMEPart): The MIME part representing the attachment. """ filename = f"{transaction_id}_html.html" logging.info(f" Writing email body '{filename}'") with open(join(output_dir, filename), "w") as body_file: # the replace is due to weird formatting of HTML in MIME body_file.write(part.get_payload().replace("=\n", ""))
def write_attachment(output_dir: str, transaction_id: str, part: MIMEPart) -> None: """Write an attachment file to disk. Args: output_dir (str): The directory to write the file to. transaction_id (str): The transaction ID of the email. part (MIMEPart): The MIME part representing the attachment. """ filename = f"{transaction_id}_{part.get_filename()}" logging.info(f" Writing attachment '{filename}'") with open(join(output_dir, filename), "wb") as attachment_file: decoded = base64.b64decode(part.get_payload()) attachment_file.write(decoded)