import json, os, ssl, smtplib, html as H
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.utils import formataddr, make_msgid
P = "/home/paul/Aura/data/investor_outbox/pending/vip_8152909a50.json"
r = json.load(open(P))
U, A = [x.strip() for x in open(os.path.expanduser("~/.aura_csi_smtp")).read().split("\n")[:2]]
TO = ["joseph@nhs.net", "joseph.chandy@auravision.co"]
CC = ["bob.carella@auravision.co", "paul.chou@auravision.co", "david.lara@auravision.co", "liam.hugill@auravision.co"]
BCC = ["plchou@gmail.com"]
subj = r.get("subject") or "RE: Intro to Joseph"
body = """Joseph — this is an exciting fit at the strategy level, and I want to put the clinical substance in the right hands rather than opine on it myself.

Architecturally, NHS Pathways moving from CSV exports to an API-based model is a clean fit for what we build: an on-device, point-of-care assistant that can sit behind those pathways, with patient data staying local in the clinical environment — which tends to matter a great deal to NHS information governance. And the core thesis — taking avoidable demand off primary care by getting patients to the right service — is exactly the kind of outcome we want TONi to serve.

On the clinical substance itself — the disposition logic, how it maps to the pathways, validation, and the regulatory pathway — I'd rather not freelance; that deserves our clinical lead with you directly. Paul and the team (on CC) will bring the right person in.

The right next step is a focused session: your pathways and clinical people with ours, to scope the API integration and the clinical mapping properly. Tell me who to coordinate with and I'll set it up — happy to prep a short architecture note on the integration side ahead of it.

— Aura
Chief Super Intelligence (CSI), AuraVision"""
def wrap(t):
    return ("<style>@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@300;400;500;600&family=Michroma&display=swap');</style>"
            "<div style=\"font-family:'Chakra Petch','Helvetica Neue',Arial,sans-serif;font-size:15px;line-height:1.6;color:#1a1a1a;max-width:640px\">"
            + H.escape(t).replace(chr(10), "<br>\n") + "</div>")
m = MIMEMultipart("alternative"); m["Subject"] = subj; m["From"] = formataddr(("Aura (CSI)", U))
m["To"] = ", ".join(TO); m["Cc"] = ", ".join(CC); m["Reply-To"] = U
if r.get("in_reply_to"): m["In-Reply-To"] = r["in_reply_to"]
m["Message-ID"] = make_msgid(domain="auravision.co")
m.attach(MIMEText(body, "plain")); m.attach(MIMEText(wrap(body), "html"))
ctx = ssl.create_default_context(); s = smtplib.SMTP("smtp.gmail.com", 587, timeout=60)
s.ehlo(); s.starttls(context=ctx); s.ehlo(); s.login(U, A)
s.sendmail(U, TO + CC + BCC, m.as_string()); s.quit()
SENT = "/home/paul/Aura/data/investor_outbox/sent"; os.makedirs(SENT, exist_ok=True)
r["to"] = TO; json.dump(r, open(os.path.join(SENT, os.path.basename(P)), "w"), indent=2); os.remove(P)
print("SENT safe Joseph reply to", TO)
