是的,您可以使用pypff 提取文本。我也关注了这个链接(Export PST and OST with pypff / libpff)。
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 构建,这对我来说崩溃了很多。
在他们的website 上从较新版本构建。有一个setup.py,应该很容易构建。
对于附件,ascii 解码器并不理想。我在 python3 中尝试过all 98 decoders,但没有一个可以解码每个字节。这意味着,单个方法不能解码所有。在我的情况下,utf_16 可以提取内容,这对我来说已经足够了。