Чтение файла PST Outlook и получение информации о папках и подпапках
Чтение файла PST Outlook и получение информации о папках и подпапках
Aspose.Email для C++ предоставляет API для чтения файлов PST Microsoft Outlook. Вы можете загрузить файл PST с диска или потока в экземпляр класса PersonalStorage и получить информацию о его содержимом, например, папках, подпапках и сообщениях. API также предоставляет возможность включать папки поиска при обходе сообщений из папок PST.
Загрузка файла PST
Файл PST Outlook можно загрузить в экземпляр класса PersonalStorage. Следующий фрагмент кода показывает, как загрузить файл PST.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
// Load the Outlook PST file | |
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::FromFile(dataDir + L"PersonalStorage.pst"); |
Отображение информации о папках
После загрузки файла PST в класс PersonalStorage вы можете получить информацию о его отображаемом имени, корневой папке, подпапках и количестве сообщений. Следующий фрагмент кода показывает, как отобразить имя файла PST, папки и количество сообщений в папках.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
// The path to the File directory. | |
System::String dataDir = RunExamples::GetDataDir_Outlook(); | |
System::String dst = dataDir + L"PersonalStorage.pst"; | |
// load PST file | |
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::FromFile(dst); | |
// Get the folders information | |
System::SharedPtr<FolderInfoCollection> folderInfoCollection = personalStorage->get_RootFolder()->GetSubFolders(); | |
// Browse through each folder to display folder name and number of messages | |
{ | |
auto folderInfo_enumerator = (folderInfoCollection)->GetEnumerator(); | |
decltype(folderInfo_enumerator->get_Current()) folderInfo; | |
while (folderInfo_enumerator->MoveNext() && (folderInfo = folderInfo_enumerator->get_Current(), true)) | |
{ | |
System::Console::WriteLine(System::String(L"Folder: ") + folderInfo->get_DisplayName()); | |
System::Console::WriteLine(System::String(L"Total items: ") + folderInfo->get_ContentCount()); | |
System::Console::WriteLine(System::String(L"Total unread items: ") + folderInfo->get_ContentUnreadCount()); | |
System::Console::WriteLine(L"-----------------------------------"); | |
} | |
} |
Получение информации о родительской папке из MessageInfo
Следующий фрагмент кода показывает, как получить информацию о родительской папке из MessageInfo.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
// Load Pst File | |
System::String dataDir = RunExamples::GetDataDir_Outlook() + L"PersonalStorage.pst"; | |
{ | |
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::FromFile(dataDir); | |
auto folder_enumerator = (personalStorage->get_RootFolder()->GetSubFolders())->GetEnumerator(); | |
decltype(folder_enumerator->get_Current()) folder; | |
while (folder_enumerator->MoveNext() && (folder = folder_enumerator->get_Current(), true)) | |
{ | |
auto msg_enumerator = (folder->EnumerateMessages())->GetEnumerator(); | |
decltype(msg_enumerator->get_Current()) msg; | |
while (msg_enumerator->MoveNext() && (msg = msg_enumerator->get_Current(), true)) | |
{ | |
System::SharedPtr<FolderInfo> fi = personalStorage->GetParentFolder(msg->get_EntryId()); | |
} | |
} | |
} |