-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakespam.py
70 lines (61 loc) · 1.62 KB
/
makespam.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time
import textwrap
import re
import html
import pyperclip
TEMPLATE = '''
<article>
{selectheaders}
<details>
<summary>Headers</summary>
<pre>
{headers}
</pre>
</details>
<hr/>
{body}
</article>
'''
print('Copy the body...')
pyperclip.copy('')
while pyperclip.paste() == '':
time.sleep(0.5)
body = html.escape(pyperclip.paste())
body = body.replace('\r', '')
body = [line.strip() for line in body.splitlines()]
body = [line for line in body if line]
body = ['<p>' + line + '</p>' for line in body]
body = '\n'.join(body)
body = textwrap.indent(body, ' ')
print('Copy the headers...')
pyperclip.copy('')
while pyperclip.paste() == '':
time.sleep(0.5)
headers = html.escape(pyperclip.paste())
headers = headers.replace('\r', '')
headers = [line.rstrip() for line in headers.splitlines()]
headers = [line for line in headers if line]
headers = '\n'.join(headers)
keyed = {}
for line in headers.splitlines():
key = re.search(r'^([A-Za-z\-]+): ', line, flags=re.MULTILINE)
if key is None:
continue
key = key.group(1)
line = line.replace(key + ':', '<p><b>' + key + '</b>:')
keyed[key] = line
selectheaders = [
keyed.get('From'),
keyed.get('Reply-To'),
keyed.get('Return-Path'),
keyed.get('To'),
keyed.get('Bcc'),
keyed.get('Subject'),
keyed.get('Date'),
]
selectheaders = [s for s in selectheaders if s]
selectheaders = '\n'.join(selectheaders)
selectheaders = textwrap.indent(selectheaders, ' ')
spam = TEMPLATE.format(body=body, headers=headers, selectheaders=selectheaders)
print(spam)
pyperclip.copy(spam)