Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

python 3.x - Export PST and OST with pypff / libpff

I need to do in python a module to export PST and OST files and I am trying to use pypff to do so. Can someone give me some tips how can I use pypff to extract messages and attachments.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To read messages in pst or ost files, in python, refer to the following functions in https://github.com/PacktPublishing/Learning-Python-for-Forensics/blob/master/Chapter%2010/pst_indexer.py

folderTraverse(base)
checkForMessages(folder)
processMessage(message)

To read the attachments also, you could modify processMessage(message)

def processMessage(message, folder):
    attachments = []
    total_attachment_size_bytes = 0
    if message.number_of_attachments > 0:
        for i in range(message.number_of_attachments):
            total_attachment_size_bytes = total_attachment_size_bytes + (message.get_attachment(i)).get_size()
            # get the content of the attachment file
            attachments.append(((message.get_attachment(i)).read_buffer((message.get_attachment(i)).get_size())).decode('ascii', errors="ignore"))
    return {
        "subject": message.subject,
        "sender": message.sender_name,
        "header": message.transport_headers,
        "body": message.plain_text_body,
        "creation_time": message.creation_time,
        "submit_time": message.client_submit_time,
        "delivery_time": message.delivery_time,
        "attachment_count": message.number_of_attachments,
        "total_attachment_size": total_attachment_size_bytes,
        "attachments": attachments
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...