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

Class Method Details

.get_configObject



57
58
59
60
# File 'lib/mailpot.rb', line 57

def get_config
 options &&= @@defaults.merge options
 options ||= 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 |options|
  OptionParser.new do |parser|
   parser.banner = "Usage: mailpot [options]"
   parser.version = File.read(File.expand_path("../../VERSION", __FILE__))
   
   parser.on("--ip IP", "Set the ip address of the smtp server") do |ip|
    options[:smtp_ip] = ip
   end
   
   parser.on("--keys KEYFILE", "Set the key file that contains AWS creds") do |f|
    options[:key_file] = f
   end
   
   parser.on("--port PORT", Integer, "Set the port of the smtp server") do |port|
    options[:smtp_port] = port
   end
   
   parser.on('-f', '--foreground', 'Run in forground') do
    options[:daemon] = false
   end
   
   parser.on('-v', '--verbose', 'Be more verbose') do
    options[: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! options=nil
 #options &&= @@defaults.merge options
 #options ||= parse!
 #@config = options
 options = get_config
 puts "Starting MailPot"
 EventMachine.run do
  rescue_port options[:smtp_port] do
   EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
   puts "==> smtp://#{options[:smtp_ip]}:#{options[:smtp_port]}"
  end
  
  if options[:daemon]
   EventMachine.next_tick do
    puts "*** Mailpot now runs as a daemon by default"
    Process.daemon
   end
  end
 end
end