Class | EventMachine::Protocols::SmtpServer
In: | lib/protocols/smtpserver.rb
Parent: | EventMachine::Connection

### Methods

connection_ended get_server_domain get_server_greeting init_protocol_state new parms= parms= post_init process_auth process_data process_data_line process_ehlo process_expn process_helo process_help process_mail_from process_noop process_quit process_rcpt_to process_rset process_starttls process_unknown process_vrfy receive_data_chunk receive_data_command receive_ehlo_domain receive_line receive_message receive_plain_auth receive_recipient receive_reset receive_sender receive_transaction reset_protocol_state send_server_greeting unbind

### Included Modules

Protocols::LineText2

### Constants

HeloRegex | = | /\AHELO\s*/i
EhloRegex | = | /\AEHLO\s*/i
QuitRegex | = | /\AQUIT/i
MailFromRegex | = | /\AMAIL FROM:\s*/i
RcptToRegex | = | /\ARCPT TO:\s*/i
DataRegex | = | /\ADATA/i
NoopRegex | = | /\ANOOP/i
RsetRegex | = | /\ARSET/i
VrfyRegex | = | /\AVRFY\s+/i
ExpnRegex | = | /\AEXPN\s+/i
HelpRegex | = | /\AHELP/i
StarttlsRegex | = | /\ASTARTTLS/i
AuthRegex | = | /\AAUTH\s+/i

### Public Class methods

new(*args)
parms=(parms={})

### Public Instance methods

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. But by a (perhaps flawed) axiom in EM, post_init will execute BEFORE the block passed to start_server, for any given accepted connection. Since in this class we‘ll probably be getting a lot of initialization parameters, we want the guts of post_init to run AFTER the application has initialized the connection object. So we use a spawn to schedule the post_init to run later. It‘s a little weird, I admit. A reasonable alternative would be to set parameters as a class variable and to do that before accepting any connections.

OBSOLETE, now we have @@parms. But the spawn is nice to keep as an illustration.

process_auth(str)
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. That lets the application be a little more flexible about storing to disk, etc. Since we clear the chunk array every time we submit it, the caller needs to be aware to do things like dup it if he wants to keep it around across calls.

DON‘T reset the transaction upon disposition of the incoming message. This means another DATA command can be accepted with the same sender and recipients. If the client wants to reset, he can call RSET. Not sure whether the standard requires a transaction-reset at this point, but it appears not to.

User-written code can return a Deferrable as a response from receive_message.

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()

TODO - implement this properly, the implementation is a stub!

receive_data_chunk(data)

Sent when data from the remote peer is available. The size can be controlled by setting the :chunksize parameter. This call can be made multiple times. The goal is to strike a balance between sending the data to the application one line at a time, and holding all of a very large message in memory.

receive_data_command()

Called when the remote peer sends the DATA command. Returning false will cause us to send a 550 error to the peer. This can be useful for dealing with problems that arise from processing the whole set of sender and recipients.

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. User code must return true or false to indicate whether the message has been accepted for delivery.

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. Can be given multiple times per transaction. Return false to reject the recipient.

receive_reset()

Sent when the remote peer issues the RSET command. Since RSET is not allowed to fail (according to the protocol), we ignore any return value from user overrides of this method.

receive_sender(sender)

Receives the argument of the MAIL FROM command. Return false to indicate to the remote client that the sender is not accepted. This can only be successfully called once per transaction.

receive_transaction()

This is called when the protocol state is reset. It happens when the remote client calls EHLO/HELO or RSET.

reset_protocol_state()
send_server_greeting()
unbind()

[Validate]