读取和导出 Zimbra TGZ 文件

Zimbra 是一个基于云的电子邮件和协作套件,提供电子邮件、联系人、日历、文件共享、任务和消息功能——所有这些都可通过任何设备上的 Zimbra Web 客户端访问。

Aspose.Email for Node.js via .NET 使开发者能够使用该库读取、提取并导出 Zimbra TGZ 备份文件中的数据,使用 TgzReader 该类。您可以轻松访问所有消息、统计总项目数,并将消息、联系人或日历数据从 TGZ 文件导出为通用格式。

读取 Zimbra TGZ 文件中的所有消息

TgzReader 该类允许您读取存储在 Zimbra TGZ 备份文件中的所有消息。

以下示例演示如何遍历所有消息并显示其文件夹位置和主题。

const asposeemail = require('@aspose/email');
const fs = require('fs');

// Path to the Zimbra TGZ file
const tgzPath = "ZimbraSample.tgz";

// Create a TgzReader instance
const reader = new asposeemail.TgzReader(tgzPath);

// Read and display all messages
while (reader.readNextMessage()) {
    const directoryName = reader.currentDirectory;
    console.log("Directory:", directoryName);

    const message = reader.currentMessage;
    console.log("Subject:", message.subject);
}

reader.dispose();
console.log("All messages read successfully from the Zimbra TGZ file.");

统计 Zimbra TGZ 文件中的总项目数

您可以使用以下方法快速确定 TGZ 备份中存在多少电子邮件项: getTotalItemsCount() 方法的 TgzReader 类。

以下代码示例将展示如何在项目中实现此方法:

const asposeemail = require('@aspose/email');

const tgzFile = "ZimbraSample.tgz";
const reader = new asposeemail.TgzReader(tgzFile);

const totalCount = reader.getTotalItemsCount();
console.log(`Total items in TGZ file: ${totalCount}`);

reader.dispose();

从 Zimbra TGZ 文件保存消息及文件夹结构

exportTo() 该方法允许您在保留原始文件夹结构的情况下保存 TGZ 文件中的所有消息。这在恢复或迁移邮箱数据时非常有用。

以下代码示例演示如何使用 Aspose.Email 库从 TGZ 存档文件中提取并导出所有 Zimbra 电子邮件消息。

const asposeemail = require('@aspose/email');

const tgzFile = "ZimbraSample.tgz";
const outputDir = "Output/Zimbra/";

const reader = new asposeemail.TgzReader(tgzFile);
reader.exportTo(outputDir);

reader.dispose();
console.log(`All Zimbra messages exported to: ${outputDir}`);

从 Zimbra 备份文件导出日历和联系人

Zimbra TGZ 备份可能包含联系人和日历文件夹。您可以使用相同的方式将它们导出为 VCard (.vcf) 和 iCalendar (.ics) 格式。 exportTo() 方法。

const asposeemail = require('@aspose/email');

const tgzFile = "ZimbraBackup.tgz";
const outputPath = "Output/ZimbraData/";

const reader = new asposeemail.TgzReader(tgzFile);

// Contacts can be found in "Contacts" and "Emailed Contacts" folders.
// Calendar entries can be found in the "Calendar" folder.
reader.exportTo(outputPath);

reader.dispose();
console.log("Zimbra calendar and contacts exported successfully.");