mydriver-mailcatcher 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +120 -0
- data/bin/catchmail +71 -0
- data/bin/mailcatcher +5 -0
- data/lib/mail_catcher.rb +229 -0
- data/lib/mail_catcher/events.rb +7 -0
- data/lib/mail_catcher/mail.rb +160 -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 +337 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de9729793fe1b6b8a7a3d86cfb22d0e89d701ba1
|
4
|
+
data.tar.gz: 2bdda3f90900a6d323da3433a681a25cee920e95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e6a6f632e351ae3935d81ae4d4bab96583453c926a50dc4d48bac490d3cbd0abf90add273bcf32afee1223d55ca5bd4d3c2bd7c5d3c1118a0941c86b4951803
|
7
|
+
data.tar.gz: 2b87ccbeb8103e7b82c8f25e42d38cf82317ab845eba3ef0abf74d235fb49a56baacbe07003a9207015f92bfdbc1689d53573b10841df6d8c6f242fdf079c3d4
|
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,120 @@
|
|
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
|
+
![MailCatcher screenshot](https://cloud.githubusercontent.com/assets/14028/14093249/4100f904-f598-11e5-936b-e6a396f18e39.png)
|
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
|
+
* Compatibility testing against CampaignMonitor's [design guidelines](http://www.campaignmonitor.com/design-guidelines/) and [CSS support matrix](http://www.campaignmonitor.com/css/).
|
94
|
+
* Forward mail to rendering service, maybe CampaignMonitor?
|
95
|
+
|
96
|
+
## Thanks
|
97
|
+
|
98
|
+
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.
|
99
|
+
|
100
|
+
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.
|
101
|
+
|
102
|
+
## Donations
|
103
|
+
|
104
|
+
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).
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
Copyright © 2010-2011 Samuel Cochran (sj26@sj26.com). Released under the MIT License, see [LICENSE][license] for details.
|
109
|
+
|
110
|
+
## Dreams
|
111
|
+
|
112
|
+
For dream catching, try [this](http://goo.gl/kgbh). OR [THIS](http://www.nyanicorn.com), OMG.
|
113
|
+
|
114
|
+
[donate]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=522WUPLRWUSKE
|
115
|
+
[license]: https://github.com/sj26/mailcatcher/blob/master/LICENSE
|
116
|
+
[mailcatcher-github]: https://github.com/sj26/mailcatcher
|
117
|
+
[mailcatcher-issues]: https://github.com/sj26/mailcatcher/issues
|
118
|
+
[tfg]: http://www.thefrontiergroup.com.au
|
119
|
+
[websockets]: http://www.whatwg.org/specs/web-socket-protocol/
|
120
|
+
[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,229 @@
|
|
1
|
+
# Apparently rubygems won't activate these on its own, so here we go. Let's
|
2
|
+
# repeat the invention of Bundler all over again.
|
3
|
+
gem "activesupport", "~> 4.0"
|
4
|
+
gem "eventmachine", "1.0.9.1"
|
5
|
+
gem "mail", "~> 2.3"
|
6
|
+
gem "rack", "~> 1.5"
|
7
|
+
gem "sinatra", "~> 1.2"
|
8
|
+
gem "sqlite3", "~> 1.3"
|
9
|
+
gem "thin", "~> 1.5.0"
|
10
|
+
gem "skinny", "~> 0.2.3"
|
11
|
+
|
12
|
+
require "open3"
|
13
|
+
require "optparse"
|
14
|
+
require "rbconfig"
|
15
|
+
|
16
|
+
require "active_support/all"
|
17
|
+
require "eventmachine"
|
18
|
+
require "thin"
|
19
|
+
|
20
|
+
module EventMachine
|
21
|
+
# Monkey patch fix for 10deb4
|
22
|
+
# See https://github.com/eventmachine/eventmachine/issues/569
|
23
|
+
def self.reactor_running?
|
24
|
+
(@reactor_running || false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require "mail_catcher/events"
|
29
|
+
require "mail_catcher/mail"
|
30
|
+
require "mail_catcher/smtp"
|
31
|
+
require "mail_catcher/web"
|
32
|
+
require "mail_catcher/version"
|
33
|
+
|
34
|
+
module MailCatcher extend self
|
35
|
+
def which(command)
|
36
|
+
not windows? and Open3.popen3 'which', 'command' do |stdin, stdout, stderr|
|
37
|
+
return stdout.read.chomp.presence
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def mac?
|
42
|
+
RbConfig::CONFIG['host_os'] =~ /darwin/
|
43
|
+
end
|
44
|
+
|
45
|
+
def windows?
|
46
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
47
|
+
end
|
48
|
+
|
49
|
+
def macruby?
|
50
|
+
mac? and const_defined? :MACRUBY_VERSION
|
51
|
+
end
|
52
|
+
|
53
|
+
def browse?
|
54
|
+
windows? or which "open"
|
55
|
+
end
|
56
|
+
|
57
|
+
def browse url
|
58
|
+
if windows?
|
59
|
+
system "start", "/b", url
|
60
|
+
elsif which "open"
|
61
|
+
system "open", url
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
@@defaults = {
|
66
|
+
:smtp_ip => '127.0.0.1',
|
67
|
+
:smtp_port => '1025',
|
68
|
+
:http_ip => '127.0.0.1',
|
69
|
+
:http_port => '1080',
|
70
|
+
:verbose => false,
|
71
|
+
:daemon => !windows?,
|
72
|
+
:browse => false,
|
73
|
+
:quit => true,
|
74
|
+
}
|
75
|
+
|
76
|
+
def options
|
77
|
+
@@options
|
78
|
+
end
|
79
|
+
|
80
|
+
def quittable?
|
81
|
+
options[:quit]
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse! arguments=ARGV, defaults=@defaults
|
85
|
+
@@defaults.dup.tap do |options|
|
86
|
+
OptionParser.new do |parser|
|
87
|
+
parser.banner = "Usage: mailcatcher [options]"
|
88
|
+
parser.version = VERSION
|
89
|
+
|
90
|
+
parser.on("--ip IP", "Set the ip address of both servers") do |ip|
|
91
|
+
options[:smtp_ip] = options[:http_ip] = ip
|
92
|
+
end
|
93
|
+
|
94
|
+
parser.on("--smtp-ip IP", "Set the ip address of the smtp server") do |ip|
|
95
|
+
options[:smtp_ip] = ip
|
96
|
+
end
|
97
|
+
|
98
|
+
parser.on("--smtp-port PORT", Integer, "Set the port of the smtp server") do |port|
|
99
|
+
options[:smtp_port] = port
|
100
|
+
end
|
101
|
+
|
102
|
+
parser.on("--http-ip IP", "Set the ip address of the http server") do |ip|
|
103
|
+
options[:http_ip] = ip
|
104
|
+
end
|
105
|
+
|
106
|
+
parser.on("--http-port PORT", Integer, "Set the port address of the http server") do |port|
|
107
|
+
options[:http_port] = port
|
108
|
+
end
|
109
|
+
|
110
|
+
parser.on("--no-quit", "Don't allow quitting the process") do
|
111
|
+
options[:quit] = false
|
112
|
+
end
|
113
|
+
|
114
|
+
if mac?
|
115
|
+
parser.on("--[no-]growl") do |growl|
|
116
|
+
puts "Growl is no longer supported"
|
117
|
+
exit -2
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
unless windows?
|
122
|
+
parser.on('-f', '--foreground', 'Run in the foreground') do
|
123
|
+
options[:daemon] = false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
if browse?
|
128
|
+
parser.on('-b', '--browse', 'Open web browser') do
|
129
|
+
options[:browse] = true
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
parser.on('-v', '--verbose', 'Be more verbose') do
|
134
|
+
options[:verbose] = true
|
135
|
+
end
|
136
|
+
|
137
|
+
parser.on('-h', '--help', 'Display this help information') do
|
138
|
+
puts parser
|
139
|
+
exit
|
140
|
+
end
|
141
|
+
end.parse!
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def run! options=nil
|
146
|
+
# If we are passed options, fill in the blanks
|
147
|
+
options &&= options.reverse_merge @@defaults
|
148
|
+
# Otherwise, parse them from ARGV
|
149
|
+
options ||= parse!
|
150
|
+
|
151
|
+
# Stash them away for later
|
152
|
+
@@options = options
|
153
|
+
|
154
|
+
# If we're running in the foreground sync the output.
|
155
|
+
unless options[:daemon]
|
156
|
+
$stdout.sync = $stderr.sync = true
|
157
|
+
end
|
158
|
+
|
159
|
+
puts "Starting MailCatcher"
|
160
|
+
|
161
|
+
Thin::Logging.silent = (ENV["MAILCATCHER_ENV"] != "development")
|
162
|
+
|
163
|
+
# One EventMachine loop...
|
164
|
+
EventMachine.run do
|
165
|
+
# Set up an SMTP server to run within EventMachine
|
166
|
+
rescue_port options[:smtp_port] do
|
167
|
+
EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
|
168
|
+
puts "==> #{smtp_url}"
|
169
|
+
end
|
170
|
+
|
171
|
+
# Let Thin set itself up inside our EventMachine loop
|
172
|
+
# (Skinny/WebSockets just works on the inside)
|
173
|
+
rescue_port options[:http_port] do
|
174
|
+
Thin::Server.start(options[:http_ip], options[:http_port], Web)
|
175
|
+
puts "==> #{http_url}"
|
176
|
+
end
|
177
|
+
|
178
|
+
# Open the web browser before detatching console
|
179
|
+
if options[:browse]
|
180
|
+
EventMachine.next_tick do
|
181
|
+
browse http_url
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Daemonize, if we should, but only after the servers have started.
|
186
|
+
if options[:daemon]
|
187
|
+
EventMachine.next_tick do
|
188
|
+
if quittable?
|
189
|
+
puts "*** MailCatcher runs as a daemon by default. Go to the web interface to quit."
|
190
|
+
else
|
191
|
+
puts "*** MailCatcher is now running as a daemon that cannot be quit."
|
192
|
+
end
|
193
|
+
Process.daemon
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def quit!
|
200
|
+
EventMachine.next_tick { EventMachine.stop_event_loop }
|
201
|
+
end
|
202
|
+
|
203
|
+
protected
|
204
|
+
|
205
|
+
def smtp_url
|
206
|
+
"smtp://#{@@options[:smtp_ip]}:#{@@options[:smtp_port]}"
|
207
|
+
end
|
208
|
+
|
209
|
+
def http_url
|
210
|
+
"http://#{@@options[:http_ip]}:#{@@options[:http_port]}"
|
211
|
+
end
|
212
|
+
|
213
|
+
def rescue_port port
|
214
|
+
begin
|
215
|
+
yield
|
216
|
+
|
217
|
+
# XXX: EventMachine only spits out RuntimeError with a string description
|
218
|
+
rescue RuntimeError
|
219
|
+
if $!.to_s =~ /\bno acceptor\b/
|
220
|
+
puts "~~> ERROR: Something's using port #{port}. Are you already running MailCatcher?"
|
221
|
+
puts "==> #{smtp_url}"
|
222
|
+
puts "==> #{http_url}"
|
223
|
+
exit -1
|
224
|
+
else
|
225
|
+
raise
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|