Class: RExchange::MessageHref
- Inherits:
-
Object
- Object
- RExchange::MessageHref
- Defined in:
- lib/rexchange/message_href.rb
Class Method Summary collapse
-
.find_message_hrefs(href_regex, credentials, path, conditions = nil) ⇒ Object
Retrieve an Array of hrefs to items (such as Contact, Message, etc).
- .query(path) ⇒ Object
Instance Method Summary collapse
-
#delete! ⇒ Object
Delete this message.
- #fetch(uri_str, limit = 10) ⇒ Object
-
#initialize(session, href) ⇒ MessageHref
constructor
A new instance of MessageHref.
- #mark_as_read ⇒ Object
-
#move_to(folder) ⇒ Object
Move this message to the specified folder.
- #raw ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(session, href) ⇒ MessageHref
Returns a new instance of MessageHref.
7 8 9 10 |
# File 'lib/rexchange/message_href.rb', line 7 def initialize(session, href) @href = href @session = session end |
Class Method Details
.find_message_hrefs(href_regex, credentials, path, conditions = nil) ⇒ Object
Retrieve an Array of hrefs to items (such as Contact, Message, etc)
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rexchange/message_href.rb', line 89 def self.(href_regex, credentials, path, conditions = nil) qbody = <<-QBODY <D:searchrequest xmlns:D = "DAV:"> <D:sql> #{query(path)} </D:sql> </D:searchrequest> QBODY items = [] DavSearchRequest.execute(credentials, :body => qbody) do |response| response.body.scan(href_regex){|m| items << self.new(credentials, m[0]) if m[0] } end items end |
.query(path) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rexchange/message_href.rb', line 76 def self.query(path) <<-QBODY SELECT "DAV:href" FROM SCOPE('shallow traversal of "#{path}"') WHERE "DAV:ishidden" = false AND "DAV:isfolder" = false QBODY # AND "DAV:contentclass" = 'urn:content-classes:message' end |
Instance Method Details
#delete! ⇒ Object
Delete this message.
Example
mailbox.inbox.each do ||
.delete!
end
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rexchange/message_href.rb', line 35 def delete! uri_str = @href response = DavDeleteRequest.execute(@session, @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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rexchange/message_href.rb', line 57 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 puts "URI #{@href}" response.error! end end |
#mark_as_read ⇒ Object
72 73 74 |
# File 'lib/rexchange/message_href.rb', line 72 def mark_as_read DavProppatchRequest.execute(@session, @href, RExchange::PR_HTTPMAIL_READ, RExchange::NS_HTTPMAIL, 1) 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
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rexchange/message_href.rb', line 18 def move_to(folder) destination = if folder.is_a?(RExchange::Folder) folder.to_s.ensure_ends_with('/') + @href.split('/').last else @session.uri.path.ensure_ends_with('/') + folder.to_s.ensure_ends_with('/') + @href.split('/').last end DavMoveRequest.execute(@session, @href, destination) end |
#raw ⇒ Object
52 53 54 55 |
# File 'lib/rexchange/message_href.rb', line 52 def raw # memoization of the raw contents @raw ||= fetch(@href, limit = 10) end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/rexchange/message_href.rb', line 48 def to_s "Href: #{@href}" end |