将 MBOX 转换为 PST
Contents
[
Hide
]
将 MBOX 转换为 PST。基础转换
当从 Mozilla Thunderbird 等客户端迁移邮件数据到 Microsoft Outlook 时,通常需要将 MBOX 存档转换为 PST(个人存储表)格式。PST 格式是 Outlook 和 Exchange 的原生格式,支持文件夹结构和基于 MAPI 的消息处理等高级功能。
Aspose.Email 允许将消息从 MBOX 文件传输到 Outlook 兼容的存储,并完全控制转换过程。下面的示例加载 MBOX 存档中的消息并将其保存到结构化的 Outlook 数据文件中:
- 使用以下方式初始化 MBOX 阅读器 MboxStorageReader.create_reader().
- 创建一个带有 PersonalStorage.create().
- 添加邮件文件夹——例如 “收件箱”——到存储中。
- 循环遍历消息,将每个消息转换为 MapiMessage 并将其插入到文件夹中。
from aspose.email.mapi import MapiMessage
from aspose.email.storage.mbox import MboxStorageReader, MboxLoadOptions
from aspose.email.storage.pst import PersonalStorage, FileFormatVersion, StandardIpmFolder
# Load the source file
mbox = MboxStorageReader.create_reader("source.mbox", MboxLoadOptions())
# Create the destination Outlook data file
with PersonalStorage.create("converted.pst", FileFormatVersion.UNICODE) as personal_storage:
# Add a folder to hold the imported messages
folder_info = personal_storage.create_predefined_folder("Inbox", StandardIpmFolder.INBOX)
# Process each message from the source file
for eml in mbox.enumerate_messages():
msg = MapiMessage.from_mail_message(eml)
folder_info.add_message(msg)
在保留或移除签名的情况下将 MBOX 转换为 PST
在将 MBOX 文件转换为 PST 格式时,您可能希望从消息中排除数字签名,以获得更干净的输出或兼容性。Aspose.Email 提供了一个便利选项,可在转换过程中使用以下方式删除这些签名: remove_signature 属性的 MboxToPstConversionOptions 类。
下面的示例演示如何在 Python 项目中启用此选项:
import aspose.email as ae
personalStorage = ae.storage.pst.PersonalStorage.create("target.pst", ae.storage.pst.FileFormatVersion.UNICODE)
conversion_options = ae.storage.MboxToPstConversionOptions()
conversion_options.remove_signature = True
ae.storage.MailStorageConverter.mbox_to_pst( ae.storage.mbox.MboxrdStorageReader("source.mbox", ae.storage.mbox.MboxLoadOptions()), personalStorage, "Inbox", conversion_options)