הפעל הרחבות IMAP
תמיכה בהרחבות IMAP
ה‑API של Aspose.Email תומך במגוון הרחבות של פרוטוקול IMAP. הרחבות אלו מאפשרות פעולות מתקדמות כגון זיהוי יישומי לקוח וקבלת מטא‑נתוני תיבת דואר מפורטים. למרות שלא כל שרתי הדוא"ל תומכים בתכונות אלו, רבים משירותים פופולריים כמו Gmail כן תומכים.
מאמר זה מציג כיצד להשתמש בהרחבות IMAP הבאות עם ImapClient מחלקה ב‑Aspose.Email:
-
פקודת IMAP ID
-
פקודת IMAP LIST-EXTENDED
שימוש בפקודת IMAP ID
פקודה זו מספקת משוב האם השרת תומך בהרחבת IMAP ID ומחזירה פרטי זיהוי מובנים מהשרת. זה יכול להיות שימושי ללוגינג, אבחון והתאמה של התנהגות השרת.
דוגמת הקוד שלהלן מציגה כיצד להשתמש בספריית Aspose.Email לתקשר עם שרת IMAP, ובמיוחד לקבל מידע זיהוי של השרת באמצעות פקודת ID:
import aspose.email as ae
with ae.clients.imap.ImapClient("imap.gmail.com", 993, "username", "password") as client:
# Set security options
client.security_options = ae.clients.SecurityOptions.AUTO
# Check if ID command is supported
print(client.id_supported)
# Send identification info to the server
server_identification_info1 = client.introduce_client()
server_identification_info2 = client.introduce_client(ae.clients.imap.ImapIdentificationInfo.default_value)
# Display server response
print(server_identification_info1)
print(server_identification_info2)
print(server_identification_info1.name)
print(server_identification_info1.vendor)
print(server_identification_info1.support_url)
print(server_identification_info1.version)
שימוש בפקודת IMAP LIST-EXTENDED
פקודת IMAP LIST-EXTENDED (הוגדרה ב‑RFC 5258) מאפשרת ללקוחות לקבל היררכיות תיקיות מפורטות ונתוני מטא, כגון האם לתיקיות יש תיקיות ילד. זה מועיל במיוחד ללקוחות המנהלים מבני תיבת דואר מורכבים.
דוגמת הקוד שלהלן מציגה כיצד למנות תיקיות ב‑Gmail באמצעות פקודת LIST המורחבת ולוודא אילו תיקיות מכילות תתי‑תיקיות:
import aspose.email as ae
with ae.clients.imap.ImapClient("imap.gmail.com", 993, "username", "password") as client:
folder_info_col = client.list_folders("*")
print("Extended List Supported:", client.extended_list_supported)
for folder_info in folder_info_col:
folder_name = folder_info.name
if folder_name == "[Gmail]/All Mail":
print("Has Children:", folder_info.has_children)
elif folder_name == "[Gmail]/Bin":
print("Bin has children?", folder_info.has_children)
elif folder_name == "[Gmail]/Drafts":
print("Drafts has children?", folder_info.has_children)
elif folder_name == "[Gmail]/Important":
print("Important has Children?", folder_info.has_children)
elif folder_name == "[Gmail]/Sent Mail":
print("Sent Mail has Children?", folder_info.has_children)
elif folder_name == "[Gmail]/Spam":
print("Spam has Children?", folder_info.has_children)
elif folder_name == "[Gmail]/Starred":
print("Starred has Children?", folder_info.has_children)