Initial skills documentation — 25 categories, all SKILL.md + references + scripts
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check IMAP inbox for bounce-back / delivery-failure emails.
|
||||
|
||||
Silent (exit 0 with no output) when nothing to report.
|
||||
Outputs summary when bounces are found.
|
||||
"""
|
||||
|
||||
import imaplib
|
||||
import email
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
HOST = "mail.germainebrown.com"
|
||||
PORT = 993
|
||||
USER = "g@germainebrown.com"
|
||||
PW_FILE = "/root/.config/himalaya/g-germainebrown.pass"
|
||||
CHECK_HOURS = 24
|
||||
|
||||
BOUNCE_KEYWORDS = [
|
||||
"mail delivery failed", "delivery status notification", "undelivered",
|
||||
"returned mail", "mail delivery failure", "non-delivery",
|
||||
"delivery failed", "undeliverable", "delivery report",
|
||||
"returned to sender", "message bounced",
|
||||
]
|
||||
|
||||
BOUNCE_SENDERS = [
|
||||
"mailer-daemon", "postmaster", "mail delivery system",
|
||||
]
|
||||
|
||||
|
||||
def safe_str(val):
|
||||
if val is None:
|
||||
return ""
|
||||
if isinstance(val, str):
|
||||
return val
|
||||
try:
|
||||
return str(val)
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def is_bounce(msg):
|
||||
subject = safe_str(msg.get("Subject", "")).lower()
|
||||
sender = safe_str(msg.get("From", "")).lower()
|
||||
|
||||
for kw in BOUNCE_KEYWORDS:
|
||||
if kw in subject:
|
||||
return True
|
||||
|
||||
for s in BOUNCE_SENDERS:
|
||||
if s in sender:
|
||||
return True
|
||||
|
||||
if msg.get_content_type() == "text/plain":
|
||||
payload = msg.get_payload(decode=True)
|
||||
if payload:
|
||||
body = safe_str(payload).lower()
|
||||
if "permanent error" in body or "could not be delivered" in body:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
pw = open(PW_FILE).read().strip()
|
||||
except FileNotFoundError:
|
||||
print("[SILENT]")
|
||||
return
|
||||
|
||||
since = (datetime.now(timezone.utc) - timedelta(hours=CHECK_HOURS)).strftime("%d-%b-%Y")
|
||||
|
||||
try:
|
||||
conn = imaplib.IMAP4_SSL(HOST, PORT)
|
||||
conn.login(USER, pw)
|
||||
conn.select("INBOX")
|
||||
except Exception as e:
|
||||
print(f"ERROR: IMAP connection failed: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
status, data = conn.search(None, f'(SINCE {since})')
|
||||
if status != "OK":
|
||||
print("[SILENT]")
|
||||
conn.logout()
|
||||
return
|
||||
|
||||
bounces = []
|
||||
for num in data[0].split():
|
||||
status, msg_data = conn.fetch(num, "(RFC822)")
|
||||
if status != "OK":
|
||||
continue
|
||||
raw = email.message_from_bytes(msg_data[0][1])
|
||||
if is_bounce(raw):
|
||||
subject = raw.get("Subject", "(no subject)")
|
||||
sender = raw.get("From", "(unknown)")
|
||||
date = raw.get("Date", "")
|
||||
bounces.append({
|
||||
"subject": subject,
|
||||
"from": sender,
|
||||
"date": date,
|
||||
"uid": num.decode(),
|
||||
})
|
||||
|
||||
conn.logout()
|
||||
|
||||
if not bounces:
|
||||
return
|
||||
|
||||
print(f"📬 {len(bounces)} bounce-back(s) detected in the last {CHECK_HOURS}h:\n")
|
||||
for b in bounces:
|
||||
print(f" • {b['subject']}")
|
||||
print(f" From: {b['from']}")
|
||||
print(f" Date: {b['date']}")
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Send email from Sho'Nuff Brown with rotating title + signature + BCC to Germaine."""
|
||||
import smtplib, random, importlib.util
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
SHONUFF_PASS = "Catches.bullets1985"
|
||||
|
||||
def send(to, subject, body, cc=None):
|
||||
# Load random closing
|
||||
spec = importlib.util.spec_from_file_location("closings", "/root/.hermes/references/shonuff-closings.py")
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
closing = random.choice(mod.SHONUFF_CLOSINGS)
|
||||
|
||||
# Load random title
|
||||
spec2 = importlib.util.spec_from_file_location("titles", "/root/.hermes/references/shonuff-titles.py")
|
||||
mod2 = importlib.util.module_from_spec(spec2)
|
||||
spec2.loader.exec_module(mod2)
|
||||
title = random.choice(mod2.SHONUFF_TITLES)
|
||||
|
||||
# Load image and signature
|
||||
b64 = open("/root/.hermes/references/shonuff-image-b64.txt").read().strip()
|
||||
sig = open("/root/.hermes/references/shonuff-email-signature.html").read()
|
||||
sig = sig.replace("%SHONUFF_IMAGE%", b64).replace("%SHONUFF_TITLE%", title)
|
||||
|
||||
msg = MIMEMultipart("alternative")
|
||||
msg["From"] = "shonuff@germainebrown.com"
|
||||
msg["To"] = to
|
||||
msg["Bcc"] = "g@germainebrown.com"
|
||||
msg["Subject"] = subject
|
||||
|
||||
text = MIMEText(f"{body}\n\n{closing}\n\n-- \nSho'Nuff Brown\n{title}\nIT Pro Partner\nshonuff@germainebrown.com", "plain")
|
||||
html = MIMEText(f"<p>{body.replace(chr(10), '<br>')}</p><p><em>{closing}</em></p>{sig}", "html")
|
||||
msg.attach(text)
|
||||
msg.attach(html)
|
||||
|
||||
with smtplib.SMTP("mail.germainebrown.com", 2525) as s:
|
||||
s.starttls()
|
||||
s.login("shonuff@germainebrown.com", SHONUFF_PASS)
|
||||
s.send_message(msg)
|
||||
|
||||
print(f"Sent to {to} | closing: {closing} | title: {title}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) >= 4:
|
||||
send(sys.argv[1], sys.argv[2], sys.argv[3])
|
||||
else:
|
||||
print("Usage: send-shonuff.py <to> <subject> <body>")
|
||||
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check shonuff@germainebrown.com inbox. Outputs JSON for LLM summary.
|
||||
Silent if nothing new. Skips trusted senders (Germaine, mailer-daemon).
|
||||
"""
|
||||
import imaplib, email, json, os, hashlib
|
||||
from email.utils import parsedate_to_datetime
|
||||
|
||||
HOST = "mail.germainebrown.com"
|
||||
PORT = 993
|
||||
USER = "shonuff@germainebrown.com"
|
||||
PW = "Catches.bullets1985"
|
||||
SEEN_FILE = "/root/.hermes/scripts/.shonuff-processed.json"
|
||||
TRUSTED = ["g@germainebrown.com"]
|
||||
|
||||
def load_seen():
|
||||
if os.path.exists(SEEN_FILE):
|
||||
return set(json.load(open(SEEN_FILE)))
|
||||
return set()
|
||||
|
||||
def save_seen(seen):
|
||||
json.dump(list(seen), open(SEEN_FILE, "w"))
|
||||
|
||||
def safe_str(val):
|
||||
if val is None: return ""
|
||||
if isinstance(val, str): return val
|
||||
try: return str(val)
|
||||
except: return ""
|
||||
|
||||
def get_text_body(msg):
|
||||
body = ""
|
||||
# Try text/plain first
|
||||
if msg.is_multipart():
|
||||
for part in msg.walk():
|
||||
if part.get_content_type() == "text/plain":
|
||||
payload = part.get_payload(decode=True)
|
||||
if payload:
|
||||
body += payload.decode("utf-8", errors="replace")
|
||||
# Fallback: extract text from text/html if no plain text found
|
||||
if not body.strip():
|
||||
for part in msg.walk():
|
||||
if part.get_content_type() == "text/html":
|
||||
payload = part.get_payload(decode=True)
|
||||
if payload:
|
||||
import html
|
||||
text = payload.decode("utf-8", errors="replace")
|
||||
text = re.sub(r'<[^>]+>', ' ', text)
|
||||
text = html.unescape(text)
|
||||
body = text
|
||||
break
|
||||
else:
|
||||
payload = msg.get_payload(decode=True)
|
||||
if payload:
|
||||
ct = msg.get_content_type()
|
||||
text = payload.decode("utf-8", errors="replace")
|
||||
if ct == "text/html":
|
||||
text = re.sub(r'<[^>]+>', ' ', text)
|
||||
import html
|
||||
text = html.unescape(text)
|
||||
body = text
|
||||
import re
|
||||
body = re.sub(r'\s+', ' ', body).strip()
|
||||
return body[:500]
|
||||
|
||||
def main():
|
||||
seen = load_seen()
|
||||
new_msgs = []
|
||||
try:
|
||||
conn = imaplib.IMAP4_SSL(HOST, PORT)
|
||||
conn.login(USER, PW)
|
||||
conn.select("INBOX")
|
||||
status, data = conn.search(None, "UNSEEN")
|
||||
if status == "OK" and data[0]:
|
||||
for num in data[0].split():
|
||||
status, msg_data = conn.fetch(num, "(RFC822)")
|
||||
if status != "OK": continue
|
||||
raw = email.message_from_bytes(msg_data[0][1])
|
||||
sender = safe_str(raw.get("From", "")).strip()
|
||||
subj = safe_str(raw.get("Subject", "(no subject)"))
|
||||
mid = safe_str(raw.get("Message-ID", str(num)))
|
||||
date = safe_str(raw.get("Date", ""))
|
||||
if any(t.lower() in sender.lower() for t in TRUSTED): continue
|
||||
h = hashlib.md5(mid.encode()).hexdigest()
|
||||
if h in seen: continue
|
||||
seen.add(h)
|
||||
new_msgs.append({"from": sender, "subject": subj, "date": date, "body_preview": get_text_body(raw)[:500], "uid": num.decode()})
|
||||
conn.store(num, "+FLAGS", "\\Seen")
|
||||
conn.logout()
|
||||
save_seen(seen)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
return
|
||||
if new_msgs:
|
||||
print(json.dumps({"messages": new_msgs}, indent=2))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user