การส่งออกและสกัดเนื้อหา Zimbra TGZ

การอ่านสำเนาสำรองมักไม่ได้เป็นเป้าหมายหลัก - ข้อความมักต้องไปยังที่อื่น 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();