Class: EventMachine::Protocols::SmtpServer
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Connection
|
|
Instance Chain:
self,
LineText2 ,
Connection
|
|
Inherits: |
EventMachine::Connection
|
Defined in: | lib/em/protocols/smtpserver.rb |
Overview
This is a protocol handler for the server side of SMTP. It's NOT a complete SMTP server obeying all the semantics of servers conforming to RFC2821. Rather, it uses overridable method stubs to communicate protocol states and data to user code. User code is responsible for doing the right things with the data in order to get complete and correct SMTP server behavior.
Simple SMTP server example:
class EmailServer < EM::P::SmtpServer def receive_plain_auth(user, pass) true end
def get_server_domain "mock.smtp.server.local" end
def get_server_greeting "mock smtp server greets you with impunity" end
def receive_sender(sender) current.sender = sender true end
def receive_recipient(recipient) current.recipient = recipient true end
def receive_message current.received = true current.completed_at = Time.now
p [:received_email, current]
@current = OpenStruct.new
true
end
def receive_ehlo_domain(domain) @ehlo_domain = domain true end
def receive_data_command current.data = "" true end
def receive_data_chunk(data) current.data << data.join("\n") true end
def receive_transaction if @ehlo_domain current.ehlo_domain = @ehlo_domain @ehlo_domain = nil end true end
def current @current ||= OpenStruct.new end
def self.start(host = 'localhost', port = 1025) require 'ostruct' @server = EM.start_server host, port, self end
def self.stop if @server EM.stop_server @server @server = nil end end
def self.running? !!@server end end
EM.run{ EmailServer.start }
Constant Summary
-
AuthRegex =
# File 'lib/em/protocols/smtpserver.rb', line 140/\AAUTH\s+/i
-
DataRegex =
# File 'lib/em/protocols/smtpserver.rb', line 133/\ADATA/i
-
EhloRegex =
# File 'lib/em/protocols/smtpserver.rb', line 129/\AEHLO\s*/i
-
ExpnRegex =
# File 'lib/em/protocols/smtpserver.rb', line 137/\AEXPN\s+/i
-
HeloRegex =
# File 'lib/em/protocols/smtpserver.rb', line 128/\AHELO\s*/i
-
HelpRegex =
# File 'lib/em/protocols/smtpserver.rb', line 138/\AHELP/i
-
MailFromRegex =
# File 'lib/em/protocols/smtpserver.rb', line 131/\AMAIL FROM:\s*/i
-
NoopRegex =
# File 'lib/em/protocols/smtpserver.rb', line 134/\ANOOP/i
-
QuitRegex =
# File 'lib/em/protocols/smtpserver.rb', line 130/\AQUIT/i
-
RcptToRegex =
# File 'lib/em/protocols/smtpserver.rb', line 132/\ARCPT TO:\s*/i
-
RsetRegex =
# File 'lib/em/protocols/smtpserver.rb', line 135/\ARSET/i
-
StarttlsRegex =
# File 'lib/em/protocols/smtpserver.rb', line 139/\ASTARTTLS/i
-
VrfyRegex =
# File 'lib/em/protocols/smtpserver.rb', line 136/\AVRFY\s+/i
LineText2
- Included
Class Method Summary
- .new(*args) ⇒ SmtpServer constructor
- .parms=(parms = {})
Connection
- Inherited
.new | Override .new so subclasses don't have to call super and can ignore connection-specific arguments. |
Instance Attribute Summary
Connection
- Inherited
#comm_inactivity_timeout | comm_inactivity_timeout returns the current value (float in seconds) of the inactivity-timeout property of network-connection and datagram-socket objects. |
#comm_inactivity_timeout= | Allows you to set the inactivity-timeout property for a network connection or datagram socket. |
#error? | Returns true if the connection is in an error state, false otherwise. |
#notify_readable= | Watches connection for readability. |
#notify_readable?, | |
#notify_writable= | Watches connection for writeability. |
#notify_writable? | Returns true if the connection is being watched for writability. |
#paused?, | |
#pending_connect_timeout | The duration after which a TCP connection in the connecting state will fail. |
#pending_connect_timeout= | Sets the duration after which a TCP connection in a connecting state will fail. |
#signature, #watch_only? |
Instance Method Summary
-
#connection_ended
Sent when the remote peer has ended the connection.
-
#get_server_domain
The domain name returned in the first line of the response to a successful EHLO or HELO command.
-
#get_server_greeting
The greeting returned in the initial connection message to the client.
- #init_protocol_state
- #parms=(parms = {})
-
#post_init
In SMTP, the server talks first.
- #process_auth(str)
- #process_auth_line(line)
- #process_data
-
#process_data_line(ln)
Send the incoming data to the application one chunk at a time, rather than one line at a time.
- #process_ehlo(domain)
-
#process_expn
TODO - implement this properly, the implementation is a stub!
- #process_helo(domain)
-
#process_help
TODO - implement this properly, the implementation is a stub!
- #process_mail_from(sender)
- #process_noop
- #process_quit
- #process_rcpt_to(rcpt)
- #process_rset
- #process_starttls
- #process_unknown
-
#process_vrfy
RFC2821, 3.5.3 Meaning of VRFY or EXPN Success Response:
-
#receive_data_chunk(data)
Sent when data from the remote peer is available.
-
#receive_data_command
Called when the remote peer sends the DATA command.
-
#receive_ehlo_domain(domain)
A false response from this user-overridable method will cause a 550 error to be returned to the remote client.
- #receive_line(ln)
-
#receive_message
Sent after a message has been completely received.
-
#receive_plain_auth(user, password)
Return true or false to indicate that the authentication is acceptable.
-
#receive_recipient(rcpt)
Receives the argument of a RCPT TO command.
-
#receive_reset
Sent when the remote peer issues the RSET command.
-
#receive_sender(sender)
Receives the argument of the MAIL FROM command.
-
#receive_transaction
This is called when the protocol state is reset.
- #reset_protocol_state
- #send_server_greeting
- #unbind