Skip to content

extract_msg.Message.export() fails to export updated attributes #388

Description

@jill-leflour-db

Hi,

Bug Metadata

  • Version of extract_msg: 0.45.0
  • Your python version: Python 3.9.12
  • How did you launch extract_msg?
    • I used the extract_msg package

Describe the bug
I am using extract_msg to open an Outlook email template, replace some values in the body of the email and export the updated email as a .msg file. I managed to update the body of the Message object and save it as a txt file using extract_msg.Message.save(). However, extract_msg.Message.export() always exports the original body instead of the updated one.

See the some sample code below to reproduce the error.

import extract_msg

REPLACEMENT_STRING="test"

f = "template.msg"
msg = extract_msg.Message(f)

msg.body = msg.body.replace("[STRING_TO_REPLACE]",REPLACEMENT_STRING)
print('Body: {}'.format(msg.body))  # [STRING_TO_REPLACE] has been replaced

msg.htmlBody = msg.htmlBody.replace(b"[STRING_TO_REPLACE]",bytes(REPLACEMENT_STRING, encoding='utf-8'))
print('HTML Body: {}'.format(msg.htmlBody))  # [STRING_TO_REPLACE] has been replaced

msg_name = "updated_" + f
msg.save()  # [STRING_TO_REPLACE] has been replaced in .txt file
msg.export(msg_name)  # [STRING_TO_REPLACE] is still in updated_template.msg
msg.close()

Github doesn't accept .msg files as attachments, but the "template.msg" in question is empty apart from the two following fields:
subject: Test subject
body: [STRING_TO_REPLACE]

Traceback
No error is printed out but the body of the exported "updated_template.msg" file is the same as "template.msg".

Am I doing it wrong or is this indeed not the expected behaviour?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a bugThe reported bug is not, in fact, a bug in the module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions