Zimbra TGZ コンテンツのエクスポートと抽出

バックアップの読み取り自体が目的になることはほとんどなく、メッセージは通常別の場所へ移す必要があります。 TgzReader 2 つのアプローチをサポートします: ディスク上にメールボックスをミラーリングするワンコールエクスポートと、反復処理中に選択したメッセージを手動で保存する方法です。

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

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