-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist_drafts.py
More file actions
31 lines (25 loc) · 1.19 KB
/
Copy pathlist_drafts.py
File metadata and controls
31 lines (25 loc) · 1.19 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
29
30
31
import json
import logging
from src.google_auth import get_credentials
from googleapiclient.discovery import build
logging.basicConfig(level=logging.ERROR)
creds = get_credentials()
service = build('gmail', 'v1', credentials=creds)
drafts = service.users().drafts().list(userId='me', maxResults=1).execute().get('drafts', [])
for d in drafts:
draft = service.users().drafts().get(userId='me', id=d['id'], format='full').execute()
msg = draft.get('message', {})
headers = msg.get('payload', {}).get('headers', [])
print("--- DRAFT HEADERS ---")
for h in headers:
if h['name'] in ('From', 'To', 'Subject', 'Message-ID', 'In-Reply-To', 'References'):
print(f"{h['name']}: {h['value']}")
thread_id = msg.get('threadId')
print("--- LAST MSG IN THREAD HEADERS ---")
thread = service.users().threads().get(userId='me', id=thread_id).execute()
last_msg = thread.get('messages', [])[-1]
last_headers = last_msg.get('payload', {}).get('headers', [])
for h in last_headers:
if h['name'] in ('From', 'To', 'Subject', 'Message-ID', 'In-Reply-To', 'References'):
print(f"{h['name']}: {h['value']}")
print("----------------------")