Class: Percolate::Listener
- Inherits:
-
Object
- Object
- Percolate::Listener
- Defined in:
- lib/percolate/listener.rb
Constant Summary collapse
- CRLF =
"\r\n"
Instance Attribute Summary collapse
-
#hostname ⇒ Object
My current hostname as return by the HELO and EHLO commands.
Instance Method Summary collapse
-
#go(&block) ⇒ Object
Once the listener is running, let it start handling mail by invoking the poorly-named “go” method.
-
#initialize(opts = {}) ⇒ Listener
constructor
The constructor for an smtp listener.
Constructor Details
#initialize(opts = {}) ⇒ Listener
The constructor for an smtp listener. This has a number of options you can give it, a lot of which already have defaults.
- :verbose_debug
-
Just turns on lots of debugging output.
- :responder
-
The responder class you want to use as a responder. This defaults to, as you might expect, SMTP::Responder, but really I want you to subclass that and write your own mail handling code. Its normal default behaviour is to act as a sort of null MTA, accepting and cheerfully discarding messages.
- :ipaddress
-
The IP address you want this to listen on. Defaults to 0.0.0.0 (all available interfaces)
:port The port to listen on. I have it default
to 10025 rather than, as you might expect,
25, because 25 is a privileged port and so
you have to be root to listen on it.
Unless you're foolish enough to try
building a real MTA on this (just leave
that kind of foolishness to me), just stick
to leaving this at a high port and letting
Postfix or Sendmail or your real MTA of
choice filter through it.
33 34 35 36 37 38 39 40 41 |
# File 'lib/percolate/listener.rb', line 33 def initialize(opts = {}) @verbose_debug = opts[:debug] || false @ipaddress = opts[:ipaddr] || "0.0.0.0" @port = opts[:port] || 10025 @hostname = opts[:hostname] || "localhost" @responder = opts[:responder] || SMTP::Responder @socket = TCPServer.new @ipaddress, @port end |
Instance Attribute Details
#hostname ⇒ Object
My current hostname as return by the HELO and EHLO commands
44 45 46 |
# File 'lib/percolate/listener.rb', line 44 def hostname @hostname end |
Instance Method Details
#go(&block) ⇒ Object
Once the listener is running, let it start handling mail by invoking the poorly-named “go” method.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/percolate/listener.rb', line 48 def go &block trap 'CLD' do debug "Got SIGCHLD" reap_children end trap 'INT' do debug "Got SIGINT" cleanup_and_exit end @pids = [] while mailsocket=@socket.accept debug "Got connection from #{mailsocket.peeraddr[3]}" pid = handle_connection mailsocket, &block mailsocket.close @pids << pid end end |