Integration Exercise: Mail Servers
written by: Brent Vatne
Description and usage
Jester is a mail friendly mail daemon that saves a bunch of great stories and jokes and is willing to tell them to anyone who asks. He exists in the ethereal realm of email.
- Set up dependencies with
bundle install. You will also need sqlite installed if you don't have it already.
- Fill it in with an e-mail account that you'd like Jester to watch
- Optionally, populate Jester with a few stories by running
- Start Jester by running
Now you can e-mail the address you told him to watch, and use the following commands:
Have him remember a story for you
In the subject line of your e-mail put:
a funny story "the time I went
helicopter fishing" and use the body
of the email to tell him the story. He will remember it and tell it to other
people looking to brighten up their day.
Of course, some people were born without a funny bone, and have no
desire to read anything funny. Jester thinks that's hilarious, but also
feels a duty to entertain, so he likes to remember any other type of story too.
For example, maybe you heard an interesting fact hat you think Jester and his
friends might like to hear. In the subject line of your email write:
an interesting story "why the sky is blue"
Ask Jester to brighten up your day
Great, he can remember jokes that I tell him. What use is a Jester that
you tell jokes to, but that doesn't tell any to you? Ask Jester for a story
by specifying in the subject
tell me something funny or perhaps
me something interesting. I'm not judging you, Jester might be.
Here's a grab bag of everything you can do. Keep in mind that wherever you see quotation marks, they are required.
a ____ story 'story name here' - Teaches Jester a story so he can share it with others.
a funny story 'This story is really funny isn't it'
tell me something __ - Hear a particular kind of story, such as funny
tell me something funny
tell something ___ to __@__.__ - Sends a random story to a friend!
tell something funny to firstname.lastname@example.org
tell me '___' - Jester tells you a specific story from his collection
tell me 'What do you call a lazy bear?'
what stories do you know? - Lists all of Jester's stories
help - List all available commands
Add more commands to Jester
A command is called a Request in Jester's world. There are two steps to extending Jester's Request repitoire.
1. Write a new Request class
Unlike an old dog, it's easy to teach him new tricks. The first step is to
create a new Request class in
lib/jester/requests/, which implements the
self.handle - returns nil if the message subject is not handled by this
request, or an instance of itself if it is handled.
self.description - a text description of how to make the request, and
what it does.
execute - performs required actions to carry out the request, returns
For example, if we wanted to create a greet command:
module Jester module Request class Greet def self.handle(message) if message.subject.match(/hello jester/) new(message.from.first) end end def self.description "hello jester - Jester will greet you" end def initialize(email) @email = email end def execute Response.new(:subject => "Well hello world!", :email => @email) end end end end
2. Tell the Request handler about it
The second and final step is to make sure the Request handler knows about your
Request object. In
lib/jester/requests.rb, require your new Request class and
add it to the array