Reading PST files

I’m trying to read a few hundred PST files and get some basic information from them. Basically just the earliest and latest dates from the messages. Is there a faster way than the following function?


private void GetFolderContents(FolderInfo rootFolder, PersonalStorage pst)
{
MessageInfoCollection messageInfoCollection = rootFolder.GetContents();

foreach (MessageInfo msgInfo in messageInfoCollection)
{
if (msgInfo.MessageClass.ToLower() == “ipm.note”)
{
// I believe this is what is taking so long
MapiMessage mapi = pst.ExtractMessage(msgInfo);
// dates are initialized to 1/1/0001
if (FirstDate.ToShortDateString() == “1/1/0001”)
{
LastDate = FirstDate = mapi.DeliveryTime;
}
if (mapi.DeliveryTime < FirstDate) FirstDate = mapi.DeliveryTime;
if (mapi.DeliveryTime > LastDate) LastDate = mapi.DeliveryTime;
}
}

if (rootFolder.HasSubFolders == true)
{
foreach (FolderInfo subfolderInfo in rootFolder.GetSubFolders())
{
GetFolderContents(subfolderInfo, pst);
}
}
return;
}

Hi Richard,

Thank you for contacting Aspose support team.

You may please modify your code such that instead of fetching the complete message, extract the required property.

Code:

// I believe this is what is taking so long
// MapiMessage mapi = pst.ExtractMessage(msgInfo);
MapiProperty propDelvTime = pst.ExtractProperty(msgInfo.EntryId, MapiPropertyTag.PR_DELIVER_TIME);
DateTime dt = propDelvTime.GetDateTime();

Please give it a try and let us know the feedback.

When I use your code propDelvTime is always null. Any idea why that would be the case?

I am using version 5.0.0.0

Hi,

Thank you for providing the feedback. It may be noted that the property which is extracted, should be present there in the message in PST. In your case you may please use PR_MESSAGE_DELIVERY_TIME tag to extract the required information using latest version Aspose.Email for .NET 6.0.0.

Code:

MapiProperty mapiProp = pst.ExtractProperty(msgInfo.EntryId, MapiPropertyTag.PR_MESSAGE_DELIVERY_TIME);
DateTime dt = mapiProp.GetDateTime();

I upgraded and using this code it now works.


Thanks much!

Another related question. Is there a way to extract the attachments without extracting the message first?


I’ve tried this but it always returns null.
MapiProperty mapiAttachments = pst.ExtractProperty[msgInfo.EntryId, MapiPropertyTag.PR_MESSAGE_ATTACHMENTS);

Thanks again

Hi,


The PR_MESSAGE_ATTACHMENTS refers to the attachment table presence in a message file that may not always be present if the provider has not set it. You can check it by taking a simple MSG file with attachment and check for this property. Thus, it can be null.

Using the ExtractProperty method, we could not find any way to extract attachments from a PST file without extracting the message first. Thus, it seems necessary to extract message first in order to extract the attachments.

Thanks Muhammad.

But let me re-phrase my question. I don’t actually need to extract the attachments. I just need access to their properties. Specifically the size of the attachment. Does that still require me to extract the mapiMessage and then get the attachment properties from that?

Hi,


At present, we can’t retrieve any of the attachment properties without extracting the message first. We have logged an enhancement request with id: EMAILNET-35062 to extract attachments from a message in PST without extracting the message first. We shall share the update with you here as soon as the enhancement is available.

Thank you again!!

Hi,


You are welcome and please feel free to write to us if you have any additional query related to the API.

The issues you have found earlier (filed as EMAILNET-35062) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.