-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
32 lines (25 loc) · 1.06 KB
/
Copy pathrun.py
File metadata and controls
32 lines (25 loc) · 1.06 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
import win32com.client
import os
import sys
if getattr(sys, 'frozen', False):
dirname = os.path.normpath((os.path.dirname(sys.executable)))
elif __file__:
dirname = os.path.normpath(os.path.dirname(__file__))
mail_path = os.path.join(dirname, 'mails')
if not os.path.exists(mail_path):
input('Creating directory called mails. Put .msg files here and run this program again. Press any key to close')
os.makedirs(mail_path)
else:
reletive_files = os.listdir(mail_path)
files = [os.path.join(mail_path, f) for f in reletive_files]
print(files)
for file in files:
if file.endswith(".msg"):
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(file)
att = msg.Attachments
for i in att:
attachment_path = os.path.join(dirname, 'attachments')
if not os.path.exists(attachment_path):
os.makedirs(attachment_path)
i.SaveAsFile(os.path.join(attachment_path, i.FileName))