Làm việc với MapiJournal trong PST

Các mục nhật ký Outlook ghi lại các hoạt động - cuộc gọi, họp, công việc trên tài liệu - cùng với thời gian bắt đầu và kết thúc. Trong Aspose.Email cho C++ mục như vậy là một MapiJournal đối tượng, có thể được lưu trong thư mục Journal của tệp PST như bất kỳ mục Outlook nào khác.

Các mẫu trong bài viết này sử dụng các tiêu đề và không gian tên sau:

#include <Mapi/MapiMessage.h>
#include <Mapi/MapiJournal.h>
#include <Mapi/MapiAttachment.h>
#include <Mapi/MapiAttachmentCollection.h>
#include <Storage/Pst/PersonalStorage.h>
#include <Storage/Pst/FolderInfo.h>
#include <Storage/Pst/MessageInfo.h>
#include <Storage/Pst/FileFormatVersion.h>
#include <Storage/Pst/StandardIpmFolder.h>
#include <system/array.h>
#include <system/convert.h>
#include <system/io/file.h>
#include <system/io/path.h>

using namespace System;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Storage::Pst;

Thêm MapiJournal vào PST

Cái MapiJournal constructor nhận tiêu đề, nội dung, loại hoạt động như Outlook hiển thị (ví dụ "Cuộc gọi điện thoại") và mô tả ngắn. Thời gian và các công ty liên quan được đặt qua các thuộc tính.

Để hiển thị trong chế độ xem nhật ký của Outlook, mục nhập phải nằm trong thư mục có vai trò nhật ký. CreatePredefinedFolder với StandardIpmFolder::Journal tạo thư mục như vậy, và FolderInfo::AddMapiMessageItem lưu mục nhập trong đó.

auto journal = MakeObject<MapiJournal>(u"Call with the supplier", u"Agreed on the delivery dates for May.",
    u"Phone call", u"Phone call");
journal->set_StartTime(DateTime(2025, 4, 14, 10, 0, 0));
journal->set_EndTime(journal->get_StartTime().AddMinutes(25));
journal->set_Companies(MakeArray<String>({u"Northwind Traders", u"Contoso"}));

auto pst = PersonalStorage::Create(u"Journal.pst", FileFormatVersion::Unicode);
auto journalFolder = pst->CreatePredefinedFolder(u"Journal", StandardIpmFolder::Journal);
journalFolder->AddMapiMessageItem(journal);

Console::WriteLine(u"Entries in the journal folder: " + Convert::ToString(journalFolder->get_ContentCount()));
pst->Dispose();

Thêm Tệp Đính Kèm vào MapiJournal

Tài liệu liên quan đến một hoạt động - biên bản cuộc họp, báo giá đã thảo luận qua điện thoại - có thể đi cùng với mục nhật ký như các tệp đính kèm. get_Attachments trả về MapiAttachmentCollection của mục nhập, mà Add phương thức nhận tên tệp và nội dung của tệp đính kèm. Mẫu thêm mục nhập như vậy vào kho lưu trữ đã tạo ở trên.

auto journal = MakeObject<MapiJournal>(u"Quote review", u"Went through the quote with the sales team.",
    u"Meeting", u"Meeting");
journal->set_StartTime(DateTime(2025, 4, 15, 14, 0, 0));
journal->set_EndTime(journal->get_StartTime().AddHours(1));

for (String file : MakeArray<String>({u"1.jpg", u"Attachments.eml"}))
{
    journal->get_Attachments()->Add(IO::Path::GetFileName(file), IO::File::ReadAllBytes(file));
}

auto pst = PersonalStorage::FromFile(u"Journal.pst", true);
auto journalFolder = pst->GetPredefinedFolder(StandardIpmFolder::Journal);
journalFolder->AddMapiMessageItem(journal);

// read the entries back and list their attachments
for (auto messageInfo : journalFolder->EnumerateMessages())
{
    auto message = pst->ExtractMessage(messageInfo);
    Console::WriteLine(message->get_Subject() + u": " + Convert::ToString(message->get_Attachments()->get_Count()) + u" attachments");
}

pst->Dispose();