Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 50 lines (42 sloc) 1.604 kb
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
1 #!/usr/bin/env python
2
3 import rfc822
4 import StringIO
5 import subprocess
6 import sys
7
1b1c66f Aaron Toponce Updated logic to close issues 1 & 4
authored
8 # Change the DB path in COMMAND as needed, and change your email address(es)
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
9 COMMAND="hashcash -cdb '%s' -r '%s' -f ~/.mutt/hashcash.db '%s'"
1b1c66f Aaron Toponce Updated logic to close issues 1 & 4
authored
10 EMAILADDR=("foo@example.com", "bar@example.com")
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
11
12 tokens = []
13 token_status = []
14
15 # converting a list to a file-type object for parsing rfc822 headers
16 original = sys.stdin.read()
17 emailmsg = StringIO.StringIO(''.join(original))
18 message = rfc822.Message(emailmsg)
19
20 # check for the presence of "X-Hashcash" and "Hashcash" headers
1b1c66f Aaron Toponce Updated logic to close issues 1 & 4
authored
21 # and extract only matches from EMAILADDR
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
22 if message.has_key("X-Hashcash"):
23 for hc_list in message.getheaders("X-Hashcash"):
1b1c66f Aaron Toponce Updated logic to close issues 1 & 4
authored
24 if hc_list.split(":")[3] in EMAILADDR:
25 tokens.append(hc_list)
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
26 if message.has_key("Hashcash"):
27 for hc_list in message.getheaders("Hashcash"):
1b1c66f Aaron Toponce Updated logic to close issues 1 & 4
authored
28 if hc_list.split(":")[3] in EMAILADDR:
29 tokens.append(hc_list)
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
30
31 # check each token
32 if tokens:
33 token_status.append("[-- Begin Hashcash output --]")
1b1c66f Aaron Toponce Updated logic to close issues 1 & 4
authored
34 for token in tokens:
35 bits = token.split(":")[1]
36 emailaddr = token.split(":")[3]
37 p = subprocess.Popen(COMMAND % (bits, emailaddr, token),
38 shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
39 out = p.stderr.read().strip()
40 token_status.append(out)
2148845 Aaron Toponce Added CHANGELOG, LICENSE, mint_hashcash.py and verify_hashcash.py
authored
41 token_status.append("[-- End Hashcash output --]")
42
43 print >> sys.stdout, ''.join(message.headers)
44 for status in token_status:
45 print >> sys.stdout, ''.join(status)
46 if tokens:
47 print ''
48 emailmsg.seek(message.startofbody)
49 print >> sys.stdout, ''.join(emailmsg.readlines())
Something went wrong with that request. Please try again.