Jump to content

Help with parsing PST files


nashie
 Share

Recommended Posts

Does anyone know how to parse PST files please? I would like reliable information in relation to the PST file structure. Any resources or documentation source/s would be greatly appreciated. I've tried Googling and all that jazz but nothing useful. I need the structure rather than reading the content as this will at some point be incorporated into an application which needs to extract all emails and their attachments.

Thanks in advance

Dave

Link to comment
Share on other sites

  • 2 years later...

Does anyone know how to parse PST files please? I would like reliable information in relation to the PST file structure. Any resources or documentation source/s would be greatly appreciated. I've tried Googling and all that jazz but nothing useful. I need the structure rather than reading the content as this will at some point be incorporated into an application which needs to extract all emails and their attachments.

Thanks in advance

Dave

Much agreed, if anyone out there has any information on parseing pst files for the use of extracting emails and attachements please post!.

Link to comment
Share on other sites

okay so i have figured something out, the only problem is that you need outlook installed and configured with a profile. still working on a standalone solution.

public static IEnumerable<MailItem> readPst(string pstFilePath, string pstName)
        {
            List<MailItem> mailItems = new List<MailItem>();
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            NameSpace outlookNs = app.GetNamespace("MAPI");
            // Add PST file (Outlook Data File) to Default Profile
            outlookNs.AddStore(pstFilePath);
            Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = outlookNs.Stores[pstName].GetRootFolder();
            // Traverse through all folders in the PST file
            // TODO: This is not recursive, refactor
            Folders subFolders = rootFolder.Folders;
            foreach (Folder folder in subFolders)
            {
                Items items = folder.Items;
                foreach (object item in items)
                {
                    if (item is MailItem)
                    {
                        MailItem mailItem = item as MailItem;
                        mailItems.Add(mailItem);
                    }
                }
            }
            // Remove PST file from Default Profile
            outlookNs.RemoveStore(rootFolder);
            return mailItems;
        }

This code will retrieve all mailitems inside the pst file.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...