跳转到主要内容

从Outlook .msg文件中提取附件。

项目描述

MIT License on PyPI Python 3.9+

python-oxmsg

解析Outlook MSG (.msg)文件以提取电子邮件消息和附件。

目标使用案例是提取Outlook消息文本和访问附件。不支持修改消息或从头创建它们。除了消息文本外,其他消息属性(如发送日期等)也可以访问。

文档

此项目的文档位于 GitHub Pages

安装

pip install python-oxmsg

有时从GitHub分支安装可能很有用,也许是为了尝试尚未发布的版本。此命令将从 develop 分支安装

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

用法

>>> 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.filename
'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.filename, "wb") as f:
...     f.write(attachment.file_bytes)

CLI

python-oxmsg 包含一个CLI,可能对诊断目的有用。

$ 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...

dump 子命令显示消息中所有可用的属性,以及从 Properties 对象访问这些属性所需的PID和PTYP信息。

$ 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.md 中。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

python_oxmsg-0.0.1.tar.gz (34.5 kB 查看哈希)

上传时间 源代码

构建分发

python_oxmsg-0.0.1-py3-none-any.whl (31.4 kB 查看哈希)

上传时间 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面