Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Transform rendered mail from TEXT to YAML #46

Open
iknowright opened this issue Dec 17, 2022 · 3 comments
Open

[Feature Request] Transform rendered mail from TEXT to YAML #46

iknowright opened this issue Dec 17, 2022 · 3 comments
Assignees

Comments

@iknowright
Copy link

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

  • 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')

The result will be:

attachment:
- banner.png
- menu.pdf
body: |+
  謹致 ,

  Tha「Life is short  (You need Python)」自這句名言以來,Python 程式語言儼然成為「簡單、易用、開放與自由社群」的代名詞。截至今日,全球已有 47 個國家自主成立官方 Python Conference 社群 ( https://www.python.org/psf/trademarks/pycon/  )。

  臺灣亦在此全球趨勢下,自 2012 年起正式成立 PyCon Taiwan。來自全臺各地,自願付出的志工們為了推動臺灣的程式交流持續努力,與所有的會眾和贊助夥伴一同經歷了八年的持續成長與茁壯,已經累積與會數千人次,成為臺灣數一數二規模的技術研討會。

  但是我們仍在思考,如何更進一步地擴大年會的影響力呢?

  答案是,讓支持著台灣 Python 年會的各地社群成長與彼此交流,一旦各地社群能夠穩定發展,將可以從點的質變形成連接彼此的線,進一步的推進全臺灣程式社群的量變。

  今年年會將安排於濁水溪以南的府城,加重對非北部 Python 在地社群的推廣力道,更在會期之間加入了有別以往的社群軌議程。我們捨棄了儘管專業卻死板的會議室,將各地社群帶進了咖啡廳、展演空間甚至是古蹟內,以在地的社群主辦人擔任主持,協助講者與會眾進行更深度的交流互動。

  換言之,我們希望今年的年會不僅是一場盛大的活動,也能夠持續性的活化台灣各地的 Python 社群。

  為此,我們誠摯地邀請  一同加入我們的行列,給予 PyCon Taiwan 最需要的支持與贊助!展現貴公司所重視的企業價值、面對面接觸專業人士且於會期中招募所需人才。

  為感謝您共襄盛舉,贊助廠商可選擇不同的贊助方案且享有多項的回饋服務。我們亦提供社群軌議程的贊助方案,使您可以選定主題以包下整個場地,來對參與的會眾(甚至講者)做精準的接觸;同時,由於主持人為各地社群主辦人,您亦有機會與社群意見領袖建立連結,甚至洽談後續社群活動贊助事宜。後附「」贊助方案,供您參酌。

  若您有任何相關活動問題或是合作想法,請務必與我們聯繫!


  會期資訊:5-6 Sep, 2020 於國立成功大學與週邊地區
  贊助方案:https://tw.pycon.org/2020/zh-hant/sponsor/prospectus/
  PyCon TW 官網:http://pycon.tw/


  敬祝 昌隆,


receiver:
- [email protected]

Related Issue

@tai271828
Copy link
Member

Thanks for suggestions. Are you interested in making a pull request for this feature request?

@Lee-W
Copy link
Member

Lee-W commented Dec 18, 2022

The sample output looks great 👍

@iknowright
Copy link
Author

Hi @tai271828, sure. I'm on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready
Development

No branches or pull requests

3 participants