PstReader Class |
Namespace: MailBee.Outlook
The PstReader type exposes the following members.
Name | Description | |
---|---|---|
PstReader(Stream) |
Creates an instance of PstReader class and loads .PST database from a stream.
| |
PstReader(String) |
Creates an instance of PstReader class and opens the specified .PST file.
| |
PstReader(Stream, String) |
Creates a new .PST reader and loads .PST database from a stream.
| |
PstReader(String, String) |
Creates a new .PST reader, unlocks it and loads .PST database from the specified file.
|
Name | Description | |
---|---|---|
Close |
Closes the opened .PST stream.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetFolderByID |
Gets the PST folder by its ID.
| |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetItemByID |
Gets the PST item by its ID.
| |
GetPstRootFolders(Boolean) |
Gets the list of root folders which are present in the .PST file or stream.
| |
GetPstRootFolders(Boolean, String) |
Gets the list of root folders which are present in the .PST file or stream
with specified delimiter which is used as a hierarchy delimiter of separate
levels of folder names.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
LicenseKey | Obsolete.
Assigns the license key.
| |
TrialDaysLeft |
Gets the number of days left to the date of the trial license key expiration.
|
PstReader class parses a .PST file, extracts its tree-like structure (folders and other items like messages, contacts, tasks, etc), and provides access to the extracted data.
You can parse very large .PST files with this method as it does not parse the file at once. Instead, it allows you to iterate though the collection of folders or items at any nesting level, processing items one-by-one and thus reducing memory usage.
Prior to creating instances of this class, the correct license key must be set. See MailBee.Global.LicenseKey property for details.
Note |
---|
In this sample, it's assumed the license key is already set outside (such as in app.config file). Otherwise, use MailBee.Global.LicenseKey property to unlock the component. |
// To use the code below, import these namespaces at the top of your code. using System; using System.IO; using MailBee.Outlook; using MailBee.Mime; class Sample { static void Main(string[] args) { PstReader reader = new PstReader(@"C:\OutlookMessageBase\Outlook.pst"); string outPath = @"C:\OutlookMessageBase\PstOutputDir"; PstFolderCollection pstColl = reader.GetPstRootFolders(true); foreach (PstFolder fItem in pstColl) { int i = 0; Console.WriteLine("::: " + fItem.Name); string folderPath = Path.Combine(outPath, fItem.SafeName); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } foreach (PstItem item in fItem.Items) { if (item != null && item.PstType == PstItemType.Message) { MailMessage msg = ((PstMessage) item).GetAsMailMessage(); Console.WriteLine(msg.Subject); string fileName = Path.Combine(folderPath, string.Format("{0}_{1}.eml", PstMessage.MakeStringSafeForFileName(msg.Subject), i++)); // Charset fix. msg.Parser.CharsetMetaTagMode = CharsetMetaTagProcessing.RemoveCharsetMetaTag; msg.Charset = "UTF-8"; msg.EncodeAllHeaders(System.Text.Encoding.UTF8, HeaderEncodingOptions.None); msg.SaveMessage(fileName); //msg = null; //GC.Collect(); // For big amount of large messages } } } } }