Commit 4645809

mokha <mokha@cisco.com>
2019-03-18 18:58:18
allow passing mail body via stdin.
1 parent fb95ec6
Changed files (3)
lib/minbox/cli.rb
@@ -22,7 +22,7 @@ module Minbox
           x.to = options[:to]
           x.from = options[:from]
           x.subject = options[:subject]
-          x.body = options[:body]
+          x.body = (STDIN.tty?) ? options[:body] : $stdin.read
         end
         Net::SMTP.start(host, port) do |smtp|
           smtp.debug_output = Minbox.logger
@@ -35,7 +35,8 @@ module Minbox
       desc 'server <HOST> <PORT>', 'SMTP server'
       def server(host = 'localhost', port = '25')
         publisher = Publisher.from(options[:output])
-        Server.new(host, port, options[:tls]).listen! do |mail|
+        server = Server.new(host: host, port: port, tls: options[:tls])
+        server.listen! do |mail|
           publisher.publish(mail)
         end
       end
lib/minbox/publisher.rb
@@ -50,7 +50,7 @@ module Minbox
     end
 
     def add(publisher)
-      publishers.push(publisher)
+      publishers << publisher
     end
 
     def publish(mail)
lib/minbox/server.rb
@@ -5,14 +5,14 @@ module Minbox
     SUBJECT = '/C=CA/ST=AB/L=Calgary/O=minbox/OU=development/CN=minbox'
     attr_reader :host, :logger, :key, :server
 
-    def initialize(host = 'localhost', port = 25, tls = false, logger = Minbox.logger)
+    def initialize(host: 'localhost', port: 25, tls: false, logger: Minbox.logger, thread_pool: Concurrent::CachedThreadPool.new)
       @host = host
       @logger = logger
       @tls = tls
       @key = OpenSSL::PKey::RSA.new(2048)
       logger.debug("Starting server on port #{port}...")
       @server = TCPServer.new(port.to_i)
-      @thread_pool = Concurrent::CachedThreadPool.new
+      @thread_pool = thread_pool
     end
 
     def tls?