mailcatcher 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +1 -1
  2. data/lib/mail_catcher.rb +22 -16
  3. metadata +2 -2
data/README.md CHANGED
@@ -4,7 +4,7 @@ Catches mail and serves it through a dream.
4
4
 
5
5
  MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.
6
6
 
7
- ![MailCatcher screenshot](http://puu.sh/2fZR)
7
+ ![MailCatcher screenshot](http://f.cl.ly/items/0w3m122B401k3Q2C373Q/Image%202011.06.01%202:06:25%20AM.png)
8
8
 
9
9
  ## Features
10
10
 
@@ -1,25 +1,29 @@
1
1
  require 'active_support/all'
2
- require 'daemons'
3
2
  require 'eventmachine'
3
+ require ‘rbconfig’
4
4
  require 'thin'
5
5
 
6
+ def windows?
7
+ Config::CONFIG[‘host_os’] =~ /mswin|mingw/
8
+ end
9
+
6
10
  module MailCatcher
7
11
  extend ActiveSupport::Autoload
8
-
12
+
9
13
  autoload :Events
10
14
  autoload :Mail
11
15
  autoload :Smtp
12
16
  autoload :Web
13
-
17
+
14
18
  @@defaults = {
15
19
  :smtp_ip => '127.0.0.1',
16
20
  :smtp_port => '1025',
17
21
  :http_ip => '127.0.0.1',
18
22
  :http_port => '1080',
19
23
  :verbose => false,
20
- :daemon => true,
24
+ :daemon => true unless windows?,
21
25
  }
22
-
26
+
23
27
  def self.parse! arguments=ARGV, defaults=@@defaults
24
28
  @@defaults.dup.tap do |options|
25
29
  OptionParser.new do |parser|
@@ -45,8 +49,10 @@ module MailCatcher
45
49
  options[:http_port] = port
46
50
  end
47
51
 
48
- parser.on('-f', '--foreground', 'Run in the foreground') do
49
- options[:daemon] = false
52
+ unless windows?
53
+ parser.on('-f', '--foreground', 'Run in the foreground') do
54
+ options[:daemon] = false
55
+ end
50
56
  end
51
57
 
52
58
  parser.on('-v', '--verbose', 'Be more verbose') do
@@ -60,34 +66,34 @@ module MailCatcher
60
66
  end.parse!
61
67
  end
62
68
  end
63
-
69
+
64
70
  def self.run! options=nil
65
71
  # If we are passed options, fill in the blanks
66
72
  options &&= @@defaults.merge options
67
73
  # Otherwise, parse them from ARGV
68
74
  options ||= parse!
69
-
75
+
70
76
  puts "Starting MailCatcher"
71
77
 
72
78
  Thin::Logging.silent = true
73
-
79
+
74
80
  # One EventMachine loop...
75
81
  EventMachine.run do
76
82
  # TODO: DRY this up
77
-
83
+
78
84
  # Set up an SMTP server to run within EventMachine
79
85
  rescue_port options[:smtp_port] do
80
86
  EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
81
87
  puts "==> smtp://#{options[:smtp_ip]}:#{options[:smtp_port]}"
82
88
  end
83
-
89
+
84
90
  # Let Thin set itself up inside our EventMachine loop
85
91
  # (Skinny/WebSockets just works on the inside)
86
92
  rescue_port options[:http_port] do
87
93
  Thin::Server.start options[:http_ip], options[:http_port], Web
88
94
  puts "==> http://#{options[:http_ip]}:#{options[:http_port]}"
89
95
  end
90
-
96
+
91
97
  # Daemonize, if we should, but only after the servers have started.
92
98
  if options[:daemon]
93
99
  EventMachine.next_tick do
@@ -97,17 +103,17 @@ module MailCatcher
97
103
  end
98
104
  end
99
105
  end
100
-
106
+
101
107
  def self.quit!
102
108
  EventMachine.next_tick { EventMachine.stop_event_loop }
103
109
  end
104
110
 
105
- protected
111
+ protected
106
112
 
107
113
  def self.rescue_port port
108
114
  begin
109
115
  yield
110
-
116
+
111
117
  # XXX: EventMachine only spits out RuntimeError with a string description
112
118
  rescue RuntimeError
113
119
  if $!.to_s =~ /\bno acceptor\b/
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mailcatcher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.4.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Samuel Cochran
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-31 00:00:00 Z
13
+ date: 2011-06-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport