summaryrefslogtreecommitdiffstats
path: root/debian/tests/usage/pop3
blob: 00b1657495758f12ab0a9e28352cf9175f5e0162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python3
import poplib

print("Testing POP3")
print("Connecting")
client = poplib.POP3('localhost')
client.set_debuglevel(2)

print("Checking for STARTTLS capability")
assert 'STLS' in client.capa()

client.stls()

print("Logging in")
client.user('dep8')
client.pass_('test')

print("Listing INBOX")
res, data, _ = client.list()
assert res.startswith(b'+OK')

print("Fetching and verifying test message")
for entry in data:
    _id, _ = entry.split(maxsplit=1)
    res, body, _ = client.retr(int(_id))
    if b'Subject: DEP-8 test' in body:
        break
else:
    raise AssertionError("Test message not found")

print("Done")