การอ่านไฟล์ PST/OST ที่เสียหาย

การอ่านไฟล์ PST/OST ที่เสียหาย

ในบางกรณีไฟล์ PST หรือ OST อาจไม่สามารถเข้าถึงได้เนื่องจากความเสียหายหรือบิดเบือน. เมื่อเกิดเช่นนั้น Outlook อาจไม่สามารถเปิดไฟล์ได้ ทำให้ยากต่อการดึงอีเมลสำคัญและข้อมูลอื่นๆ ของกล่องจดหมาย.

Aspose.Email มี API ที่ให้คุณสแกนและดึงข้อความที่ไม่มีความเสียหายจากไฟล์ PST ที่เสียหายโดยใช้ ID ของข้อความและโฟลเดอร์.

เมธอดต่อไปนี้ของ PersonalStorage คลาสมีความสำคัญต่อการกู้คืนข้อมูลจากไฟล์ PST ที่เสียหาย:

  • ดึง ID ของข้อความและโฟลเดอร์:

    find_messages(parent_entry_id) - ดึงรายการ ID ของข้อความภายในโฟลเดอร์ที่ระบุ.

    find_subfolders(parent_entry_id) - ได้รายการ ID ของโฟลเดอร์ย่อยภายในโฟลเดอร์ที่กำหนด.

  • เข้าถึงข้อความและโฟลเดอร์โดยใช้ ID ของพวกเขา:

    extract_message(entry_id) - ดึงข้อความจากไฟล์ PST โดยใช้ entry ID.

    get_folder_by_id(entry_id) - ดึงโฟลเดอร์จากไฟล์ PST โดยใช้ entry ID.

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีนำทางผ่านไฟล์ PST ที่อาจเสียหาย, ดึงข้อความที่ไม่ได้รับความเสียหาย, และสำรวจโฟลเดอร์ย่อย:

import aspose.email as ae

def explore_corrupted_pst(pst, root_folder_id):
    message_id_list = pst.find_messages(root_folder_id)

    for message_id in message_id_list:
        try:
            msg = pst.extract_message(message_id)
            print("- " + msg.subject)
        except Exception as e:
            print("Message reading error. Entry id: " + message_id)

    folder_id_list = pst.find_subfolders(root_folder_id)

    for sub_folder_id in folder_id_list:
        if sub_folder_id != root_folder_id:
            try:
                subfolder = pst.get_folder_by_id(sub_folder_id)
                print(subfolder.display_name)
            except Exception as e:
                print("Message reading error. Entry id: " + sub_folder_id)

            explore_corrupted_pst(pst, sub_folder_id)


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

explore_corrupted_pst(pst, pst.root_folder.entry_id_string)