# Takes what a 1.0 site posts from its outboxes (DHD_HOOKS) and lets each row go: # sink.py on 127.0.0.1; SIGUSR1 prints `count `, SIGTERM the sums. # Nothing is delivered and nothing kept: it counts rows per outbox, and for # mail how many addresses and which subjects. Never an address or a body. import sys, json, hashlib, collections, http.server, signal port=int(sys.argv[1]); rows=collections.Counter(); who=collections.defaultdict(set); subj=collections.Counter(); keys=collections.defaultdict(set) class H(http.server.BaseHTTPRequestHandler): def do_POST(s): b=s.rfile.read(int(s.headers.get('Content-Length',0))); o=s.headers.get('Dhd-Outbox','?'); rows[o]+=1 try: d=json.loads(b); keys[o].update(d.keys()) if o=='mail': to=d.get('to'); to=to if isinstance(to,list) else [to] for t in to: who[o].add(hashlib.sha256(str(t).encode()).hexdigest()) subj[str(d.get('subject'))[:60]]+=1 except Exception: pass s.send_response(204); s.end_headers() def log_message(s,*a): pass def done(*a): print(f'mail: {rows["mail"]} rows to {len(who["mail"])} different addresses; subjects {dict(subj)}') for o,n in rows.items(): if o!='mail': print(f'{o}: {n} rows; fields {sorted(keys[o])}') sys.stdout.flush(); sys.exit(0) def count(*a): print('count',rows['mail']); sys.stdout.flush() signal.signal(signal.SIGUSR1,count) signal.signal(signal.SIGTERM,done); signal.signal(signal.SIGINT,done) http.server.HTTPServer(('127.0.0.1',port),H).serve_forever()