Initial resurrection kit — 81 scripts, 62 references, configs, systemd units, crons, Docker compose files, Caddy config, master README
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check shonuff@germainebrown.com inbox for new messages from unknown senders.
|
||||
|
||||
Silent if nothing new. Alerts if someone other than Germaine has emailed.
|
||||
"""
|
||||
import imaplib, email, os, json, hashlib
|
||||
from datetime import datetime, timezone
|
||||
|
||||
HOST = "mail.germainebrown.com"
|
||||
PORT = 993
|
||||
USER = "shonuff@germainebrown.com"
|
||||
PW = "Catches.bullets1985"
|
||||
SEEN_FILE = "/root/.hermes/scripts/.shonuff-seen.json"
|
||||
TRUSTED = ["g@germainebrown.com", "mailer-daemon@heracles.mxrouting.net"]
|
||||
|
||||
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 main():
|
||||
seen = load_seen()
|
||||
new_alerts = []
|
||||
|
||||
try:
|
||||
conn = imaplib.IMAP4_SSL(HOST, PORT)
|
||||
conn.login(USER, PW)
|
||||
conn.select("INBOX")
|
||||
|
||||
status, data = conn.search(None, "UNSEEN")
|
||||
if status != "OK" or not data[0]:
|
||||
conn.logout()
|
||||
save_seen(seen)
|
||||
return # silent — nothing new
|
||||
|
||||
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 = raw.get("From", "").strip()
|
||||
subj = raw.get("Subject", "(no subject)")
|
||||
msg_id = raw.get("Message-ID", str(num))
|
||||
|
||||
# Skip trusted senders
|
||||
trusted = any(t.lower() in sender.lower() for t in TRUSTED)
|
||||
if trusted:
|
||||
continue
|
||||
|
||||
# Skip if already reported
|
||||
h = hashlib.md5(msg_id.encode()).hexdigest()
|
||||
if h in seen:
|
||||
continue
|
||||
seen.add(h)
|
||||
|
||||
new_alerts.append((sender, subj))
|
||||
|
||||
conn.logout()
|
||||
save_seen(seen)
|
||||
|
||||
except Exception as e:
|
||||
print(f"⚠️ Sho'Nuff inbox check failed: {e}")
|
||||
return
|
||||
|
||||
if not new_alerts:
|
||||
return # silent
|
||||
|
||||
print(f"📬 Sho'Nuff received {len(new_alerts)} message(s) from unknown senders:\n")
|
||||
for sender, subj in new_alerts:
|
||||
print(f" • From: {sender}")
|
||||
print(f" Subject: {subj}")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user