You can use the mail gem (https://github.com/mikel/mail) to read emails. Just grab it from stdin, and then pass it in.
#!/usr/bin/env ruby
require 'mail'
message = $stdin.read
mail = Mail.new(message)
... work with the Mail here ..
The documentation on the github is pretty good.