File: example.py

package info (click to toggle)
python-imapclient 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 668 kB
  • sloc: python: 5,355; sh: 14; makefile: 11
file content (26 lines) | stat: -rw-r--r-- 703 bytes parent folder | download
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
# List number of messages in INBOX folder
# and print details of the messages that are not deleted

from imapclient import IMAPClient

HOST = "imap.host.com"
USERNAME = "someuser"
PASSWORD = "secret"

server = IMAPClient(HOST)
server.login(USERNAME, PASSWORD)

select_info = server.select_folder("INBOX")
print("%d messages in INBOX" % select_info[b"EXISTS"])

messages = server.search(["NOT", "DELETED"])
print("%d messages that aren't deleted\n" % len(messages))

print("Messages:")
response = server.fetch(messages, ["FLAGS", "RFC822.SIZE"])
for msgid, data in response.items():
    print(
        "   ID %d: %d bytes, flags=%s" % (msgid, data[b"RFC822.SIZE"], data[b"FLAGS"])
    )

server.logout()