Python hashcash minting script for Mutt
Aaron Toponce <[email protected]> Thu, 24 Mar 2011 17:27:58 -0600
| Newsgroups | gmane.mail.spam.hashcash |
|---|---|
| Message-ID | <[email protected]> |
--eDB11BtaWSyaBkpc
Content-Type: multipart/mixed; boundary="brEuL7wsLY8+TuWz"
Content-Disposition: inline
--brEuL7wsLY8+TuWz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
I have finalized my Python minting script for Mutt. I haven't written a
verification script yet, although that should be trivial with
$display_filter. That's next.
Anyway, the script is attached. If you wish to give it a go, here is what
you'll need to do to set it up:
Set the following varibles in your ~/.muttrc:
set editor="/path/to/mint_hashcash.py" # required
set edit_headers="yes" # required
set askcc="yes" # recommended
The Python script calls Vim on line 10 of the script. Feel free to replace
it with your favorite editor.
A couple notes about the logic:
* Python 2.5 or later is required.
* It uses formatting of version 1 of the protocol only.
* It only mints new tokens after exiting your editor. If you add
additional emails, you will need to re-edit the mail, then quit to
mint the new tokens.
* Already existing tokens are left in place without duplicates minted.
* Both "X-Hashcash" and "Hashcash" headers are supported.
* 20 bits is minted, and compression level 2 is used.
If you use it, and find any bugs, please let me know. I've been using it
all day, and I've been trying to break it, but haven't found anything yet.
--
. o . o . o . . o o . . . o .
. . o . o o o . o . o o . . o
o o o . o . . o o o o . o o o
--brEuL7wsLY8+TuWz
Content-Type: text/x-python; charset=us-ascii
Content-Disposition: attachment; filename="mint_hashcash.py"
Content-Transfer-Encoding: quoted-printable
#!/usr/bin/env python
import csv
import fileinput
import re
import rfc822
import subprocess
import sys
subprocess.call("vim %s" % sys.argv[1], shell=3DTrue)
file =3D open(sys.argv[1], 'r')
headers =3D rfc822.Message(file)
=66rom_email =3D headers.getaddrlist("From")
to_emails =3D headers.getaddrlist("To")
cc_emails =3D headers.getaddrlist("Cc")
bcc_emails =3D headers.getaddrlist("Bcc")
email_addrs =3D []
tokens =3D []
# Harvest all email addresses from the header
for email in to_emails:
email_addrs.append(email[1])
for email in cc_emails:
email_addrs.append(email[1])
# Remove duplicate emails from the list, requires Python 2.5 and later
email_addrs =3D list(set(email_addrs))
# Check if an appropriate token is already generated for the mail
if headers.has_key("X-Hashcash"):
for list in headers.getheaders("X-Hashcash"):
email_addrs.remove(list.split(":")[3])
if headers.has_key("Hashcash"):
for list in headers.getheaders("Hashcash"):
email_addrs.remove(list.split(":")[3])
# Call the hashcash function from the operating system to mint tokens
for email in email_addrs:
t =3D subprocess.Popen("hashcash -m %s -X -Z 2" % email, shell=3DTrue, =
stdout=3Dsubprocess.PIPE)
tokens.append(t.stdout.read())
f =3D fileinput.FileInput(sys.argv[1], inplace=3D1)
for line in f:
line =3D line.strip()
if f.lineno() =3D=3D 7:
for token in tokens:
print token,
print line
continue
else:
print line
file.close()
--brEuL7wsLY8+TuWz--
--eDB11BtaWSyaBkpc
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: http://tinyurl.com/aarongpg
iQEcBAEBCgAGBQJNi9N+AAoJEM55Ebf8BAiP4uUIAL3jXg79ZqCjPhQQA52kwYXk
Y46fL9BctpMcAqdjYgXBqzXPDcbkB6GidnP3itw/yu75MBY2af0iF16NJID/uQta
C2LfPFWyYfpSkFzGWRfeuoIEfLU4tQoR3SbKqpd0ecZ+tSM8Qvtj1TpM9fQB05T7
iU9cE4E2v7q015raK+U4w1tGxIvB+fJHdhgN8Pth0IPKnRHKIBv683rQ49kggPyg
Hvw7Pl7jUbaSZooGIUMYxzv8ESmqL4ONoOEbummAmovvu4G+wgxUGWz6LLUsVB09
JDcw1+bulzAI2sohVqfRetUorXBoZ+DtUT9PI4LMUWst8e/plEKiI/dDxPQFwbA=
=Jdht
-----END PGP SIGNATURE-----
--eDB11BtaWSyaBkpc--