|
@@ -2,7 +2,11 @@
|
|
|
import sys
|
|
|
import email
|
|
|
|
|
|
-txt, html = sys.argv[1:3]
|
|
|
+mailgroup = sys.argv[1]
|
|
|
+with open(f'/opt/cropswap/{mailgroup}/banner.html', 'rb') as f:
|
|
|
+ html = f.read().decode("utf-8")
|
|
|
+with open(f'/opt/cropswap/{mailgroup}/banner.txt', 'rb') as f:
|
|
|
+ txt = f.read().decode("utf-8")
|
|
|
|
|
|
m = email.message_from_bytes(sys.stdin.buffer.read())
|
|
|
|
|
@@ -13,7 +17,8 @@ INJECTED = {
|
|
|
|
|
|
def inject(m):
|
|
|
c = m.get_content_type()
|
|
|
- payload = m.get_payload()
|
|
|
+ e = m.get('Content-Transfer-Encoding','').lower()
|
|
|
+ payload = m.get_payload(decode=True).decode("utf-8")
|
|
|
if c == 'text/plain' and txt not in payload:
|
|
|
payload = payload + f"""
|
|
|
{txt}
|
|
@@ -24,7 +29,18 @@ def inject(m):
|
|
|
payload = payload.replace('</body>', f'{html}</body>')
|
|
|
else:
|
|
|
payload += f'{html}'
|
|
|
- m.set_payload(payload)
|
|
|
+
|
|
|
+ if e == 'quoted-printable':
|
|
|
+ encode = email.encoders.encode_quopri
|
|
|
+ elif e in ('7bit', '8bit'):
|
|
|
+ encode = email.encoders.encode_7or8bit
|
|
|
+ elif e == 'base64':
|
|
|
+ encode = email.encoders.encode_base64
|
|
|
+ else:
|
|
|
+ encode = email.encoders.encode_noop
|
|
|
+ m.set_payload(payload.encode("utf-8"))
|
|
|
+ encode(m)
|
|
|
+ m.set_charset("utf-8")
|
|
|
|
|
|
def visit(m):
|
|
|
c = m.get_content_type()
|