การแปลง MBOX เป็น PST
การย้ายจาก Thunderbird ไป Outlook หมายถึงการแปลงอาร์ไคฟ์ MBOX เป็นไฟล์ PST. Aspose.Email สำหรับ C++ มีสองวิธี: ลูปแบบแมนนวลที่ให้คุณควบคุมโฟลเดอร์และการแปลงข้อความเต็มที่, และ MailStorageConverter ผู้ช่วยที่ทำทั้งหมดในหนึ่งการเรียก.
ตัวอย่างด้านล่างใช้ส่วนหัวและเนมสเปซต่อไปนี้:
#include <MailMessage.h>
#include <EmlLoadOptions.h>
#include <Mapi/MapiMessage.h>
#include <Storage/Mbox/MboxStorageReader.h>
#include <Storage/Mbox/MboxrdStorageReader.h>
#include <Storage/Mbox/MboxLoadOptions.h>
#include <Storage/MailStorageConverter.h>
#include <Storage/MboxToPstConversionOptions.h>
#include <Storage/Pst/PersonalStorage.h>
#include <Storage/Pst/FolderInfo.h>
#include <Storage/Pst/FileFormatVersion.h>
#include <Storage/Pst/StandardIpmFolder.h>
#include <system/io/file_stream.h>
#include <system/io/memory_stream.h>
#include <system/convert.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Storage;
using namespace Aspose::Email::Storage::Mbox;
using namespace Aspose::Email::Storage::Pst;
คัดลอกข้อความเข้า PST ด้วยตนเอง
ขั้นตอนการทำด้วยตนเองประกอบด้วยสี่ขั้นตอน:
- เปิดอาร์ไคฟ์ด้วย MboxStorageReader::CreateReader.
- สร้างไฟล์ผลลัพธ์ด้วย PersonalStorage::Create.
- เพิ่มโฟลเดอร์เป้าหมาย - ที่นี่คือ Inbox มาตรฐาน, สร้างด้วย CreatePredefinedFolder.
- แปลงแต่ละ MailMessage ไปยัง MapiMessage กับ MapiMessage::FromMailMessage และเพิ่มด้วย FolderInfo::AddMessage.
เพราะคุณควบคุมลูปด้วยตนเอง, จึงง่ายต่อการส่งข้อความไปยังโฟลเดอร์ต่าง ๆ, ข้ามบางข้อความ, หรือเปลี่ยนแปลงคุณสมบัติก่อนบันทึก.
// Open the source MBOX archive
SharedPtr<MboxStorageReader> mbox = MboxStorageReader::CreateReader(u"mailbox.mbox", MakeObject<MboxLoadOptions>());
// Create the target Outlook data file
SharedPtr<PersonalStorage> pst = PersonalStorage::Create(u"FromMbox.pst", FileFormatVersion::Unicode);
// Create the folder that will receive the imported messages
SharedPtr<FolderInfo> inbox = pst->CreatePredefinedFolder(u"Inbox", StandardIpmFolder::Inbox);
// Convert every message to MAPI and add it to the folder
for (SharedPtr<MailMessage> eml : mbox->EnumerateMessages())
{
SharedPtr<MapiMessage> msg = MapiMessage::FromMailMessage(eml);
inbox->AddMessage(msg);
}
pst->Dispose();
mbox->Dispose();
แปลงด้วย MailStorageConverter
MailStorageConverter::MboxToPst อ่านอาร์ไคฟ์, สร้าง PST, ใส่ทุกข้อความลงในโฟลเดอร์ "Inbox" และคืนค่า PersonalStorage. ส่วน MboxMessageOptions คุณสมบัติกำหนด EmlLoadOptions ใช้เพื่อแยกข้อความ; กำหนดก่อนการเรียก.
// Options used to parse each message taken from the MBOX file
MailStorageConverter::set_MboxMessageOptions(MakeObject<EmlLoadOptions>());
// One call: read the MBOX file and write a new PST file
SharedPtr<PersonalStorage> pst = MailStorageConverter::MboxToPst(u"mailbox.mbox", u"Converted.pst");
// the converter places the messages into an "Inbox" folder under the root
SharedPtr<FolderInfo> inbox = pst->get_RootFolder()->GetSubFolder(u"Inbox");
Console::WriteLine(u"Messages imported into Inbox: " + Convert::ToString(inbox->get_ContentCount()));
pst->Dispose();
ลบลายเซ็นดิจิทัลระหว่างการแปลง
ลายเซ็น S/MIME ของข้อความต้นทางไม่ได้ต้องการเสมอในไฟล์เป้าหมาย. ตั้งค่า RemoveSignature บน MboxToPstConversionOptions อ็อบเจกต์และใช้ MboxToPst การโหลดที่รับผู้อ่านที่มีอยู่, ที่จัดเก็บที่มีอยู่, ชื่อโฟลเดอร์ปลายทางและตัวเลือก. การโหลดนี้ยังให้คุณเขียน PST ไปยังสตรีมหน่วยความจำ, อย่างที่ตัวอย่างทำ.
MailStorageConverter::set_MboxMessageOptions(MakeObject<EmlLoadOptions>());
SharedPtr<IO::FileStream> mboxStream = MakeObject<IO::FileStream>(u"mailbox.mbox", IO::FileMode::Open, IO::FileAccess::Read);
SharedPtr<MboxrdStorageReader> reader = MakeObject<MboxrdStorageReader>(mboxStream, MakeObject<MboxLoadOptions>());
// The PST is built in memory here; a file path works the same way
SharedPtr<IO::MemoryStream> pstStream = MakeObject<IO::MemoryStream>();
SharedPtr<PersonalStorage> pst = PersonalStorage::Create(pstStream, FileFormatVersion::Unicode);
// Strip S/MIME signatures from the messages while they are copied
SharedPtr<MboxToPstConversionOptions> options = MakeObject<MboxToPstConversionOptions>();
options->set_RemoveSignature(true);
MailStorageConverter::MboxToPst(reader, pst, u"Inbox", options);
Console::WriteLine(u"Messages imported: " + Convert::ToString(pst->get_RootFolder()->GetSubFolder(u"Inbox")->get_ContentCount()));
pst->Dispose();
reader->Dispose();
mboxStream->Close();