Class: RExchange::Message
- Inherits:
-
GenericItem
- Object
- GenericItem
- RExchange::Message
- Defined in:
- lib/rexchange/message.rb
Instance Attribute Summary
Attributes inherited from GenericItem
Instance Method Summary collapse
-
#delete! ⇒ Object
Delete this message.
- #fetch(uri_str, limit = 10) ⇒ Object
- #mark_as_read ⇒ Object
-
#move_to(folder) ⇒ Object
Move this message to the specified folder.
- #raw ⇒ Object
- #to_s ⇒ Object
Methods inherited from GenericItem
attribute_mappings, find, inherited, #initialize, set_content_class, set_folder_type
Constructor Details
This class inherits a constructor from RExchange::GenericItem
Instance Method Details
#delete! ⇒ Object
Delete this message.
Example
mailbox.inbox.each do ||
.delete!
end
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rexchange/message.rb', line 42 def delete! response = DavDeleteRequest.execute(@session, self.href) case response.code when 204 then # Standard success response. ( http://msdn.microsoft.com/en-us/library/aa142839(EXCHG.65).aspx ) true when 423 then # The destination resource is locked. false end end |
#fetch(uri_str, limit = 10) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rexchange/message.rb', line 63 def fetch(uri_str, limit = 10) # You should choose better exception. raise ArgumentError, 'HTTP redirect too deep' if limit == 0 response = DavGetRequest.execute(@session, uri_str) case response when Net::HTTPSuccess then response.body when Net::HTTPRedirection then fetch(response['location'], limit - 1) else response.error! end end |
#mark_as_read ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/rexchange/message.rb', line 77 def mark_as_read response = DavProppatchRequest.execute(@session, self.href, RExchange::PR_HTTPMAIL_READ, RExchange::NS_HTTPMAIL, 1) case response when Net::HTTPSuccess then true else false end end |
#move_to(folder) ⇒ Object
Move this message to the specified folder. The folder can be a string such as ‘inbox/archive’ or a RExchange::Folder.
Example
mailbox.inbox.each do ||
.move_to mailbox.inbox.archive
end
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rexchange/message.rb', line 26 def move_to(folder) destination = if folder.is_a?(RExchange::Folder) folder.to_s.ensure_ends_with('/') + self.href.split('/').last else @session.uri.path.ensure_ends_with('/') + folder.to_s.ensure_ends_with('/') + self.href.split('/').last end DavMoveRequest.execute(@session, self.href, destination) end |
#raw ⇒ Object
59 60 61 |
# File 'lib/rexchange/message.rb', line 59 def raw fetch(href, limit = 10) end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/rexchange/message.rb', line 55 def to_s "To: #{to}, From: #{from}, Subject: #{subject}" end |