Coverage for rfpy/mail/stub.py: 100%
30 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-24 10:52 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-24 10:52 +0000
1import logging
2import uuid
3from pathlib import Path
4from typing import List, Dict
6import pymustache # type: ignore[import]
7from rfpy import conf
10log = logging.getLogger("rfpy.mail.dummy_mailer")
13# Dummy mailbox for testing
14MAILBOX: List[Dict[str, str]] = []
15stars: str = "\n" + ("*" * 90) + "\n"
18def clear_mailbox():
19 MAILBOX.clear()
22def get_tmpl(evt_type):
23 path = Path(conf.CONF.template_dir) / f"{evt_type}.txt"
24 tmpl = path.read_text()
25 log.debug("Template \n: %s \n", tmpl)
26 return tmpl
29def render_msg(tmpl_string: str, model: dict):
30 return pymustache.render(tmpl_string, model)
33def send_email(model: dict):
34 tmpl = get_tmpl(model["TemplateAlias"])
35 # import ipdb; ipdb.set_trace()
36 msg = render_msg(tmpl, model["TemplateModel"])
37 to_email = model["To"]
38 with open("/tmp/emailout.txt", "a+") as f:
39 f.write(f"To: {to_email}")
40 f.write(stars)
41 f.write(msg)
42 f.write(stars)
43 message_id = str(uuid.uuid4())
44 MAILBOX.append(dict(to_address=to_email, text=msg, MessageID=message_id))
45 return message_id