forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmark_emails.py
More file actions
Latest commit
35 lines (31 loc) · 1.26 KB
/
Copy pathmark_emails.py
File metadata and controls
35 lines (31 loc) · 1.26 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
32
33
34
35
fromcommonimportgmail_authenticate, search_messages
defmark_as_read(service, query):
messages_to_mark=search_messages(service, query)
returnservice.users().messages().batchModify(
userId='me',
body={
'ids': [ msg['id'] formsginmessages_to_mark ],
'removeLabelIds': ['UNREAD']
}
).execute()
defmark_as_unread(service, query):
messages_to_mark=search_messages(service, query)
returnservice.users().messages().batchModify(
userId='me',
body={
'ids': [ msg['id'] formsginmessages_to_mark ],
'addLabelIds': ['UNREAD']
}
).execute()
if__name__=="__main__":
importargparse
parser=argparse.ArgumentParser(description="Marks a set of emails as read or unread")
parser.add_argument('query', help='a search query that selects emails to mark')
parser.add_argument("-r", "--read", action="store_true", help='Whether to mark the message as read')
parser.add_argument("-u", "--unread", action="store_true", help='Whether to mark the message as unread')
args=parser.parse_args()
service=gmail_authenticate()
ifargs.read:
mark_as_read(service, args.query)
elifargs.unread:
mark_as_unread(service, args.query)