-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_gmail.py
41 lines (32 loc) · 1.14 KB
/
verify_gmail.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
40
41
import imaplib
import email
import subprocess
username = "someone@gmail.com" # USERNAME HERE
password = "somepassword" # PASSWORD HERE
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(username, password)
# retrieve a list of the mailboxes and select one
result, mailboxes = mail.list()
mail.select("INBOX")
result, numbers = mail.uid('search', None, 'UNSEEN')
uids = numbers[0].split()
# set flag seen for unseen mails
for i in uids:
mail.uid('store', i, '+FLAGS','\SEEN')
if len(uids) > 0:
result, messages = mail.uid('fetch', ','.join(uids[-10:]), '(BODY.PEEK[HEADER])')
mail_sender = []
mail_subject = []
for _, message in messages[::2]:
msg = email.message_from_string(message)
email_subject = msg['subject']
email_from = msg['from']
mail_sender.append(email_from)
if len(email_subject) > 20:
email_subject = email_subject[:65]
mail_subject.append(email_subject)
cmd = 'zenity --info --width=500 --title="You have a massage from: {}"'\
.format(mail_sender[0]).replace("<", "").replace(">", "")\
+' --text="Subject: {}"'.format("".join(x.split()[0] for x in mail_subject))
subprocess.call(cmd, shell=True)
else:pass