从Outlook .msg文件中提取附件。
项目描述
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_oxmsg-0.0.1.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b65c1f93d688b85a9410afa824192a1ddc39da359b04a0bd2cbd3874e84d4994 |
|
MD5 | 89cb43237cb032b636906af08cbdbd1b |
|
BLAKE2b-256 | 4fd44ec721fd433453fe05344f41f17458775d111e9f6c668ce1a0fccec0fecd |
关闭
python_oxmsg-0.0.1-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8ea7d5dda1bc161a413213da9e18ed152927c1fda2feaf5d1f02192d8ad45eea |
|
MD5 | d425c88a20c742a2e196c9dfcf925a9b |
|
BLAKE2b-256 | d4c8fb23e1e7723ba9200b75bc121f22f67498ae098a202f1646acc4f6a54f5c |