-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetMessage.py
More file actions
26 lines (21 loc) · 822 Bytes
/
getMessage.py
File metadata and controls
26 lines (21 loc) · 822 Bytes
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
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
print("User not authentiated")
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
threads = GMAIL.users().threads().list(userId='me').execute().get('threads', [])
for thread in threads:
tdata = GMAIL.users().threads().get(userId='me', id=thread['id']).execute()
nmsgs = len(tdata['messages'])
if nmsgs > 2:
msg = tdata['messages'][0]['payload']
subject = ''
for header in msg['headers']:
if header['name'] == 'Subject':
subject = header['value']
break
if subject:
print('%s (%d msgs)' % (subject, nmsgs))