-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (25 loc) · 1011 Bytes
/
main.py
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
32
33
34
35
36
37
from __future__ import unicode_literals
import logging
from envparse import env
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
from imapclient import IMAPClient
env.read_envfile()
if __name__ == '__main__':
logger.info('start IMAP')
server = IMAPClient(env('HOST'), port=env('PORT', default=None), use_uid=True, ssl=env.bool('SSL', default=True))
logger.info(' [+] LOGIN')
server.login(env('USERNAME'), env('PASSWORD'))
select_info = server.select_folder('INBOX')
print('%d messages in INBOX' % select_info['EXISTS'])
messages = server.search(['NOT', 'DELETED'])
print("%d messages that aren't deleted" % len(messages))
print()
print("Messages:")
# https://tools.ietf.org/html/rfc3501.html#section-6.4.5
response = server.fetch(messages, ['FLAGS', 'ENVELOPE', ])
for msgid, data in response.iteritems():
print(''' ---ID %d ---
HEADER: %s
flags=%s''' % (msgid, data[b'ENVELOPE'], data[b'FLAGS']))