Free Support Forum - aspose.com

Detecting attachment type

Hi,

We are extracting messages from a PST that may contain Tasks, Calendar and other non-email items in the folder. How can we differentiate between these type of messages when extracting as we have to keep thm in saparate fodlers?

Hi Aaron,

MapiMessage.MessageClass can be used to identify different type of items in a PST. Please give a try to the following sample code and let us know the feedback.

static void SampleCode()

{

using (PersonalStorage pst = PersonalStorage.FromFile("sample.pst"))

{

FolderInfo contactFolder = pst.GetPredefinedFolder(StandardIpmFolder.Inbox);

foreach (MapiMessage mapi in contactFolder.EnumerateMapiMessages())

{

if (mapi.MessageClass.Contains("IPM.Schedule.Meeting"))

{

MapiCalendar cal = (MapiCalendar)mapi.ToMapiMessageItem();

Console.WriteLine("Start Time = " + cal.StartDate);

Console.WriteLine("End Time = " + cal.EndDate);

Console.WriteLine("Location = " + cal.Location);

Console.WriteLine("Response Status = " + cal.MessageClass);

}

else if (mapi.MessageClass == "IPM.Appointment")

{

MapiCalendar cal = (MapiCalendar)mapi.ToMapiMessageItem();

Console.WriteLine("Start Time = " + cal.StartDate);

Console.WriteLine("End Time = " + cal.EndDate);

Console.WriteLine("Location = " + cal.Location);

}

else if (mapi.MessageClass == "IPM.Task")

{

MapiTask task = (MapiTask)mapi.ToMapiMessageItem();

Console.WriteLine("Task Owner = " + task.Users.Owner);

}

Console.WriteLine("____________________________________________");

}

}

}