-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreatEmailText.py
More file actions
141 lines (110 loc) · 4.32 KB
/
TreatEmailText.py
File metadata and controls
141 lines (110 loc) · 4.32 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from Npp import editor
import re
# Wim Gielis
# Apr. 2025
#
# TreatEmailText script (Alt-a):
# - Select all the text in the selected file, it is coming from a copy/paste of email messages
# - Remove unnecessary text like the signature and the timestamp of sending the email
# - Also, if wanted:
# * delete all lines that contain the word Wim.
# * for every line that is ONLY a space character and nothing else, in front we add an arrow
# * the cursor is put after the first arrow, for quick editing.
# Get the editor object
editor.beginUndoAction()
clean_up_emails = notepad.prompt("Do you want to clean up the email text ? (YN)", "Clean up email text", "Y")
if clean_up_emails.upper() == 'Y':
try:
# Select all text
editor.selectAll()
all_text = editor.getText()
# Split into lines and process
lines = all_text.splitlines()
new_lines = []
for line in lines:
# Skip certain lines
if line == 'Best regards / Beste groeten,':
continue
if line == '(geen onderwerp)':
continue
if line == 'Wim Gielis':
continue
if line.startswith('Sent:'):
continue
if 'IBM Champion' in line:
continue
if 'Excel MVP' in line:
continue
if line == 'https://www.wimgielis.com':
continue
if 'Wim Gielis <wim.gielis@gmail.com>' in line:
continue
if 'minuten geleden' in line:
continue
if 'uur geleden' in line:
continue
if '1 dag geleden' in line:
continue
if 'dagen geleden' in line:
continue
if line.strip() == '':
continue
if line.strip() == 'Inbox':
continue
if line == '------':
continue
if re.compile(r"Op .* \d{4} om \d{1,2}:\d{1,2} schreef").match(line):
continue
if line == 'aan mij':
line = ''
new_lines.append(line)
new_text = '\r\n'.join(new_lines)
editor.setText(new_text)
finally:
editor.endUndoAction()
add_arrows = notepad.prompt("Do you want to add arrows to the text ? (YN)", "Add arrows", "N")
if add_arrows.upper() == 'Y':
try:
# Select all text
editor.selectAll()
all_text = editor.getText()
# Split into lines and process
lines = all_text.splitlines()
new_lines = []
for line in lines:
# Skip certain lines
# if 'Wim' in line:
# continue
if line == 'Neil':
continue
# A line with only a space gets an arrow
# But only when there is already text (the greeting is ignored and does not need an arrow)
elif line == ' ':
if new_lines:
new_lines.append('==> ')
elif line.strip() == '':
if new_lines:
new_lines.append(line)
else:
new_lines.append(line)
# Add an extra arrow, unless the last line contains the word 'hopefully'
if not (new_lines and any(keyword in lines[-1].strip().lower() for keyword in ['hopefully', 'neil'])):
new_lines = new_lines + ['', '==> ']
# A greeting
new_lines = ["Hi Neil,", "", "I hope you're good.", ""] + new_lines
# Replace text
new_lines = [l.replace(". ", ". ") for l in new_lines]
new_lines = [l.replace("? ", "? ") for l in new_lines]
new_lines = [l.replace("! ", "! ") for l in new_lines]
# Join the processed lines back together
new_text = '\r\n'.join(new_lines)
# Replace the content in the editor
editor.setText(new_text)
# Find the position of the first arrow and move the cursor there
arrow_pos = new_text.find('==> ')
if arrow_pos != -1:
editor.gotoPos(arrow_pos + 6)
else:
editor.gotoPos(0)
finally:
editor.endUndoAction()