50 lines
1.6 KiB
Python
Executable File
50 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Print protocol capability and mailbox diagnostics for a test account."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import imaplib
|
|
import os
|
|
import poplib
|
|
import ssl
|
|
|
|
|
|
host = os.environ.get("BONGO_TEST_HOST", "127.0.0.1")
|
|
user = os.environ.get("BONGO_TEST_USER", "test2")
|
|
password = os.environ.get("BONGO_TEST_PASSWORD", "")
|
|
if not password:
|
|
raise SystemExit("set BONGO_TEST_PASSWORD for the disposable account")
|
|
|
|
context = ssl.create_default_context()
|
|
if os.environ.get("BONGO_TEST_INSECURE_TLS") == "1":
|
|
context.check_hostname = False
|
|
context.verify_mode = ssl.CERT_NONE
|
|
|
|
plain_imap = imaplib.IMAP4(
|
|
host, int(os.environ.get("BONGO_TEST_IMAP_PORT", "143")), timeout=10)
|
|
print("IMAP welcome", plain_imap.welcome)
|
|
print("IMAP capabilities", plain_imap.capabilities)
|
|
print("IMAP CAPABILITY", plain_imap.capability())
|
|
plain_imap.logout()
|
|
|
|
imap = imaplib.IMAP4_SSL(
|
|
host, int(os.environ.get("BONGO_TEST_IMAPS_PORT", "993")),
|
|
ssl_context=context, timeout=10)
|
|
imap.login(user, password)
|
|
print("IMAPS capabilities", imap.capabilities)
|
|
print("IMAPS LIST", imap.list())
|
|
print("IMAPS SELECT", imap.select("INBOX", readonly=True))
|
|
print("IMAPS SEARCH ALL", imap.search(None, "ALL"))
|
|
status, data = imap.search(None, "ALL")
|
|
if status == "OK" and data and data[0].split():
|
|
identifier = data[0].split()[-1]
|
|
print("IMAPS FETCH", identifier, imap.fetch(
|
|
identifier, "(BODY.PEEK[HEADER.FIELDS (FROM TO SUBJECT)])"))
|
|
imap.logout()
|
|
|
|
pop = poplib.POP3(
|
|
host, int(os.environ.get("BONGO_TEST_POP3_PORT", "110")), timeout=10)
|
|
print("POP3 welcome", pop.getwelcome())
|
|
print("POP3 CAPA", pop.capa())
|
|
pop.quit()
|