-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinbox_highlanderer.py
42 lines (29 loc) · 1.35 KB
/
inbox_highlanderer.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
# ---------------------------------------------------------------------------------------------------------------------#
# inbox_highlanderer.py
#
# This module removes all duplicate emails from the postorder inbox.
#
# ---------------------------------------------------------------------------------------------------------------------#
import win32com.client
def main():
# This block opens Outlook and defines the required folders.
outlook = win32com.client.Dispatch('Outlook.Application')
mapi = outlook.GetNamespace('MAPI')
inbox = mapi.GetDefaultFolder(6).Folders['Postorders']
archive = mapi.Folders.Item(3).Folders['Archive']
# This gets a list of all emails in the Postorders folder and sorts them in chronological order, oldest-first.
messages = inbox.Items
messages.Sort("[ReceivedTime]", Descending=False)
# This terminates the module if there are no emails.
if not len(messages):
# print('No emails!')
return
# This block checks the subject list for the current email's subject, archives the email if it's a duplicate, and
# adds its subject to the list if it isn't.
subject_list = []
for item in messages:
if item.Subject in subject_list:
item.Move(archive)
else:
subject_list.append(item.Subject)
main()