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)