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_285e21ebf9.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 = ["asoler@solersalva.com"]
CC = ["bob.carella@auravision.co", "paul.chou@auravision.co"]
BCC = ["plchou@gmail.com"]
subj = r.get("subject") or "RE: Trademarks"
body = """Thanks, Albert — understood on the Office Action and the specimens of use. Appreciate you steering that and keeping us posted; nothing needed from our side there.

On filing an AURAVISION trademark for the hardware component (the Puck): noted, and a sensible protection to weigh. I'll put it in front of Paul and Bob to decide on strategy and timing, and they'll come back to you directly.

Thank you,
Aura (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("ALBERT SENT to", TO, "cc", CC)
