Class: Hotmailer::Message
- Inherits:
-
Object
- Object
- Hotmailer::Message
- Defined in:
- lib/hotmailer.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#from_email ⇒ Object
readonly
Returns the value of attribute from_email.
-
#from_name ⇒ Object
readonly
Returns the value of attribute from_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #delete ⇒ Object
- #forward(to) ⇒ Object
-
#initialize(parent, opts = {}) ⇒ Message
constructor
A new instance of Message.
- #read ⇒ Object (also: #body)
Constructor Details
#initialize(parent, opts = {}) ⇒ Message
Returns a new instance of Message.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/hotmailer.rb', line 196 def initialize(parent,opts = {}) @from_email = opts[:from_email] @from_name = opts[:from_name] @status = opts[:status] @link = opts[:link] @subject = opts[:subject] @date = opts[:date] @size = opts[:size] @body = '' @parent = parent #Get message id @link =~ /msg=(.+)/ @id = $1 end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def date @date end |
#from_email ⇒ Object (readonly)
Returns the value of attribute from_email.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def from_email @from_email end |
#from_name ⇒ Object (readonly)
Returns the value of attribute from_name.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def from_name @from_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def id @id end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def link @link end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def parent @parent end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def status @status end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
193 194 195 |
# File 'lib/hotmailer.rb', line 193 def subject @subject end |
Instance Method Details
#delete ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/hotmailer.rb', line 231 def delete #Used to delete the message #Get message page, and all links on page msg_page = parent.get(self.link) links = (msg_page/"a") #Get delete link del_a = links.find {|a| a.inner_html == 'Delete' } if del_a.attributes['onclick'] =~ /G\('([^']+)'/ del_link = $1 else raise "Could not find delete link - hotmail layout changed?" end res_page = parent.get(del_link) #Remove self from parent's messages array parent..delete(self) return true if res_page.body =~ /Mail/ end |
#forward(to) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/hotmailer.rb', line 252 def forward(to) #Forward this message f_url = "/cgi-bin/compose?type=f&msg=#{self.id}&"+parent.inbox f_page = parent.get(f_url) fwd_form = f_page.form('composeform') fwd_form.to = to res_page = parent.submit(fwd_form) if res_page.body =~ /Your message has been sent/ return true else raise "Error forwarding message" end end |
#read ⇒ Object Also known as: body
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/hotmailer.rb', line 211 def read #Used to read the message's contents (in plain text) return @body unless @body.empty? msg_link = self.link+"&raw=0&"+@parent.inbox msg_page = @parent.get(msg_link) raw_text = (msg_page/"pre")[0].inner_html if raw_text =~ /\n\n(.+)/m msg_text = $1 else msg_text = '' end @body = msg_text return @body end |