EML 파일에서 Zimbra TGZ 백업 만들기

Aspose.Email for C++는 EML 파일 모음으로부터 Zimbra 호환 TGZ 아카이브를 만들 수 있습니다. 이는 백업 및 마이그레이션 작업을 단순화합니다: 예를 들어, 다른 메일 시스템에서 내보낸 메시지를 수집해 단일 백업으로 Zimbra에 가져올 수 있습니다.

EML 파일 디렉터리에서 TGZ 백업 만들기

정적 TgzBackupBuilder::Build() 메서드 Aspose::Email::Storage::Zimbra::TgzBackup 네임스페이스는 세 개의 매개변수를 사용합니다:

  • inputDirectory - 다음을 포함한 디렉터리 *.eml 파일. 디렉터리를 재귀적으로 스캔하고 다른 확장자를 가진 파일은 무시합니다.
  • outputArchive - 생성할 TGZ 아카이브 경로입니다.
  • rootFolderName - 가져온 메시지의 최상위 사서함 폴더 이름입니다. 입력 디렉터리의 하위 디렉터리는 해당 폴더의 하위 폴더가 되며, 따라서 파일은 emails/Projects 다음에 배치됩니다 Projects 의 하위 폴더 Imported.

메서드는 BuildResult 작업 세부 정보를 포함하는 객체: get_MessagesWritten() 아카이브에 추가된 메시지 수를 반환하고, get_Errors() 구축 중 발생한 오류 목록을 반환합니다.

#include <Storage/Zimbra/TgzBackup/TgzBackupBuilder.h>
#include <Storage/Zimbra/TgzBackup/BuildResult.h>
#include <system/collections/ilist.h>
#include <system/console.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email::Storage::Zimbra::TgzBackup;

SharedPtr<BuildResult> result = TgzBackupBuilder::Build(u"emails", u"backup.tgz", u"Imported");

Console::WriteLine(u"Messages written: " + Convert::ToString(result->get_MessagesWritten()));
for (const String& error : result->get_Errors())
{
    Console::WriteLine(u"Error: " + error);
}

생성된 백업 읽기

결과 아카이브는 다음을 사용하여 읽을 수 있습니다 TgzReader 다른 Zimbra 백업과 같은 클래스입니다. 리더는 생성 후 첫 번째 항목에 위치하므로 do ... while 루프는 그 전에 처리합니다 ReadNextMessage() 다음 항목으로 이동합니다. get_CurrentDirectory() 현재 항목의 메일 폴더를 반환하고, get_CurrentMessage() 메시지 자체를 반환합니다.

#include <MailMessage.h>
#include <Storage/Zimbra/TgzReader.h>
#include <system/console.h>

using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Storage::Zimbra;

auto reader = MakeObject<TgzReader>(u"backup.tgz");

do
{
    SharedPtr<MailMessage> message = reader->get_CurrentMessage();
    if (message != nullptr)
    {
        Console::WriteLine(reader->get_CurrentDirectory() + u": " + message->get_Subject());
    }
} while (reader->ReadNextMessage());

reader->Dispose();