Skip to main content

Extract attachments from Outlook .msg files.

Project description

MIT License on PyPI Python 3.9+

python-oxmsg

Parse Outlook MSG (.msg) files to extract email messages and attachments.

The target use case is extracting Outlook message text and accessing attachments. There is no support for modifying messages or creating them from scratch. In addition to message text, other message properties such as sent-date, etc. are also accessible.

Documentation

Documentation for this project is on GitHub Pages.

Installation

pip install python-oxmsg

Occasionally it can be useful to install from a GitHub branch, perhaps to try out a version that has not yet been released. This command would install from the develop branch:

pip install git+https://github.com/scanny/python-oxmsg@develop

Usage

>>> from oxmsg import Message
>>> msg = Message.load("message.msg")
>>> msg.message_class
'IPM.Note'
>>> msg.attachment_count
1
>>> attachment = msg.attachments[0]
>>> attachment.attached_by_value  # -- attachment bytes only available when True --
True
>>> attachment.file_name
'q1-objectives.pptx'
>>> attachment.mime_type
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
>>> attachment.size
96407
>>> attachment.last_modified.isoformat()
'2023-11-18T16:08:17+00:00'
>>> with open(attachment.file_name, "wb") as f:
...     f.write(attachment.file_bytes)

CLI

python-oxmsg includes a CLI that may be useful for diagnostic purposes.

$ oxmsg
Usage: oxmsg [OPTIONS] COMMAND [ARGS]...

  Utility CLI for `python-oxmsg`.

  Provides the subcommands listed below, useful for exploratory or diagnostic
  purposes.

Options:
  --help  Show this message and exit.

Commands:
  dump     Write a summary of the MSG file's properties to stdout.
  storage  Summarize low-level "directories and files" structure of MSG...

The dump sub-command displays all properties available in the message along with the PID and PTYP information required to access those properties from a Properties object.

$ oxmsg dump message.msg

------------------
Message Properties
------------------

header-properties
-----------------
recipient_count:    1

distinguished-properties
------------------------
attachment_count:         0
internet_code_page:       utf-8
message_class:            IPM.Note
sender:                   from@domain.com
...

other properties
-----------------------------------------+---------------+--------------------
property-id                              | type          | value
-----------------------------------------+---------------+--------------------
0x0017 - PidTagImportance                | PtypInteger32 | 00 00 00 01
0x001A - PidTagMessageClass              | PtypString8   | 'IPM.Note'
0x0036 - PidTagSensitivity               | PtypInteger32 | 00 00 00 00
0x0037 - PidTagSubject                   | PtypString8   | 'A test message'
0x003B - PidTagSentRepresentingSearchKey | PtypBinary    | 21 bytes
0x003D - PidTagSubjectPrefix             | PtypString8   | ''
0x0042 - PidTagSentRepresentingName      | PtypString8   | 'from@domain.com'
...

Changelog

The release history including a chronicle of notable changes with each release is recorded in CHANGELOG.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_oxmsg-0.0.2.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_oxmsg-0.0.2-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file python_oxmsg-0.0.2.tar.gz.

File metadata

  • Download URL: python_oxmsg-0.0.2.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for python_oxmsg-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a6aff4deb1b5975d44d49dab1d9384089ffeec819e19c6940bc7ffbc84775fad
MD5 9c2430ab2b741509df9744fb9dcead62
BLAKE2b-256 a24e869f34faedbc968796d2c7e9837dede079c9cb9750917356b1f1eda926e9

See more details on using hashes here.

File details

Details for the file python_oxmsg-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: python_oxmsg-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for python_oxmsg-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 22be29b14c46016bcd05e34abddfd8e05ee82082f53b82753d115da3fc7d0355
MD5 9eaa925723c031c32123194c3fc00fd7
BLAKE2b-256 5367f56c69a98c7eb244025845506387d0f961681657c9fcd8b2d2edd148f9d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page