如何在 Java 中将 MBOX 转换为 PST 文件

这个简短的主题是关于如何MBOX 转换为 PST 文件在 Java 通过涵盖设置环境的所有细节和执行任务的完整程序流程。借助几行代码,您可以轻松地将 MBOX 保存为 Java 中的 PST 文件**,并在任何 Java 支持的环境(包括 Windows、macOS 和 Linux)中使用此应用程序。

在 Java 中将 MBOX 转换为 PST 文件的步骤

  1. 设置开发环境以包含来自 Maven 存储库的 Aspose.Email for Java JAR 文件
  2. 使用 PersonalStorage 类实例在磁盘上创建 PST 存储文件
  3. 在 PST 中添加自定义收件箱文件夹
  4. 使用 MboxrdStorageReader 类并提供 MBOX 加载选项从磁盘打开源 MBOX 文件
  5. 遍历 MBOX 中的每条消息并将其插入所需的 PST 文件夹中

上述步骤提供了使用 Java 从 MBOX 创建 PST 的详细信息,通过使用 PersonalStorage 类实例创建一个空的 PST 存储文件以及其中的收件箱文件夹来开始该过程。最后,使用 MailMessage 类对 MBOX 文件中的消息进行迭代,并在使用 MboxrdStorageReader 类对象从磁盘打开源 MBOX 文件后保存在 PST 文件夹中。

使用 Java 从 MBOX 创建 PST 的代码

import com.aspose.email.FileFormatVersion;
import com.aspose.email.FolderInfo;
import com.aspose.email.License;
import com.aspose.email.MailMessage;
import com.aspose.email.MapiConversionOptions;
import com.aspose.email.MapiMessage;
import com.aspose.email.MboxLoadOptions;
import com.aspose.email.MboxrdStorageReader;
import com.aspose.email.PersonalStorage;
public class MBOXToPSTConverter {
public static void main(String[] args) throws Exception { // Throw exception in case of conversion error
String filePath = "C:/TestData/";
// Instantiate the license to convert MBOX to a PST File
License LicenseMboxToPST = new License();
LicenseMboxToPST.setLicense(filePath + "Conholdate.Total.Product.Family.lic");
// Create the output PST file on the disk
PersonalStorage desPersonalStorage = PersonalStorage.create(filePath + "OutputFile.pst", FileFormatVersion.Unicode);
// Include a subfolder inside the PST
FolderInfo inbox = desPersonalStorage.getRootFolder().addSubFolder("Inbox");
// Set the MBOX loading options
MboxLoadOptions mboxLoadOptions = new MboxLoadOptions();
mboxLoadOptions.setLeaveOpen(false);
// Load the source MBOX file
MboxrdStorageReader mboxReader = new MboxrdStorageReader(filePath + "srcInputFile.mbox", mboxLoadOptions);
// Read the MBOX Messages
MailMessage itrMessage = mboxReader.readNextMessage();
MapiMessage mapiMsg;
// Iterate through the MBOX messages and insert them in a selected PST sub-folder
while (itrMessage != null){
mapiMsg = MapiMessage.fromMailMessage(itrMessage, MapiConversionOptions.getUnicodeFormat());
inbox.addMessage(mapiMsg);
itrMessage = mboxReader.readNextMessage();
}
}
}

这个例子展示了开发一个 MBOX 到 PST 转换器基于 Java 的 API 可以在简单 API 调用的帮助下使用。这是一个简单的过程,第一步在磁盘上创建一个 PST 存储文件及其各自的收件箱文件夹。随后,MBOX 文件消息在从磁盘加载后被迭代并保存在 PST 文件夹中。

在这个例子中,我们探索了使用简单的 API 接口创建使用 Java MBOX 到 PST 转换器应用程序是多么容易。如果您有兴趣了解如何使用 Java 将 PST 文件拆分为多个 PST 文件,请参阅 如何使用 Java 拆分 PST 文件 上的文章。

 简体中文