Class: Cybertrain::Test::ReceivedMessage
- Inherits:
-
Object
- Object
- Cybertrain::Test::ReceivedMessage
- Defined in:
- cybertrain/test/smtp_receiver.rb
Overview
What one SMTP connection carried.
Instance Attribute Summary collapse
-
#envelope_from ⇒ String
readonly
The MAIL FROM address, without the angle brackets.
-
#envelope_recipients ⇒ Array<String>
readonly
The RCPT TO addresses the receiver accepted.
-
#message_data ⇒ String
readonly
The message as it was sent after DATA: headers, a blank line, the body, CRLF line endings, dot-stuffing undone, the final “.” line removed; “” when no message was accepted.
-
#transcript ⇒ Array<String>
readonly
Every command line the client sent, in order (“EHLO localhost”, “MAIL FROM:a@example.com”, …, “QUIT”); the message itself is in #message_data, not here.
Instance Method Summary collapse
-
#delivered? ⇒ Boolean
Whether a message was accepted (the 250 after the data was sent).
-
#message_body ⇒ String
The message body: what follows the blank line after the headers.
-
#message_header(name) ⇒ String
The value of the first message header named
name(any case), unfolded; “” when there is none. -
#message_parts ⇒ Hash{String => String}
The message read back by Mailer::Message.parse:
"subject"decoded,"text"and"html"decoded from base64 (or as sent), CRLF line endings kept;"html"is “” for a plain-text message.
Instance Attribute Details
#envelope_from ⇒ String (readonly)
Returns the MAIL FROM address, without the angle brackets.
17 18 19 |
# File 'cybertrain/test/smtp_receiver.rb', line 17 def envelope_from @envelope_from end |
#envelope_recipients ⇒ Array<String> (readonly)
Returns the RCPT TO addresses the receiver accepted.
21 22 23 |
# File 'cybertrain/test/smtp_receiver.rb', line 21 def envelope_recipients @envelope_recipients end |
#message_data ⇒ String (readonly)
Returns the message as it was sent after DATA: headers, a blank line, the body, CRLF line endings, dot-stuffing undone, the final “.” line removed; “” when no message was accepted.
27 28 29 |
# File 'cybertrain/test/smtp_receiver.rb', line 27 def @message_data end |
#transcript ⇒ Array<String> (readonly)
Returns every command line the client sent, in order (“EHLO localhost”, “MAIL FROM:a@example.com”, …, “QUIT”); the message itself is in #message_data, not here.
33 34 35 |
# File 'cybertrain/test/smtp_receiver.rb', line 33 def transcript @transcript end |
Instance Method Details
#delivered? ⇒ Boolean
Whether a message was accepted (the 250 after the data was sent).
45 46 47 |
# File 'cybertrain/test/smtp_receiver.rb', line 45 def delivered? !@message_data.empty? end |
#message_body ⇒ String
The message body: what follows the blank line after the headers.
52 53 54 55 56 57 |
# File 'cybertrain/test/smtp_receiver.rb', line 52 def at = @message_data.byteindex("\r\n\r\n") return "" if at.nil? @message_data.byteslice(at + 4, @message_data.bytesize - at - 4) end |
#message_header(name) ⇒ String
The value of the first message header named name (any case),
unfolded; “” when there is none.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'cybertrain/test/smtp_receiver.rb', line 64 def (name) wanted = name.to_s.downcase data = @message_data stop = data.byteindex("\r\n\r\n") stop = data.bytesize if stop.nil? pos = 0 found = false value = String.new while pos < stop eol = data.byteindex("\r\n", pos) eol = stop if eol.nil? || eol > stop line = data.byteslice(pos, eol - pos) pos = eol + 2 continued = line.start_with?(" ") || line.start_with?("\t") if found break unless continued value << " " << line.strip elsif !continued colon = line.byteindex(":") if !colon.nil? && line.byteslice(0, colon).downcase == wanted found = true value << line.byteslice(colon + 1, line.bytesize - colon - 1).strip end end end value end |
#message_parts ⇒ Hash{String => String}
The message read back by Mailer::Message.parse:
"subject" decoded, "text" and "html" decoded from base64 (or
as sent), CRLF line endings kept; "html" is “” for a plain-text
message.
102 103 104 |
# File 'cybertrain/test/smtp_receiver.rb', line 102 def Mailer::Message.parse(@message_data) end |