2011-05-29 00:39:45 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
# Make sure we can require vendored gems
|
|
|
|
$:.unshift(*Dir.glob(File.expand_path("../../vendor/gems/*/lib", __FILE__)))
|
|
|
|
|
|
|
|
require "optparse"
|
2011-05-29 00:39:45 -04:00
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
require "mail"
|
2011-05-29 00:39:45 -04:00
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
options = {:smtp_ip => "127.0.0.1", :smtp_port => 1025}
|
2011-05-29 00:39:45 -04:00
|
|
|
|
|
|
|
OptionParser.new do |parser|
|
|
|
|
parser.banner = <<-BANNER.gsub /^ +/, ""
|
2015-01-16 23:21:13 -05:00
|
|
|
Usage: catchmail [options] [recipient ...]
|
2011-05-29 00:39:45 -04:00
|
|
|
sendmail-like interface to forward mail to MailCatcher.
|
|
|
|
BANNER
|
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("--ip IP") do |ip|
|
2011-05-29 00:39:45 -04:00
|
|
|
options[:smtp_ip] = ip
|
|
|
|
end
|
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("--smtp-ip IP", "Set the ip address of the smtp server") do |ip|
|
2011-05-29 00:39:45 -04:00
|
|
|
options[:smtp_ip] = ip
|
|
|
|
end
|
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("--smtp-port PORT", Integer, "Set the port of the smtp server") do |port|
|
2011-05-29 00:39:45 -04:00
|
|
|
options[:smtp_port] = port
|
|
|
|
end
|
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("-f FROM", "Set the sending address") do |from|
|
2012-01-23 02:29:10 -05:00
|
|
|
options[:from] = from
|
|
|
|
end
|
2014-03-17 01:31:05 -04:00
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("-oi", "Ignored option -oi") do |ignored|
|
2013-09-05 11:05:08 -04:00
|
|
|
end
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("-t", "Ignored option -t") do |ignored|
|
2013-09-05 11:05:08 -04:00
|
|
|
end
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("-q", "Ignored option -q") do |ignored|
|
2013-09-05 11:05:08 -04:00
|
|
|
end
|
2012-01-23 02:29:10 -05:00
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("-x", "--no-exit", "Can't exit from the application") do
|
2013-05-13 07:27:06 -04:00
|
|
|
options[:no_exit] = true
|
|
|
|
end
|
|
|
|
|
2016-07-21 02:28:54 -04:00
|
|
|
parser.on("-h", "--help", "Display this help information") do
|
2011-05-29 00:39:45 -04:00
|
|
|
puts parser
|
|
|
|
exit!
|
|
|
|
end
|
|
|
|
end.parse!
|
|
|
|
|
|
|
|
Mail.defaults do
|
|
|
|
delivery_method :smtp,
|
|
|
|
:address => options[:smtp_ip],
|
|
|
|
:port => options[:smtp_port]
|
|
|
|
end
|
|
|
|
|
2015-01-16 23:21:13 -05:00
|
|
|
message = Mail.new($stdin.read)
|
|
|
|
|
2012-01-23 02:29:10 -05:00
|
|
|
message.return_path = options[:from] if options[:from]
|
2015-01-16 23:21:13 -05:00
|
|
|
|
|
|
|
ARGV.each do |recipient|
|
|
|
|
if message.to.nil?
|
|
|
|
message.to = recipient
|
|
|
|
else
|
|
|
|
message.to << recipient
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-23 02:29:10 -05:00
|
|
|
message.deliver
|