使用 PST 密码保护属性

Microsoft Outlook 允许用户使用密码保护 PST 文件以限制访问。Aspose.Email 能检测 PST 文件的密码保护状态。

本文涵盖以下内容:

  • 检查 PST 文件密码保护
  • 读取受密码保护的 PST 文件
  • 在受密码保护的 PST 中验证密码
  • 在 PST 文件中添加/更改/移除密码

检查 PST 文件密码保护

要检查 PST 文件是否受密码保护,请使用该类的 is_password_protected 方法。 MessageStore 类,如以下代码示例所示:

import aspose.email as ae

pst = ae.storage.pst.PersonalStorage.from_file("my.pst")

print(f"The storage is password protected - {pst.store.is_password_protected}")

读取受密码保护的 PST 文件

您可以像读取普通未加密的 PST 文件一样读取受密码保护的文件。以下代码片段允许您访问每个单独的消息,以便进一步处理:

import aspose.email as ae

pst = ae.storage.pst.PersonalStorage.from_file("my.pst")

for folder in pst.root_folder.get_sub_folders():
    for msg in folder.enumerate_messages():
    # do something

验证 PST 密码

要检查 PST 文件中的密码是否有效,Aspose.Email 提供了该类的 is_password_valid(password) 方法。 MessageStore 类。它接受字符串密码作为参数,若密码正确返回 True,否则返回 False。

以下代码片段演示了 is_password_valid(password) 方法的使用:

import aspose.email as ae

pst = ae.storage.pst.PersonalStorage.from_file("my.pst")

print(f"Password is valid - {pst.store.is_password_valid('Password1')}")

添加、修改或移除 PST 密码

change_password(password) 方法属于 MessageStore 类用于在 PST 文件中操作密码。以下代码示例展示了如何添加、更改或移除密码:

import aspose.email as ae

pst = ae.storage.pst.PersonalStorage.create("SetPasswordOnPST_out.pst", ae.storage.pst.FileFormatVersion.UNICODE)
# Add or change the password
password = "Password1"
pst.store.change_password(password)
# Remove the password
pst.store.change_password(None)