Module: Mailpot
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/mailpot.rb
Defined Under Namespace
Modules: Events, Mail Classes: Smtp
Constant Summary collapse
- @@defaults =
{ :smtp_ip => '127.0.0.1', :smtp_port => '1025', :verbose => false, :daemon => true, :key_file => '/etc/mailpot/keys.yml', :banner => '{host} ESMTP' }
Class Method Summary collapse
- .get_config ⇒ Object
- .parse!(arguments = ARGV, defaults = @@defaults) ⇒ Object
- .quit! ⇒ Object
- .run!(options = nil) ⇒ Object
Class Method Details
.get_config ⇒ Object
57 58 59 60 |
# File 'lib/mailpot.rb', line 57 def get_config &&= @@defaults.merge ||= parse! end |
.parse!(arguments = ARGV, defaults = @@defaults) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mailpot.rb', line 23 def parse! arguments=ARGV, defaults=@@defaults @@defaults.dup.tap do || OptionParser.new do |parser| parser. = "Usage: mailpot [options]" parser.version = File.read(File.("../../VERSION", __FILE__)) parser.on("--ip IP", "Set the ip address of the smtp server") do |ip| [:smtp_ip] = ip end parser.on("--keys KEYFILE", "Set the key file that contains AWS creds") do |f| [:key_file] = f end parser.on("--port PORT", Integer, "Set the port of the smtp server") do |port| [:smtp_port] = port end parser.on('-f', '--foreground', 'Run in forground') do [:daemon] = false end parser.on('-v', '--verbose', 'Be more verbose') do [:verbose] = true end parser.on('-h', '--help', 'Display help information') do puts parser exit! end end.parse! end end |
.quit! ⇒ Object
83 84 85 |
# File 'lib/mailpot.rb', line 83 def quit! EventMachine.next_tick {EventMachine.stop_event_loop} end |
.run!(options = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mailpot.rb', line 62 def run! =nil #options &&= @@defaults.merge options #options ||= parse! #@config = options = get_config puts "Starting MailPot" EventMachine.run do rescue_port [:smtp_port] do EventMachine.start_server [:smtp_ip], [:smtp_port], Smtp puts "==> smtp://#{[:smtp_ip]}:#{[:smtp_port]}" end if [:daemon] EventMachine.next_tick do puts "*** Mailpot now runs as a daemon by default" Process.daemon end end end end |