-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_gmail.py
48 lines (43 loc) · 1.86 KB
/
process_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
42
43
44
45
46
47
48
#!/usr/bin/env python
import os
from inbox import gmail
from tasks import todotxt
from notes import dropbox
todotxt_path = os.path.join(dropbox.get_dropbox_path(), '@Todo', 'todo.txt')
r = input('Have you moved all interesting mails to "Action Support"? [y] ')
if not r.strip().lower() or r.strip().lower()[0] == 'y':
print('Processing Gmail emails...')
m = gmail.Mailbox()
with todotxt.TodoTxt(todotxt_path) as t:
for msg in m.process_action_support():
# msg = (subject, snippet, date, perma_link, item)
# check if ref is present in any existing tasks
referenced_task = t.check_for_ref_in_tasks(msg[3])
# if task is not present in list, prompt
if not isinstance(referenced_task,int):
print()
print('Date: {}'.format(msg[2]))
print('Subject: {}'.format(msg[0]))
print('Snippet: {}...'.format(msg[1]))
# if NOT, process it
r = input('Do you want to add a task for this email? [y] ')
if not r.strip().lower() or r.strip().lower()[0] == 'y':
t.add_task_with_unique_ref(msg[3])
elif r.strip().lower()[0] == 'q':
break
else:
r = input('Should we move this email to the archive then? [n] ')
if not r.strip().lower():
pass
elif r.strip().lower()[0] == 'y':
m.archive_message(msg[4])
else:
pass
else:
# if it is present, echo as such and return
print('Email is already referenced in {}'.format(t.tasks[referenced_task]))
print()
print(t)
print('Reviewing Gmail links to check if resolved...')
else:
print('Processing aborted.')