How to parse / read Outlook PST-Files with Python?

Viewed 1191

Searching the Internet for accessing Outlook PST-Files with Python gives very little results (and most of the stuff shown is outdated). Does anyone know how to read a PST with or without a library? Unfortunately I am not good enough in programming to build a PST-reader without the help of a library.

My target is to get the following information about the content:

  • Number of Items per Folder
  • Type of Item (Mail, Meeting, Contact...)
  • Size of Items
  • Attachments including size
  • maybe other Meta-Data like date, recipients etc. (optional)

I already tried the following things:

  1. libpff / pypff : crashes and seems to read whole file in memory before doing something (no good solution as the PST-files are kept on a slow network storage).

  2. Libratom : same problem as it is based on libpff.

  3. Libpst : unclear how this is used / comes as a binary (no explanation how to install) / see answer on this post / does not seems to be maintained or updated.

  4. win32 (mounting PST in Outlook) : one tutorial showed how to mount the PST into a locally installed Outlook and getting the contents with MAPI-access, but this is also very, very slow and not a good solution as Outlook is needed.

  5. Asponse Email Python : promising at the start though documentation is not very good (no Python examples / different naming e.g. for the PersonalStorage object and many others / stops after 50 items per folder (maybe a limit of the non-free version, but unclear due to lack of explanation on the publishers website).

This is an example from the Asponse-website:

personalStorage = PersonalStorage.from_file(dataDir + "Outlook.pst")

folderInfoCollection = personalStorage.root_folder.get_sub_folders()

for folderInfo in folderInfoCollection:

    print("Folder: " + folderInfo.display_name)
    print("Total Items: " + str(folderInfo.content_count))
    print("Total Unread Items: " + str(folderInfo.content_unread_count))
    print("----------------------")

I did heavy googling to find the fitting import-statement to make this run.

Does anyone have a stable clear approach for reading Outlook PST files? Even a solution using Asponse would be great exceeding the 50 items limit.

1 Answers

Redemption (I am its author) can be another choice - it is a wrapper around Extended MAPI, so you would still need to have Outlook installed (for its MAPI system), but unlike Outlook Object Model, it can be used from a service and does not require starting outlook.exe and/or adding PST files to the user's default profile. You can use either RDOSession.LogonPstStore (it creates and deletes a temporary profile configured to use the specified PST file) and/or RDOSession.Stores.AddPstStore to the add a PST file to an existing session (e.g. used by Outlook or created by LogonPstStore).

Related