mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-08-13 17:03:45 -04:00
Rawr! (Basic Growl support.)
This commit is contained in:
parent
4b689159df
commit
d0d6b29606
@ -66,9 +66,9 @@ A fairly RESTful URL schema means you can download a list of messages in JSON fr
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* Growl support.
|
|
||||||
* Test suite.
|
|
||||||
* Add mail delivery on request, optionally multiple times.
|
* Add mail delivery on request, optionally multiple times.
|
||||||
|
* Better Growl support in MacRuby and RubyCocoa with click notifications which takes you to the received message.
|
||||||
|
* Test suite.
|
||||||
* Forward mail to rendering service, maybe CampaignMonitor?
|
* Forward mail to rendering service, maybe CampaignMonitor?
|
||||||
* Package as an app? Native interfaces? HotCocoa?
|
* Package as an app? Native interfaces? HotCocoa?
|
||||||
|
|
||||||
|
@ -4,52 +4,91 @@ require 'optparse'
|
|||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
require 'thin'
|
require 'thin'
|
||||||
|
|
||||||
def windows?
|
|
||||||
Config::CONFIG['host_os'] =~ /mswin|mingw/
|
|
||||||
end
|
|
||||||
|
|
||||||
module MailCatcher
|
module MailCatcher
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
|
|
||||||
autoload :Events
|
autoload :Events
|
||||||
|
autoload :Growl
|
||||||
autoload :Mail
|
autoload :Mail
|
||||||
autoload :Smtp
|
autoload :Smtp
|
||||||
autoload :Web
|
autoload :Web
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def mac?
|
||||||
|
Config::CONFIG['host_os'] =~ /darwin/
|
||||||
|
end
|
||||||
|
|
||||||
|
def windows?
|
||||||
|
Config::CONFIG['host_os'] =~ /mswin|mingw/
|
||||||
|
end
|
||||||
|
|
||||||
|
def macruby?
|
||||||
|
mac? and const_defined? :MACRUBY_VERSION
|
||||||
|
end
|
||||||
|
|
||||||
|
def growlnotify?
|
||||||
|
system "which", "-s", "growlnotify"
|
||||||
|
end
|
||||||
|
|
||||||
|
def growlframework?
|
||||||
|
macruby? and
|
||||||
|
# TODO: Look for growl framework accessible
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def growl?
|
||||||
|
growlnotify? or growlframework?
|
||||||
|
end
|
||||||
|
|
||||||
@@defaults = {
|
@@defaults = {
|
||||||
:smtp_ip => '127.0.0.1',
|
:smtp_ip => '127.0.0.1',
|
||||||
:smtp_port => '1025',
|
:smtp_port => '1025',
|
||||||
:http_ip => '127.0.0.1',
|
:http_ip => '127.0.0.1',
|
||||||
:http_port => '1080',
|
:http_port => '1080',
|
||||||
:verbose => false,
|
:verbose => false,
|
||||||
:daemon => (true unless windows?),
|
:daemon => !windows?,
|
||||||
|
:growl => growlnotify?,
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.parse! arguments=ARGV, defaults=@@defaults
|
def parse! arguments=ARGV, defaults=@@defaults
|
||||||
@@defaults.dup.tap do |options|
|
@@defaults.dup.tap do |options|
|
||||||
OptionParser.new do |parser|
|
OptionParser.new do |parser|
|
||||||
parser.banner = 'Usage: mailcatcher [options]'
|
parser.banner = "Usage: mailcatcher [options]"
|
||||||
|
|
||||||
parser.on('--ip IP', 'Set the ip address of both servers') do |ip|
|
parser.on("--ip IP", "Set the ip address of both servers") do |ip|
|
||||||
options[:smtp_ip] = options[:http_ip] = ip
|
options[:smtp_ip] = options[:http_ip] = ip
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on('--smtp-ip IP', 'Set the ip address of the smtp server') do |ip|
|
parser.on("--smtp-ip IP", "Set the ip address of the smtp server") do |ip|
|
||||||
options[:smtp_ip] = ip
|
options[:smtp_ip] = ip
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on('--smtp-port PORT', Integer, 'Set the port of the smtp server') do |port|
|
parser.on("--smtp-port PORT", Integer, "Set the port of the smtp server") do |port|
|
||||||
options[:smtp_port] = port
|
options[:smtp_port] = port
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on('--http-ip IP', 'Set the ip address of the http server') do |ip|
|
parser.on("--http-ip IP", "Set the ip address of the http server") do |ip|
|
||||||
options[:http_ip] = ip
|
options[:http_ip] = ip
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on('--http-port PORT', Integer, 'Set the port address of the http server') do |port|
|
parser.on("--http-port PORT", Integer, "Set the port address of the http server") do |port|
|
||||||
options[:http_port] = port
|
options[:http_port] = port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if mac?
|
||||||
|
parser.on("--[no-]growl", "Growl to the local machine when a message arrives") do |growl|
|
||||||
|
if growl and not growlnotify?
|
||||||
|
puts "You'll need to install growlnotify from the Growl installer."
|
||||||
|
puts
|
||||||
|
puts "See: http://growl.info/extras.php#growlnotify"
|
||||||
|
exit!
|
||||||
|
end
|
||||||
|
|
||||||
|
options[:growl] = growl
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
unless windows?
|
unless windows?
|
||||||
parser.on('-f', '--foreground', 'Run in the foreground') do
|
parser.on('-f', '--foreground', 'Run in the foreground') do
|
||||||
options[:daemon] = false
|
options[:daemon] = false
|
||||||
@ -68,7 +107,7 @@ module MailCatcher
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run! options=nil
|
def run! options=nil
|
||||||
# If we are passed options, fill in the blanks
|
# If we are passed options, fill in the blanks
|
||||||
options &&= @@defaults.merge options
|
options &&= @@defaults.merge options
|
||||||
# Otherwise, parse them from ARGV
|
# Otherwise, parse them from ARGV
|
||||||
@ -80,6 +119,9 @@ module MailCatcher
|
|||||||
|
|
||||||
# One EventMachine loop...
|
# One EventMachine loop...
|
||||||
EventMachine.run do
|
EventMachine.run do
|
||||||
|
# Get our lion on if asked
|
||||||
|
MailCatcher::Growl.start if options[:growl]
|
||||||
|
|
||||||
# TODO: DRY this up
|
# TODO: DRY this up
|
||||||
|
|
||||||
# Set up an SMTP server to run within EventMachine
|
# Set up an SMTP server to run within EventMachine
|
||||||
@ -105,13 +147,14 @@ module MailCatcher
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.quit!
|
def quit!
|
||||||
EventMachine.next_tick { EventMachine.stop_event_loop }
|
EventMachine.next_tick { EventMachine.stop_event_loop }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
module_function
|
||||||
|
|
||||||
def self.rescue_port port
|
def rescue_port port
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
16
lib/mail_catcher/growl.rb
Normal file
16
lib/mail_catcher/growl.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
module MailCatcher
|
||||||
|
module Growl
|
||||||
|
module_function
|
||||||
|
def start
|
||||||
|
MailCatcher::Events::MessageAdded.subscribe MailCatcher::Growl.method :notify
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify message
|
||||||
|
system "growlnotify", "--name", "MailCatcher", "--message", "Message received:\n#{message["subject"]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Native support on MacRuby with click backs
|
||||||
|
#def click
|
||||||
|
#end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user