"""
- footer = f"""FORWARDED | Notice: This is a automatically forwarded email, which means it may contains something bad. You shouldn't reply directly to this email, it will never reach your destination! | """
+ header = f"""Forwarded Email {'' if is_html else 'This email is plain text, it may have display issues '} | From: {from_name} <{from_address}> To: {to_name} <{to_address}> Subject: {original_subject} |
FORWARDED | Notice: This is a automatically forwarded email, which means it may contains something bad. You shouldn't reply directly to this email, it will never reach your destination! | """
return header + content + footer
def load_config(config_file='config.json'):
@@ -133,7 +134,12 @@ def forward_emails(account_config, emails, logger):
logger.error(f"Failed to extract body from email {email_id}")
continue
- html_content = add_mask(original_msg, body)
+ is_html = bool(re.compile(r'<[^>]+>').search(body))
+
+ if not is_html:
+ body = body.replace('\n', ' ')
+
+ html_content = add_mask(original_msg, body, is_html)
msg.attach(MIMEText(html_content, 'html'))
for attachment in attachments:
diff --git a/template.html b/template.html
index c6b276e..a0c4bcb 100644
--- a/template.html
+++ b/template.html
@@ -1,71 +1,78 @@
-
-
-
-
- Forwarded Email
- |
-
- From: {from_name} <{from_address}>
- To: {to_name} <{to_address}>
- Subject: {original_subject}
- |
-
-
-
-
-
-
-
-
- FORWARDED
- |
-
- Notice:
- This is a automatically forwarded email, which means it may contains something bad.
- You shouldn't reply directly to this email, it will never reach your destination!
- |
-
-
-
+
+
+
+
+
+
+
+ Forwarded Email
+
+ |
+
+ From: {from_name} <{from_address}>
+ To: {to_name} <{to_address}>
+ Subject: {original_subject}
+ |
+
+
+
+
+
+
+
+
+ FORWARDED
+ |
+
+
+ Notice:
+
+
+ This is a automatically forwarded email, which means it may
+ contains something bad.
+
+
+ You shouldn't reply directly to this email, it will never reach
+ your destination!
+
+ |
+
+
+
+
+
|