Class: MailCatcher::Smtp
- Inherits:
-
EventMachine::Protocols::SmtpServer
- Object
- EventMachine::Protocols::SmtpServer
- MailCatcher::Smtp
- Defined in:
- lib/mail_catcher/smtp.rb
Instance Method Summary collapse
- #current_message ⇒ Object
-
#process_mail_from(sender) ⇒ Object
We override EM’s mail from processing to allow multiple mail-from commands per [RFC 2821](tools.ietf.org/html/rfc2821#section-4.1.1.2).
- #receive_data_chunk(lines) ⇒ Object
- #receive_message ⇒ Object
- #receive_recipient(recipient) ⇒ Object
- #receive_reset ⇒ Object
- #receive_sender(sender) ⇒ Object
Instance Method Details
#current_message ⇒ Object
20 21 22 |
# File 'lib/mail_catcher/smtp.rb', line 20 def @current_message ||= {} end |
#process_mail_from(sender) ⇒ Object
We override EM’s mail from processing to allow multiple mail-from commands per [RFC 2821](tools.ietf.org/html/rfc2821#section-4.1.1.2)
10 11 12 13 14 15 16 17 18 |
# File 'lib/mail_catcher/smtp.rb', line 10 def process_mail_from sender if @state.include? :mail_from @state -= [:mail_from, :rcpt, :data] receive_reset end super end |
#receive_data_chunk(lines) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/mail_catcher/smtp.rb', line 47 def receive_data_chunk(lines) [:source] ||= +"" lines.each do |line| [:source] << line << "\r\n" end true end |
#receive_message ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mail_catcher/smtp.rb', line 57 def MailCatcher::Mail. MailCatcher::Mail. puts "==> SMTP: Received message from '#{[:sender]}' (#{[:source].length} bytes)" true rescue => exception MailCatcher.log_exception("Error receiving message", @current_message, exception) false ensure @current_message = nil end |
#receive_recipient(recipient) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/mail_catcher/smtp.rb', line 40 def receive_recipient(recipient) [:recipients] ||= [] [:recipients] << recipient true end |
#receive_reset ⇒ Object
24 25 26 27 28 |
# File 'lib/mail_catcher/smtp.rb', line 24 def receive_reset @current_message = nil true end |
#receive_sender(sender) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/mail_catcher/smtp.rb', line 30 def receive_sender(sender) # EventMachine SMTP advertises size extensions [https://tools.ietf.org/html/rfc1870] # so strip potential " SIZE=..." suffixes from senders sender = $` if sender =~ / SIZE=\d+\z/ [:sender] = sender true end |