-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail_pull2.py
42 lines (31 loc) · 979 Bytes
/
mail_pull2.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
38
39
import imaplib
def get_mail():
# Create conn to G-Mail acc (spec. the PINGPLOTTER inbox)
m = imaplib.IMAP4_SSL('imap.gmail.com')
m.login('[email protected]', 'p4ssw0rd')
m.select("PINGPLOTTER")
# search through all mail in inbox
typ, data = m.search(None, 'ALL')
for num in data[0].split():
data = m.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT)])')
return data
# Close connection + logout
m.close()
m.logout()
def clean_data():
# Sanitize data to send
dirty_text = get_mail()
subject = dirty_text[1][0][1]
print(subject)
return subject
def wipe_mailbox():
m = imaplib.IMAP4_SSL('imap.gmail.com')
m.login('[email protected]', 'p4ssw0rd')
m.select("PINGPLOTTER")
typ, data = m.search(None, 'ALL')
for num in data[0].split():
data = m.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT)])')
m.store(num, '+FLAGS', '\\Deleted')
m.expunge()
m.close()
m.logout()