Class: Ronin::Support::Network::SMTP::Email
- Inherits:
-
Object
- Object
- Ronin::Support::Network::SMTP::Email
- Defined in:
- lib/ronin/support/network/smtp/email.rb
Overview
Represents an Email to be sent over Ronin::Support::Network::SMTP.
Constant Summary collapse
- CRLF =
The CR-LF String
"\n\r"
Instance Attribute Summary collapse
-
#body ⇒ String+
Body of the email.
-
#date ⇒ String, Time
Date of the email.
-
#from ⇒ String
Sender of the email.
-
#headers ⇒ Hash{String => String}
readonly
Additional headers.
-
#message_id ⇒ String
Unique message-id string.
-
#subject ⇒ String
Subject of the email.
-
#to ⇒ Array<#to_s>, String
Recipient of the email.
Instance Method Summary collapse
-
#initialize(from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) {|email| ... } ⇒ Email
constructor
Creates a new Email object.
-
#to_s ⇒ String
Formats the email into a SMTP message.
Constructor Details
#initialize(from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) {|email| ... } ⇒ Email
Creates a new Email object.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ronin/support/network/smtp/email.rb', line 99 def initialize(from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) @from = from @to = to @subject = subject @date = date @message_id = @headers = {} @headers.merge!(headers) if headers @body = [] if body case body when Array @body += body else @body << body end end yield self if block_given? end |
Instance Attribute Details
#body ⇒ String+
Body of the email
64 65 66 |
# File 'lib/ronin/support/network/smtp/email.rb', line 64 def body @body end |
#date ⇒ String, Time
Date of the email
49 50 51 |
# File 'lib/ronin/support/network/smtp/email.rb', line 49 def date @date end |
#from ⇒ String
Sender of the email
34 35 36 |
# File 'lib/ronin/support/network/smtp/email.rb', line 34 def from @from end |
#headers ⇒ Hash{String => String} (readonly)
Additional headers
59 60 61 |
# File 'lib/ronin/support/network/smtp/email.rb', line 59 def headers @headers end |
#message_id ⇒ String
Unique message-id string
54 55 56 |
# File 'lib/ronin/support/network/smtp/email.rb', line 54 def @message_id end |
#subject ⇒ String
Subject of the email
44 45 46 |
# File 'lib/ronin/support/network/smtp/email.rb', line 44 def subject @subject end |
Instance Method Details
#to_s ⇒ String
Formats the email into a SMTP message.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/ronin/support/network/smtp/email.rb', line 139 def to_s = [] if @from << "From: #{@from}" end if @to << case @to when Array "To: #{@to.join(', ')}" else "To: #{@to}" end end if @subject << "Subject: #{@subject}" end if @date << "Date: #{@date}" end if @message_id << "Message-Id: <#{@message_id}>" end @headers.each do |name,value| << "#{name}: #{value}" end << '' += @body return .join(CRLF) end |