-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoUnsubscriber.py
More file actions
28 lines (26 loc) · 1.1 KB
/
autoUnsubscriber.py
File metadata and controls
28 lines (26 loc) · 1.1 KB
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
#! python3
# a program that scans through your email account, finds all the unsubscribe links in all your emails,
# and automatically opens them in a browser.
import webbrowser, imapclient, imaplib, pyzmail, bs4
imaplib.MAXLINE = 10000000
imapObj = imapclient.IMAPClient('imap.gmail.com', ssl=True)
print('logging into your gmail')
imapObj.login('boluwatifelekeoduoye@gmail.com', 'bajtcryceihnsxuj')
imapObj.select_folder('INBOX', readonly=True)
print('searching your messages')
UIDs = imapObj.gmail_search('unsubscribe')
rawMessages = imapObj.fetch(UIDs, ['BODY[]'])
for i in range(7):
try:
message = pyzmail.PyzMessage.factory(rawMessages[UIDs[i]][b'BODY[]'])
if message.html_part != None:
html = message.html_part.get_payload().decode(message.html_part.charset)
print('searching for unsubscribe link...')
htmlSoup = bs4.BeautifulSoup(html, 'html.parser')
linkElem = htmlSoup.select('a')
link = linkElem.get('href')
webbrowser.open(link)
else:
continue
except:
continue