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.
Asked
Active
Viewed 1.2k times
1 Answers
8
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
}

Viseshini Reddy
- 744
- 3
- 13
-
Is there any way to extract all attachments from messages while preserving their original properties? Thanks – Diamantino S Dec 19 '18 at 01:25
-
1Email is text-only media. So mails & attachments (which may have binary data like images) have to be encoded as text. Hence not all the original properties are preserved while reading them plainly. – Viseshini Reddy Dec 19 '18 at 06:42
-
That code talks only about PST, no mention of OST. Does this really work for OST? – user124114 Jan 20 '20 at 18:27
-
@user124114 yes, PST and OST use the same file format. – James McLeod Apr 25 '20 at 11:30
-
1To clarify my comment from April - the OST file format used until the release of Outlook 2013 is the same as the PST file format. The OST file format used for Outlook 2013 and later has not been documented, but is *similar* to the PST file format. See https://blog.mythicsoft.com/ost-2013-file-format-the-missing-documentation/. – James McLeod Jul 23 '20 at 15:12
-
@ViseshiniReddy is there any way to access the email recipients table? I know there is an entry where I am able to get the "TO_DISPLAY" and find the email from the header. But some of the emails don't have the header data don't know why it's returning None. Any help will be appreciated. Thanks – AGk Sep 07 '22 at 05:58