New Fancy Son of Sam Code
I finished up this semester at school and I’ve been dying to sit down and hack some real code for the last month. I want to code and work so bad it’s driving me insane, so I’ve got a light gig during the day and I’m going to be working on my oppugn.us/impugn.us mailing list site idea as the test driver.
The code is still in the works, but I managed to borrow the excellent mailer module from Ryan Ginstrom to implement better crafting of responses.
What’s Son of Sam
For those of you that have no idea what I’m talking about, SoS is my little project to do an email server that works like a modern web application server. Instead of aliases files, newaliases, pipes, permissions galore, and duct taped Perl, you use modern concepts like handlers, requests, responses, state machines and Python.
Getting This Code
First, if you want this latest drop of SoS just do this:
bzr branch http://zedshaw.com/repository/sosAnd you should get it. Do not go to it with a fucking web browser. It has 403 for a reason. It’s not a fucking web page, it’s a Bazaar repository. Don’t tell me it has 403. I know it has 403, that’s on purpose. That’s the difference between 403 and 404.
In the near future I’ll have a Launchpad for people to help with the code, once I actually implement something with it as a demo.
What’s In The Repository
What I basically did was clean out the code so that there’s a distinction between an email a handler has received (MailRequest) and an email a handler would send (MailResponse). A MailRequest is basically set in stone and intended to be built from an email that was delivered to the server, must like an HTTP request. A MailResponse however is something you craft to send to someone else, so it’s mutable.
As I mentioned in the opening paragraphs, I grabbed code from Ryan Ginstrom to make it easier to make nice MailResponse objects and send them on. He figured out all the weirdness of doing HTML vs. plain-text emails and also how to include attachments in one nice interface. He also used capitalized names for the headers so that things like “from” doesn’t clash with “From” and it looks more like an email.
Here’s the test cases for the MailResponse and the Relay:
def test_relay_deliver():
relay = server.Relay(“localhost”, port=8825)
relay.deliver(test_mail_response_plain_text())
relay.deliver(test_mail_response_html())
relay.deliver(test_mail_response_html_and_plain_text())
relay.deliver(test_mail_response_attachments())
def test_mail_response_plain_text():
sample = server.MailResponse(To=“receiver@zedshaw.com”,
Subject=“Test message”,
From=“sender@zedshaw.com”,
Body=“Test from test_mail_response_plain_text.”)
return sample
def test_mail_response_html():
sample = server.MailResponse(To=“receiver@zedshaw.com”,
Subject=“Test message”,
From=“sender@zedshaw.com”,
Html=”<html><body><p>From test_mail_response_html</p></body></html>”)
return sample
def test_mail_response_html_and_plain_text():
sample = server.MailResponse(To=“receiver@zedshaw.com”,
Subject=“Test message”,
From=“sender@zedshaw.com”,
Html=”<html><body><p>Hi there.</p></body></html>”,
Body=“Test from test_mail_response_html_and_plain_text.”)
return sample
def test_mail_response_attachments():
sample = server.MailResponse(To=“receiver@zedshaw.com”,
Subject=“Test message”,
From=“sender@zedshaw.com”,
Body=“Test from test_mail_response_attachments.”)
sample.attach(”./README”)
return sample
I’m now working on the handlers a bit to make doing replies and crafting these emails even easier. I want the 90% case of doing replies with identified hashes pretty simple, possibly also bulk delivery in the background.
Current State
As usual, since I haven’t touched this code in months it’s in a barely working state. If you want to use it, hit me up on irc.freenode.org (I’m zedas) and I’ll walk you through getting it going.