Zimbra TGZ 콘텐츠 내보내기 및 추출
Contents
[
Hide
]
백업을 읽는 것이 목적 자체인 경우는 드물며, 보통 메시지를 다른 곳에 저장해야 합니다. TgzReader 두 가지 접근 방식을 지원합니다: 디스크에 메일함을 그대로 복제하는 한 번 호출 내보내기와, 순회하면서 선택한 메시지만 수동으로 저장하는 방법.
아래 샘플은 다음 헤더와 네임스페이스를 사용합니다:
#include <MailMessage.h>
#include <SaveOptions.h>
#include <EmlSaveOptions.h>
#include <MsgSaveOptions.h>
#include <AttachmentCollection.h>
#include <Storage/Zimbra/TgzReader.h>
#include <system/io/directory.h>
#include <system/string_comparison.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Storage::Zimbra;
전체 메일함 내보내기
ExportTo 디렉터리 경로를 받아 백업의 모든 항목을 그 아래에 기록하고, 각 Zimbra 폴더마다 하위 디렉터리를 생성합니다. 메시지는 원본 MIME 형태로 저장되고, 연락처와 같은 비메일 항목은 자체 형식으로 기록됩니다(연락처는 .vcf 파일). 대상 디렉터리는 존재해야 합니다.
SharedPtr<TgzReader> reader = MakeObject<TgzReader>(u"ZimbraSample.tgz");
// the target directory must exist and be writable
IO::Directory::CreateDirectory_(u"ZimbraExport");
// recreate the mailbox folder tree on disk and write every message into it
reader->ExportTo(u"ZimbraExport");
reader->Dispose();
선택한 메시지 저장
메일함의 일부만 필요할 때는 아래와 같이 순회합니다 Zimbra TGZ 파일 읽기 그리고 저장합니다 CurrentMessage 직접. 이는 MailMessage, 모든 SaveOptions 적용될 수 있습니다. 예제는 폴더 경로가 다음으로 시작하는 항목만 유지합니다 Inbox 그리고 이를 EML로 저장합니다:
SharedPtr<TgzReader> reader = MakeObject<TgzReader>(u"ZimbraSample.tgz");
IO::Directory::CreateDirectory_(u"ZimbraInbox");
int32_t index = 0;
do
{
SharedPtr<MailMessage> message = reader->get_CurrentMessage();
if (message == nullptr)
{
continue;
}
// keep only the items that belong to the Inbox folder
if (reader->get_CurrentDirectory().StartsWith(u"Inbox", StringComparison::OrdinalIgnoreCase))
{
message->Save(String::Format(u"ZimbraInbox\\message_{0}.eml", index++), SaveOptions::get_DefaultEml());
}
}
while (reader->ReadNextMessage());
reader->Dispose();
메시지 속성으로 필터링
메시지의 모든 속성이 결정을 내릴 수 있습니다. 여기서는 첨부 파일이 있는 메시지를 Outlook MSG 형식으로 저장하기 위해 다음을 전달합니다 SaveOptions::DefaultMsgUnicode:
SharedPtr<TgzReader> reader = MakeObject<TgzReader>(u"ZimbraSample.tgz");
IO::Directory::CreateDirectory_(u"ZimbraWithAttachments");
int32_t index = 0;
do
{
SharedPtr<MailMessage> message = reader->get_CurrentMessage();
if (message != nullptr && message->get_Attachments()->get_Count() > 0)
{
// Outlook MSG format this time
message->Save(String::Format(u"ZimbraWithAttachments\\message_{0}.msg", index++), SaveOptions::get_DefaultMsgUnicode());
}
}
while (reader->ReadNextMessage());
reader->Dispose();