-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseEmail.py
More file actions
39 lines (35 loc) · 1.5 KB
/
Copy pathparseEmail.py
File metadata and controls
39 lines (35 loc) · 1.5 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
36
37
38
39
from shutil import copy
import email
import os
def get_macros():
with open("/home/a/projects/attr-doc/result/found_macros.txt", "r") as filename:
# filter commented lines
macros = [line for line in filename.readlines() if not line.startswith('#')]
macros = [macro.split()[0] for macro in macros]
macros.append('sysfs')
return macros
mailDir = "/home/a/mail/aishpant/"
def get_files():
lkmlMailDir = mailDir + "LKML/"
attrDocDir = mailDir + "attrDoc/new/"
macros = get_macros()
count = 1
for dirpath, dirnames, files in os.walk(lkmlMailDir):
dirnames[:] = [d for d in dirnames if d in ['new']]
for fname in files:
with open(os.path.join(dirpath, fname), "r", encoding='ISO-8859-1') as auto:
msg = email.message_from_file(auto)
if msg.is_multipart():
path = os.path.realpath(auto.name)
print ("Multipart message, skipping..." + path)
continue
msg = msg.get_payload().split('\n')
msg_lines = [line.strip('+-\t') for line in msg if line.startswith('+') or line.startswith('-')]
res = [line for macro in macros for line in msg_lines if macro in line]
if res:
print (res)
source = os.path.realpath(auto.name)
copy(source, attrDocDir)
print ("Copying message #" + str(count))
count += 1
get_files()