use decode_text() in add_header()
This commit is contained in:
parent
091ff3ad2c
commit
fb8a43fd5d
|
@ -763,36 +763,30 @@ def add_header(msg: Message, text_header, html_header) -> Message:
|
||||||
payload = msg.get_payload()
|
payload = msg.get_payload()
|
||||||
if type(payload) is str:
|
if type(payload) is str:
|
||||||
clone_msg = copy(msg)
|
clone_msg = copy(msg)
|
||||||
to_append = encode_text(f"{text_header}\n---\n", encoding)
|
new_payload = f"""{text_header}
|
||||||
payload = f"{to_append}{payload}"
|
---
|
||||||
clone_msg.set_payload(payload)
|
{decode_text(payload, encoding)}"""
|
||||||
|
clone_msg.set_payload(encode_text(new_payload, encoding))
|
||||||
return clone_msg
|
return clone_msg
|
||||||
elif msg.get_content_type() == "text/html":
|
elif msg.get_content_type() == "text/html":
|
||||||
encoding = get_encoding(msg)
|
encoding = get_encoding(msg)
|
||||||
payload = msg.get_payload()
|
payload = msg.get_payload()
|
||||||
if type(payload) is str:
|
if type(payload) is str:
|
||||||
new_payload = (
|
new_payload = f"""<table width="100%" style="width: 100%; -premailer-width: 100%; -premailer-cellpadding: 0;
|
||||||
encode_text(
|
-premailer-cellspacing: 0; margin: 0; padding: 0;">
|
||||||
f"""
|
|
||||||
<table width="100%" style="width: 100%; -premailer-width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; margin: 0; padding: 0;">
|
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border-bottom:1px dashed #5675E2; padding: 10px 0px">{html_header}</td>
|
<td style="border-bottom:1px dashed #5675E2; padding: 10px 0px">{html_header}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>""",
|
<td>
|
||||||
encoding,
|
{decode_text(payload, encoding)}
|
||||||
)
|
</td>
|
||||||
+ payload
|
|
||||||
+ encode_text(
|
|
||||||
"""</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
""",
|
"""
|
||||||
encoding,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
clone_msg = copy(msg)
|
clone_msg = copy(msg)
|
||||||
clone_msg.set_payload(new_payload)
|
clone_msg.set_payload(encode_text(new_payload, encoding))
|
||||||
return clone_msg
|
return clone_msg
|
||||||
elif msg.get_content_type() in ("multipart/alternative", "multipart/related"):
|
elif msg.get_content_type() in ("multipart/alternative", "multipart/related"):
|
||||||
new_parts = []
|
new_parts = []
|
||||||
|
|
Loading…
Reference in New Issue