MBOX를 PST로 변환

Thunderbird에서 Outlook으로 마이그레이션하려면 MBOX 아카이브를 PST 파일로 변환해야 합니다. C++용 Aspose.Email은 두 가지 경로를 제공합니다: 폴더와 메시지 변환을 완전히 제어할 수 있는 수동 루프와 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에 수동으로 복사

수동 경로는 네 단계로 구성됩니다:

  1. 다음으로 아카이브를 엽니다 MboxStorageReader::CreateReader.
  2. 다음으로 출력 파일을 생성합니다 PersonalStorage::Create.
  3. 대상 폴더 추가 - 여기서는 표준 Inbox이며, 다음으로 생성됩니다 CreatePredefinedFolder.
  4. 각 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. The 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();