You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are potential risks and limitations for the rendered mail in TEXT form. I think transforming rendered mail from text to YAML can bring advantages and enhancement to the current format.
Risks and limitation
filename using the receiver's mail may cause filename length exceeded (if receivers are multiple)
Mail attachment is done in send mail, not in render mail, and only one attachment is supported currently
Possible Solution
Using pyyaml to dump rendered mail in YAML format, more attributes can be exposed by this format. E.g receivers, attachment, title, etc
using YAML, rendered mail will be more flexible
Additional context
Below is the example:
import sys
import yaml
from jinja2 import Template
def load_template(tmpl_path: str) -> Template:
with open(tmpl_path, "r", encoding="utf-8") as input_tmpl:
return Template(input_tmpl.read())
template = load_template("templates/sponsorship/spam_sponsors_2020.j2")
# print(template.render())
data = {"body": template.render(), "receiver": ["[email protected]"], "attachment": ["banner.png", "menu.pdf"]}
def str_presenter(dumper, data):
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
with open("test.yml", "w+") as file_write:
yaml.safe_dump(data, file_write, default_flow_style=False, allow_unicode=True, encoding='utf-8')
yaml.dump(data, sys.stdout, default_flow_style=False, allow_unicode=True, encoding='utf-8')
Description
There are potential risks and limitations for the rendered mail in TEXT form. I think transforming rendered mail from text to YAML can bring advantages and enhancement to the current format.
Risks and limitation
Possible Solution
Using pyyaml to dump rendered mail in YAML format, more attributes can be exposed by this format. E.g receivers, attachment, title, etc
Additional context
Below is the example:
The result will be:
Related Issue
The text was updated successfully, but these errors were encountered: