danxexe-mailcatcher 0.6.2
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.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +123 -0
- data/bin/catchmail +71 -0
- data/bin/mailcatcher +5 -0
- data/lib/mail_catcher.rb +213 -0
- data/lib/mail_catcher/events.rb +7 -0
- data/lib/mail_catcher/mail.rb +161 -0
- data/lib/mail_catcher/smtp.rb +61 -0
- data/lib/mail_catcher/version.rb +3 -0
- data/lib/mail_catcher/web.rb +21 -0
- data/lib/mail_catcher/web/application.rb +188 -0
- data/lib/mailcatcher.rb +3 -0
- data/public/assets/logo.png +0 -0
- data/public/assets/logo_large.png +0 -0
- data/public/assets/mailcatcher.css +1 -0
- data/public/assets/mailcatcher.js +5 -0
- data/public/favicon.ico +0 -0
- data/views/404.erb +6 -0
- data/views/index.erb +62 -0
- metadata +330 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9acc129161d8ec33c76ad20eb81006caad1ec52b
|
4
|
+
data.tar.gz: f39639bd6c01468d8a5c01e37077b7063a127cb6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9fd2294b8ee79675f41ded36cd46c44a7951ccdcc0dafbde33811fb3a1ce578158cad81efbd8397086746b195d2246bef7f7ab26b36e617b73e85974b6a6be0b
|
7
|
+
data.tar.gz: 0c36aa2525608752cabc45941bb48bcb647caf692df686bcfbb85445d0e128be333fd62fd5c1aecaad62d5b0a853f4e7941d81c812bf0ee3e2eff33c0223dd17
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010-2011 Samuel Cochran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# MailCatcher
|
2
|
+
|
3
|
+
Catches mail and serves it through a dream.
|
4
|
+
|
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
|
+
|
7
|
+

|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
* Catches all mail and stores it for display.
|
12
|
+
* Shows HTML, Plain Text and Source version of messages, as applicable.
|
13
|
+
* Rewrites HTML enabling display of embedded, inline images/etc and open links in a new window.
|
14
|
+
* Lists attachments and allows separate downloading of parts.
|
15
|
+
* Download original email to view in your native mail client(s).
|
16
|
+
* Command line options to override the default SMTP/HTTP IP and port settings.
|
17
|
+
* Mail appears instantly if your browser supports [WebSockets][websockets], otherwise updates every thirty seconds.
|
18
|
+
* Runs as a daemon run in the background.
|
19
|
+
* Sendmail-analogue command, `catchmail`, makes [using mailcatcher from PHP][withphp] a lot easier.
|
20
|
+
* Written super-simply in EventMachine, easy to dig in and change.
|
21
|
+
* Keyboard navigation between messages
|
22
|
+
|
23
|
+
## How
|
24
|
+
|
25
|
+
1. `gem install mailcatcher`
|
26
|
+
2. `mailcatcher`
|
27
|
+
3. Go to http://localhost:1080/
|
28
|
+
4. Send mail through smtp://localhost:1025
|
29
|
+
|
30
|
+
Use `mailcatcher --help` to see the command line options. The brave can get the source from [the GitHub repository][mailcatcher-github].
|
31
|
+
|
32
|
+
### Bundler
|
33
|
+
|
34
|
+
Please don't put mailcatcher into your Gemfile. It will conflict with your applications gems at some point.
|
35
|
+
|
36
|
+
Instead, pop a note in your README stating you use mailcatcher. Simply run `gem install mailcatcher` then `mailcatcher` to get started.
|
37
|
+
|
38
|
+
### RVM
|
39
|
+
|
40
|
+
Under RVM your mailcatcher command may only be available under the ruby you install mailcatcher into. To prevent this, and to prevent gem conflicts, install mailcatcher into a dedicated gemset and create wrapper scripts:
|
41
|
+
|
42
|
+
rvm default@mailcatcher --create do gem install mailcatcher
|
43
|
+
rvm wrapper default@mailcatcher --no-prefix mailcatcher catchmail
|
44
|
+
|
45
|
+
### Rails
|
46
|
+
|
47
|
+
To set up your rails app, I recommend adding this to your `environments/development.rb`:
|
48
|
+
|
49
|
+
config.action_mailer.delivery_method = :smtp
|
50
|
+
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
|
51
|
+
|
52
|
+
### PHP
|
53
|
+
|
54
|
+
For projects using PHP, or PHP frameworks and application platforms like Drupal, you can set [PHP's mail configuration](http://www.php.net/manual/en/mail.configuration.php) in your [php.ini](http://www.php.net/manual/en/configuration.file.php) to send via MailCatcher with:
|
55
|
+
|
56
|
+
sendmail_path = /usr/bin/env catchmail -f some@from.address
|
57
|
+
|
58
|
+
You can do this in your [Apache configuration](http://php.net/manual/en/configuration.changes.php) like so:
|
59
|
+
|
60
|
+
php_admin_value sendmail_path "/usr/bin/env catchmail -f some@from.address"
|
61
|
+
|
62
|
+
If you've installed via RVM this probably won't work unless you've manually added your RVM bin paths to your system environment's PATH. In that case, run `which catchmail` and put that path into the `sendmail_path` directive above instead of `/usr/bin/env catchmail`.
|
63
|
+
|
64
|
+
If starting `mailcatcher` on alternative SMTP IP and/or port with parameters like `--smtp-ip 192.168.0.1 --smtp-port 10025`, add the same parameters to your `catchmail` command:
|
65
|
+
|
66
|
+
sendmail_path = /usr/bin/env catchmail --smtp-ip 192.160.0.1 --smtp-port 10025 -f some@from.address
|
67
|
+
|
68
|
+
### Django
|
69
|
+
|
70
|
+
For use in Django, simply add the following configuration to your projects' settings.py
|
71
|
+
|
72
|
+
```python
|
73
|
+
if DEBUG:
|
74
|
+
EMAIL_HOST = '127.0.0.1'
|
75
|
+
EMAIL_HOST_USER = ''
|
76
|
+
EMAIL_HOST_PASSWORD = ''
|
77
|
+
EMAIL_PORT = 1025
|
78
|
+
EMAIL_USE_TLS = False
|
79
|
+
```
|
80
|
+
|
81
|
+
### API
|
82
|
+
|
83
|
+
A fairly RESTful URL schema means you can download a list of messages in JSON from `/messages`, each message's metadata with `/messages/:id.json`, and then the pertinent parts with `/messages/:id.html` and `/messages/:id.plain` for the default HTML and plain text version, `/messages/:id/:cid` for individual attachments by CID, or the whole message with `/messages/:id.source`.
|
84
|
+
|
85
|
+
## Caveats
|
86
|
+
|
87
|
+
* Mail processing is fairly basic but easily modified. If something doesn't work for you, fork and fix it or [file an issue][mailcatcher-issues] and let me know. Include the whole message you're having problems with.
|
88
|
+
* The interface is very basic and has not been tested on many browsers yet.
|
89
|
+
|
90
|
+
## TODO
|
91
|
+
|
92
|
+
* Add mail delivery on request, optionally multiple times.
|
93
|
+
* An API-compatible nodejs version, for fun and profit (and non-ruby npm users).
|
94
|
+
* Test suite.
|
95
|
+
* Compatibility testing against CampaignMonitor's [design guidelines](http://www.campaignmonitor.com/design-guidelines/) and [CSS support matrix](http://www.campaignmonitor.com/css/).
|
96
|
+
* Forward mail to rendering service, maybe CampaignMonitor?
|
97
|
+
* Package as an app? Native interfaces? HotCocoa?
|
98
|
+
|
99
|
+
## Thanks
|
100
|
+
|
101
|
+
MailCatcher is just a mishmash of other people's hard work. Thank you so much to the people who have built the wonderful guts on which this project relies.
|
102
|
+
|
103
|
+
Thanks also to [The Frontier Group][tfg] for giving me the idea, being great guinea pigs and letting me steal pieces of time to keep the project alive.
|
104
|
+
|
105
|
+
## Donations
|
106
|
+
|
107
|
+
I work on MailCatcher mostly in my own spare time. If you've found Mailcatcher useful and would like to help feed me and fund continued development and new features, please [donate via PayPal][donate]. If you'd like a specific feature added to MailCatcher and are willing to pay for it, please [email me](mailto:sj26@sj26.com).
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
Copyright © 2010-2011 Samuel Cochran (sj26@sj26.com). Released under the MIT License, see [LICENSE][license] for details.
|
112
|
+
|
113
|
+
## Dreams
|
114
|
+
|
115
|
+
For dream catching, try [this](http://goo.gl/kgbh). OR [THIS](http://www.nyanicorn.com), OMG.
|
116
|
+
|
117
|
+
[donate]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=522WUPLRWUSKE
|
118
|
+
[license]: https://github.com/sj26/mailcatcher/blob/master/LICENSE
|
119
|
+
[mailcatcher-github]: https://github.com/sj26/mailcatcher
|
120
|
+
[mailcatcher-issues]: https://github.com/sj26/mailcatcher/issues
|
121
|
+
[tfg]: http://www.thefrontiergroup.com.au
|
122
|
+
[websockets]: http://www.whatwg.org/specs/web-socket-protocol/
|
123
|
+
[withphp]: http://webschuur.com/publications/blogs/2011-05-29-catchmail_for_drupal_and_other_phpapplications_the_simple_version
|
data/bin/catchmail
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'mail'
|
5
|
+
rescue LoadError
|
6
|
+
require 'rubygems'
|
7
|
+
require 'mail'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'optparse'
|
11
|
+
|
12
|
+
options = {:smtp_ip => '127.0.0.1', :smtp_port => 1025}
|
13
|
+
|
14
|
+
OptionParser.new do |parser|
|
15
|
+
parser.banner = <<-BANNER.gsub /^ +/, ""
|
16
|
+
Usage: catchmail [options] [recipient ...]
|
17
|
+
sendmail-like interface to forward mail to MailCatcher.
|
18
|
+
BANNER
|
19
|
+
|
20
|
+
parser.on('--ip IP') do |ip|
|
21
|
+
options[:smtp_ip] = ip
|
22
|
+
end
|
23
|
+
|
24
|
+
parser.on('--smtp-ip IP', 'Set the ip address of the smtp server') do |ip|
|
25
|
+
options[:smtp_ip] = ip
|
26
|
+
end
|
27
|
+
|
28
|
+
parser.on('--smtp-port PORT', Integer, 'Set the port of the smtp server') do |port|
|
29
|
+
options[:smtp_port] = port
|
30
|
+
end
|
31
|
+
|
32
|
+
parser.on('-f FROM', 'Set the sending address') do |from|
|
33
|
+
options[:from] = from
|
34
|
+
end
|
35
|
+
|
36
|
+
parser.on('-oi', 'Ignored option -oi') do |ignored|
|
37
|
+
end
|
38
|
+
parser.on('-t', 'Ignored option -t') do |ignored|
|
39
|
+
end
|
40
|
+
parser.on('-q', 'Ignored option -q') do |ignored|
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.on('-x', '--no-exit', 'Can\'t exit from the application') do
|
44
|
+
options[:no_exit] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
parser.on('-h', '--help', 'Display this help information') do
|
48
|
+
puts parser
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
end.parse!
|
52
|
+
|
53
|
+
Mail.defaults do
|
54
|
+
delivery_method :smtp,
|
55
|
+
:address => options[:smtp_ip],
|
56
|
+
:port => options[:smtp_port]
|
57
|
+
end
|
58
|
+
|
59
|
+
message = Mail.new($stdin.read)
|
60
|
+
|
61
|
+
message.return_path = options[:from] if options[:from]
|
62
|
+
|
63
|
+
ARGV.each do |recipient|
|
64
|
+
if message.to.nil?
|
65
|
+
message.to = recipient
|
66
|
+
else
|
67
|
+
message.to << recipient
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
message.deliver
|
data/bin/mailcatcher
ADDED
data/lib/mail_catcher.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "optparse"
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
require "active_support/all"
|
6
|
+
require "eventmachine"
|
7
|
+
require "thin"
|
8
|
+
|
9
|
+
if EventMachine::VERSION.in? ["1.0.4", "1.0.5"]
|
10
|
+
module EventMachine
|
11
|
+
# Monkey patch fix for 10deb4
|
12
|
+
# See https://github.com/eventmachine/eventmachine/issues/569
|
13
|
+
def self.reactor_running?
|
14
|
+
(@reactor_running || false)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "mail_catcher/events"
|
20
|
+
require "mail_catcher/mail"
|
21
|
+
require "mail_catcher/smtp"
|
22
|
+
require "mail_catcher/web"
|
23
|
+
require "mail_catcher/version"
|
24
|
+
|
25
|
+
module MailCatcher extend self
|
26
|
+
def which(command)
|
27
|
+
not windows? and Open3.popen3 'which', 'command' do |stdin, stdout, stderr|
|
28
|
+
return stdout.read.chomp.presence
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def mac?
|
33
|
+
RbConfig::CONFIG['host_os'] =~ /darwin/
|
34
|
+
end
|
35
|
+
|
36
|
+
def windows?
|
37
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
38
|
+
end
|
39
|
+
|
40
|
+
def macruby?
|
41
|
+
mac? and const_defined? :MACRUBY_VERSION
|
42
|
+
end
|
43
|
+
|
44
|
+
def browse?
|
45
|
+
windows? or which "open"
|
46
|
+
end
|
47
|
+
|
48
|
+
def browse url
|
49
|
+
if windows?
|
50
|
+
system "start", "/b", url
|
51
|
+
elsif which "open"
|
52
|
+
system "open", url
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@@defaults = {
|
57
|
+
:smtp_ip => '0.0.0.0',
|
58
|
+
:smtp_port => '1025',
|
59
|
+
:http_ip => '0.0.0.0',
|
60
|
+
:http_port => '1080',
|
61
|
+
:verbose => false,
|
62
|
+
:daemon => !windows?,
|
63
|
+
:browse => false,
|
64
|
+
:quit => true,
|
65
|
+
}
|
66
|
+
|
67
|
+
def options
|
68
|
+
@@options
|
69
|
+
end
|
70
|
+
|
71
|
+
def quittable?
|
72
|
+
options[:quit]
|
73
|
+
end
|
74
|
+
|
75
|
+
def parse! arguments=ARGV, defaults=@defaults
|
76
|
+
@@defaults.dup.tap do |options|
|
77
|
+
OptionParser.new do |parser|
|
78
|
+
parser.banner = "Usage: mailcatcher [options]"
|
79
|
+
parser.version = VERSION
|
80
|
+
|
81
|
+
parser.on("--ip IP", "Set the ip address of both servers") do |ip|
|
82
|
+
options[:smtp_ip] = options[:http_ip] = ip
|
83
|
+
end
|
84
|
+
|
85
|
+
parser.on("--smtp-ip IP", "Set the ip address of the smtp server") do |ip|
|
86
|
+
options[:smtp_ip] = ip
|
87
|
+
end
|
88
|
+
|
89
|
+
parser.on("--smtp-port PORT", Integer, "Set the port of the smtp server") do |port|
|
90
|
+
options[:smtp_port] = port
|
91
|
+
end
|
92
|
+
|
93
|
+
parser.on("--http-ip IP", "Set the ip address of the http server") do |ip|
|
94
|
+
options[:http_ip] = ip
|
95
|
+
end
|
96
|
+
|
97
|
+
parser.on("--http-port PORT", Integer, "Set the port address of the http server") do |port|
|
98
|
+
options[:http_port] = port
|
99
|
+
end
|
100
|
+
|
101
|
+
parser.on("--no-quit", "Don't allow quitting the process") do
|
102
|
+
options[:quit] = false
|
103
|
+
end
|
104
|
+
|
105
|
+
if mac?
|
106
|
+
parser.on("--[no-]growl") do |growl|
|
107
|
+
puts "Growl is no longer supported"
|
108
|
+
exit -2
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
unless windows?
|
113
|
+
parser.on('-f', '--foreground', 'Run in the foreground') do
|
114
|
+
options[:daemon] = false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
if browse?
|
119
|
+
parser.on('-b', '--browse', 'Open web browser') do
|
120
|
+
options[:browse] = true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
parser.on('-v', '--verbose', 'Be more verbose') do
|
125
|
+
options[:verbose] = true
|
126
|
+
end
|
127
|
+
|
128
|
+
parser.on('-h', '--help', 'Display this help information') do
|
129
|
+
puts parser
|
130
|
+
exit
|
131
|
+
end
|
132
|
+
end.parse!
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def run! options=nil
|
137
|
+
# If we are passed options, fill in the blanks
|
138
|
+
options &&= options.reverse_merge @@defaults
|
139
|
+
# Otherwise, parse them from ARGV
|
140
|
+
options ||= parse!
|
141
|
+
|
142
|
+
# Stash them away for later
|
143
|
+
@@options = options
|
144
|
+
|
145
|
+
# If we're running in the foreground sync the output.
|
146
|
+
unless options[:daemon]
|
147
|
+
$stdout.sync = $stderr.sync = true
|
148
|
+
end
|
149
|
+
|
150
|
+
puts "Starting MailCatcher"
|
151
|
+
|
152
|
+
Thin::Logging.silent = (ENV["MAILCATCHER_ENV"] != "development")
|
153
|
+
|
154
|
+
# One EventMachine loop...
|
155
|
+
EventMachine.run do
|
156
|
+
smtp_url = "smtp://#{options[:smtp_ip]}:#{options[:smtp_port]}"
|
157
|
+
http_url = "http://#{options[:http_ip]}:#{options[:http_port]}"
|
158
|
+
|
159
|
+
# Set up an SMTP server to run within EventMachine
|
160
|
+
rescue_port options[:smtp_port] do
|
161
|
+
EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
|
162
|
+
puts "==> #{smtp_url}"
|
163
|
+
end
|
164
|
+
|
165
|
+
# Let Thin set itself up inside our EventMachine loop
|
166
|
+
# (Skinny/WebSockets just works on the inside)
|
167
|
+
rescue_port options[:http_port] do
|
168
|
+
Thin::Server.start(options[:http_ip], options[:http_port], Web)
|
169
|
+
puts "==> #{http_url}"
|
170
|
+
end
|
171
|
+
|
172
|
+
# Open the web browser before detatching console
|
173
|
+
if options[:browse]
|
174
|
+
EventMachine.next_tick do
|
175
|
+
browse http_url
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# Daemonize, if we should, but only after the servers have started.
|
180
|
+
if options[:daemon]
|
181
|
+
EventMachine.next_tick do
|
182
|
+
if quittable?
|
183
|
+
puts "*** MailCatcher runs as a daemon by default. Go to the web interface to quit."
|
184
|
+
else
|
185
|
+
puts "*** MailCatcher is now running as a daemon that cannot be quit."
|
186
|
+
end
|
187
|
+
Process.daemon
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def quit!
|
194
|
+
EventMachine.next_tick { EventMachine.stop_event_loop }
|
195
|
+
end
|
196
|
+
|
197
|
+
protected
|
198
|
+
|
199
|
+
def rescue_port port
|
200
|
+
begin
|
201
|
+
yield
|
202
|
+
|
203
|
+
# XXX: EventMachine only spits out RuntimeError with a string description
|
204
|
+
rescue RuntimeError
|
205
|
+
if $!.to_s =~ /\bno acceptor\b/
|
206
|
+
puts "~~> ERROR: Something's using port #{port}. Are you already running MailCatcher?"
|
207
|
+
exit -1
|
208
|
+
else
|
209
|
+
raise
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|