Below is the file 'policy.py' from this revision. You can also download the file.
#!/usr/bin/env python from Crypto.Hash import MD5 import addrhash import config import sys def log_rejection(req, reason): return print >>sys.stderr, req, reason if __name__ == '__main__': # verify incoming email addresses; see if they're # trying to brute-force us, and log that. otherwise, # let the mail through and we'll log more about the # message on delivery to that script def check(req): if not req.has_key('recipient'): return "DUNNO" try: user = req['recipient'] user_at = user.find('@') if user_at == -1: return "DUNNO" user = user[:user_at] addrhash.decode(user) except addrhash.GaisdeException, e: log_rejection(req, str(e)) return "REJECT 450 User unknown." return "PREPEND X-Gaisde: HMAC-verified." req = {} while True: line = sys.stdin.readline() stripped = line.strip() if line == '' or stripped == '': try: response = check(req) except: response = "DUNNO" sys.stdout.write('action='+response+'\n\n') sys.stdout.flush() req = {} if line == '': break if stripped: sp = line.split('=', 1) if len(sp) != 2: continue req[sp[0]] = sp[1]