עבודה עם קבצי PST גדולים
Contents
[
Hide
]
הביצועים עשויים להיפגע בעת עיבוד קבצי PST גדולים. הפתרונות הבאים יעזרו לך לשפר את ביצועי האפליקציה שלך כאשר אתה מעבד קבצים גדולים.
העדיף את השיטות המחשבות כאשר עוברים על התיקיות או ההודעות של PST.
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for message_info in folder.enumerate_messages():
# Do something with the message
print(message_info.subject)
העדף MessageInfo לגישה למאפייני ההודעה הבסיסיים.
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for message_info in folder.enumerate_messages():
print(f"Subject: {message_info.subject}")
print(f"To: {message_info.display_to}")
print(f"Importance: {message_info.importance}")
print(f"Message Class: {message_info.message_class}")
הימנע משימוש ב‑
extract_message או enumerate_mapi_messages לכל ההודעות אלא אם נדרשת גישה לכל המאפיינים שלהן.
שקול להשתמש ב-
enumerate_messages_entry_id כדי לקבל את כל מזהי ההודעות שבתיקייה.
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for entry_id in folder.enumerate_messages_entry_id():
# Use the id to retrieve a single property (extract_property),
# extract a MapiMessage (extract_message),
# extract the message attachments (extract_attachments),
# or save the message to a stream (save_message_to_stream).
pass
שקול להשתמש ב-
extract_property לקריאת מאפיין יחיד שחסר ב‑ MessageInfo.
import base64
from aspose.email.mapi import KnownPropertyList
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for msg_id in folder.enumerate_messages_entry_id():
transport_message_headers = pst.extract_property(
base64.b64decode(msg_id),
KnownPropertyList.TRANSPORT_MESSAGE_HEADERS.tag)
שקול להשתמש ב-
extract_attachments אם נדרשים רק הקבצים המצורפים.
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for msg_id in folder.enumerate_messages_entry_id():
attachments = pst.extract_attachments(msg_id)
השתמש סינון מבוסס חיפוש כדי לקבל רק את ההודעות הדרושות לך.
from aspose.email.mapi import MapiMessageFlags
from aspose.email.storage.pst import PersonalStorage, PersonalStorageQueryBuilder
with PersonalStorage.from_file("storage.pst") as pst:
builder = PersonalStorageQueryBuilder()
# Unread messages
builder.has_no_flags(MapiMessageFlags.READ)
for folder in pst.root_folder.enumerate_folders():
unread = folder.get_contents(builder.get_query())
שקול להשתמש ב-
save_message_to_stream כאשר יש צורך לשמור את ההודעות מ‑PST.
במקום להשתמש ב-
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for entry_id in folder.enumerate_messages_entry_id():
msg = pst.extract_message(entry_id)
msg.save("message.msg")
השתמש:
from aspose.email.storage.pst import PersonalStorage
with PersonalStorage.from_file("storage.pst") as pst:
for folder in pst.root_folder.enumerate_folders():
for entry_id in folder.enumerate_messages_entry_id():
with open("message.msg", "wb") as stream:
pst.save_message_to_stream(entry_id, stream)
Aspose.Email עבור .NET מציעה בנוסף פעולות PST אסינכרוניות —
CreateAsync, FromFileAsync, MergeWithAsync ו SplitIntoAsync. שיטות אלו מבוססות על מטלות .NET ואסימוני ביטול ואינן חושפות ב‑Aspose.Email עבור Python דרך .NET; השתמש במקבילות הסינכרוניות שלהן במקום זאת.