PST での MapiJournal の操作

Outlook のジャーナルエントリは、電話、会議、ドキュメント作業などの活動と、開始・終了時間を記録します。Aspose.Email for C++ ではこのエントリは次のようになります MapiJournal オブジェクトは、他の Outlook アイテムと同様に PST の Journal フォルダーに保存できます。

本記事のサンプルは以下のヘッダーと名前空間を使用しています:

#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;

PST への MapiJournal の追加

この MapiJournal コンストラクタは件名、本文、Outlook が表示する活動の種類(例: "Phone call")と短い説明を受け取ります。期間と関連会社はプロパティで設定します。

Outlook のジャーナルビューに表示するには、エントリはジャーナル ロールを持つフォルダーに属している必要があります。 CreatePredefinedFolder と StandardIpmFolder::Journal そのようなフォルダーを作成し、 FolderInfo::AddMapiMessageItem エントリをそれに保存します。

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();

MapiJournal への添付ファイルの追加

活動に関連するドキュメント - 会議議事録や電話で議論した見積もり - は、ジャーナルエントリの添付ファイルとして同行できます。 get_Attachments は MapiAttachmentCollection エントリの、これは Add メソッドはファイル名と添付ファイルの内容を受け取ります。サンプルは上記で作成したストレージにこのエントリを追加します。

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();