import re
from email import message_from_bytes
from email.policy import default
from pathlib import Path
from inkwell import mail_templates
from inkwell.mailer import MailSettings, build_message
LINK = "https://notes.example.test/reset-password?token=abc-123"
def test_every_email_carries_its_link_in_both_parts():
for email in (
mail_templates.password_reset("Inkwell", "a@example.test", LINK),
mail_templates.invite("Inkwell", "Sam", LINK, 7),
):
assert LINK in email.text
assert f'href="{LINK}"' in email.html
def test_text_from_settings_and_people_is_escaped_in_the_html():
email = mail_templates.invite('Ink & "co"', "", LINK, 1)
assert "" in email.text
assert "within a day" in email.text
def test_the_html_fetches_nothing():
"""No remote images or fonts: the app sends with no outbound network, and a remote
image in an email is a tracking pixel. The one image is the logo, carried inside
the message and named by cid."""
email = mail_templates.password_reset("Inkwell", "a@example.test", LINK)
assert re.findall(r'src="([^"]*)"', email.html) == [f"cid:{mail_templates.LOGO_CID}"]
assert "@import" not in email.html and ""
assert logo.get_content() == mail_templates.logo_png()
assert parsed["Subject"] == "Inkwell test email"