ทำงานกับ MapiJournal ใน PST
รายการ Journal ของ Outlook บันทึกกิจกรรม – การโทร, การประชุม, งานบนเอกสาร – พร้อมกับเวลาเริ่มและสิ้นสุด ใน Aspose.Email สำหรับ C++ รายการเช่นนี้คือ MapiJournal อ็อบเจ็กต์ที่สามารถเก็บในโฟลเดอร์ Journal ของไฟล์ PST เช่นรายการ Outlook อื่น
ตัวอย่างในบทความนี้ใช้ส่วนหัวและเนมสเปซต่อไปนี้:
#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;
เพิ่ม MapiJournal ไปยัง PST
นี้ MapiJournal คอนสตรัคเตอร์รับหัวเรื่อง เนื้อหา ประเภทของกิจกรรมตามที่ Outlook แสดง (เช่น "การโทรศัพท์") และคำอธิบายสั้น ระยะเวลาและบริษัทที่เกี่ยวข้องตั้งค่าผ่านคุณสมบัติ
เพื่อแสดงในมุมมอง Journal ของ Outlook รายการต้องอยู่ในโฟลเดอร์ที่มีบทบาทเป็น Journal 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();