Class: Ronin::Network::SMTP::Email
- Defined in:
- lib/ronin/network/smtp/email.rb
Overview
Represents an Email to be sent over Ronin::Network::SMTP.
Constant Summary collapse
- CRLF =
"\n\r"
Instance Attribute Summary collapse
-
#body ⇒ Object
Body of the email.
-
#date ⇒ Object
Date of the email.
-
#from ⇒ Object
Sender of the email.
-
#headers ⇒ Object
readonly
Additional headers.
-
#message_id ⇒ Object
Unique message-id string.
-
#subject ⇒ Object
Subject of the email.
-
#to ⇒ Object
Recipient of the email.
Instance Method Summary collapse
-
#initialize(options = {}) {|email| ... } ⇒ Email
constructor
Creates a new Email object.
-
#to_s ⇒ String
Formats the email into a SMTP message.
Constructor Details
#initialize(options = {}) {|email| ... } ⇒ Email
Creates a new Email object.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ronin/network/smtp/email.rb', line 87 def initialize(={}) @from = [:from] @to = [:to] @subject = [:subject] @date = .fetch(:date,Time.now) @message_id = [:message_id] @headers = {} if [:headers] @headers.merge!([:headers]) end @body = [] if [:body] case [:body] when Array @body += [:body] else @body << [:body] end end yield self if block_given? end |
Instance Attribute Details
#body ⇒ Object
Body of the email
49 50 51 |
# File 'lib/ronin/network/smtp/email.rb', line 49 def body @body end |
#date ⇒ Object
Date of the email
40 41 42 |
# File 'lib/ronin/network/smtp/email.rb', line 40 def date @date end |
#from ⇒ Object
Sender of the email
31 32 33 |
# File 'lib/ronin/network/smtp/email.rb', line 31 def from @from end |
#headers ⇒ Object (readonly)
Additional headers
46 47 48 |
# File 'lib/ronin/network/smtp/email.rb', line 46 def headers @headers end |
#message_id ⇒ Object
Unique message-id string
43 44 45 |
# File 'lib/ronin/network/smtp/email.rb', line 43 def @message_id end |
#subject ⇒ Object
Subject of the email
37 38 39 |
# File 'lib/ronin/network/smtp/email.rb', line 37 def subject @subject end |
#to ⇒ Object
Recipient of the email
34 35 36 |
# File 'lib/ronin/network/smtp/email.rb', line 34 def to @to end |
Instance Method Details
#to_s ⇒ String
Formats the email into a SMTP message.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 |
# File 'lib/ronin/network/smtp/email.rb', line 123 def to_s address = lambda { |info| case info when Array "#{info[0]} <#{info[1]}>" else info end } = [] 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 |