python - 从 .PST 文件中提取文本
问题描述
我正在尝试提取.pst
文件的内容(作为字符串/文本)。
我尝试了不同的答案,但没有找到任何相关的解决方案。
使用 pypff / libpff 导出 PST 和 OST
我主要关注库libpff ( https://github.com/libyal/libpff ),但我认为该库对提取 pst 的文本没有帮助。
我的代码:
import pypff
pst = pypff.file()
pst.open("my_pst_file.pst")
该代码打开 pst,但我看不到如何将其内容提取为 txt。
解决方案
是的,您可以使用它pypff
来提取文本。我也关注了这个链接(使用 pypff / libpff 导出 PST 和 OST)。
这pypff.file()
可能会令人困惑,因为开发人员没有为指令提供每个函数和属性的体面文档。我花了一段时间自己探索它。
这是我最近做的。
# path to your pst file
opst = pypff.open(path)
root = opst.get_root_folder()
# 3 subfolders, for me, only 2nd one has content
# Use 'root.get_number_of_sub_folders()' to see which folder is blank
folder = root.get_sub_folder(1)
# 2 subfolders, the 2nd one is my inbox
inbox = folder.get_sub_folder(1)
# mail count in current folder
count = inbox.get_number_of_sub_items()
# Example of extracting info from one email
msg = inbox.get_sub_item(0)
subject = msg.subject
content = msg.plain_text_body.decode()
sender = msg.sender_name
header = msg.transport_headers
sent_time = msg.delivery_time
if msg.number_of_attachments > 0:
# read from attachment 1
size = attachment = msg.get_attachment(0).get_size()
attachment_content = (msg.get_attachment(0).read_buffer(attach_size)).decode('ascii', errors='ignore')
对于那些想使用的人pypff
,不要使用 pip install。它仅从版本 20161119 构建,这对我来说崩溃了很多。
从他们网站上的较新版本构建。有一个setup.py
,它应该很容易构建。
对于附件,ascii
解码器并不理想。我试过python3中的所有98个解码器,没有一个可以解码每个字节。这意味着,单一方法无法全部解码。就我而言,utf_16
可以提取内容,这对我来说已经足够了。
推荐阅读
- python - 等待实际结果加载到 Requests 和 Beautiful Soup - Python
- c# - C# .net http | 如何从 API 中获取对象层
- reactjs - Cropperjs 库上的打字稿导入问题
- c++ - c++ 指针向量到指针向量
- terraform - 如何在 terraform 中断开远程执行?
- arduino - 使用 Mozzi 库在 Arduino IDE 中编译错误
- php - Laravel CustomRequest 授权,传递请求数据以验证 auth 用户 customer id 和 model id 匹配
- sql - 将磅和盎司转换为克 - SQL Server
- java - Spring Boot JOOQ 集成 - 编译问题
- java - Cannot get the max value in a SQLite database