Xuất và Trích xuất Nội dung Zimbra TGZ

Đọc bản sao lưu hiếm khi là mục tiêu duy nhất - thường các tin nhắn phải được chuyển đến nơi khác. TgzReader hỗ trợ hai cách tiếp cận: xuất một lần sao chép toàn bộ hộp thư lên đĩa, và lưu thủ công các tin nhắn bạn chọn trong quá trình duyệt.

Các mẫu dưới đây sử dụng các tiêu đề và không gian tên sau:

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

Export the Whole Mailbox

ExportTo nhận một đường dẫn thư mục và ghi mọi mục của bản sao lưu vào bên dưới, tạo thư mục con cho mỗi thư mục Zimbra. Tin nhắn được lưu ở dạng MIME gốc, và các mục không phải thư điện tử như liên hệ được ghi ở định dạng riêng (một liên hệ trở thành một .vcf file). Thư mục đích phải tồn tại.

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

Lưu Tin Nhắn Được Chọn

Khi chỉ muốn một phần của hộp thư, duyệt như mô tả trong Đọc Tập tin Zimbra TGZ và lưu CurrentMessage bạn tự làm. Vì nó là một MailMessage, bất kỳ SaveOptions có thể được áp dụng. Ví dụ chỉ giữ các mục có đường dẫn thư mục bắt đầu bằng Inbox và ghi chúng dưới dạng 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();

Filter by Message Properties

Bất kỳ thuộc tính nào của tin nhắn đều có thể quyết định. Ở đây các tin nhắn có tệp đính kèm được lưu dưới dạng MSG Outlook bằng cách truyền 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();