rexchange 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
- -- 1.1
1
+ -- 0.1.2: Minor documentation/cleanup
2
+ * Removed a double-dash in the README that was apparently causing some viewing errors
3
+ * Changed Session initialize to a ternary condition
4
+ * Added RExchange::Message#has_attachments?
5
+ * Added documentation for most methods in RExchange::Message and RExchange::Folder
6
+
7
+ -- 0.1.1
2
8
  * Fleshed out the README
3
9
  * Copied the RAKEFILE from the Rools project
data/RAKEFILE CHANGED
@@ -7,7 +7,7 @@ require 'rake/gempackagetask'
7
7
  require 'rake/contrib/rubyforgepublisher'
8
8
  # require 'pscp'
9
9
 
10
- PACKAGE_VERSION = '0.1.1'
10
+ PACKAGE_VERSION = '0.1.2'
11
11
 
12
12
  PACKAGE_FILES = FileList[
13
13
  'README',
data/README CHANGED
@@ -1,4 +1,6 @@
1
- = RExchange -- A pure ruby wrapper for the Microsoft Exchange Server WebDAV API
1
+ = RExchange
2
+
3
+ RExchange is a pure ruby wrapper for the Microsoft Exchange Server WebDAV API
2
4
 
3
5
  == Things you should know
4
6
 
@@ -19,6 +19,8 @@ module RExchange
19
19
 
20
20
  alias :old_method_missing :method_missing
21
21
 
22
+ # Used to access subfolders. If the subfolder does not
23
+ # exist, then old_method_missing is called.
22
24
  def method_missing(sym, *args)
23
25
  if subfolder_exist?(sym.to_s)
24
26
  Folder.new(@credentials, self, sym )
@@ -27,25 +29,34 @@ module RExchange
27
29
  end
28
30
  end
29
31
 
32
+ # Iterate through each RExchange::Message in this folder
30
33
  def each
31
34
  messages.each do |msg|
32
35
  yield msg
33
36
  end
34
37
  end
35
38
 
39
+ # Retrieve an Array of messages from a specific folder
40
+ # === Example
41
+ # RExchange::open(uri, :user => 'bob', :password => 'random') do |mailbox|
42
+ # mailbox.messages_in('inbox/archive').each do |message|
43
+ # p message.from
44
+ # end
45
+ # end
36
46
  def messages_in(folder)
37
47
  folder.split('/').inject(@credentials.uri.path) do |final_path, current_path|
38
48
  Folder.new(@credentials, final_path, current_path)
39
49
  end.messages
40
50
  end
41
51
 
52
+ # Retrieve an Array of messages in this folder
42
53
  def messages
43
54
 
44
55
  body = <<DABODY
45
56
  <?xml version="1.0"?>
46
57
  <D:searchrequest xmlns:D = "DAV:">
47
58
  <D:sql>
48
- SELECT "DAV:href",
59
+ SELECT "DAV:href",
49
60
  "urn:schemas:httpmail:from", "urn:schemas:httpmail:to", "urn:schemas:mailheader:message-id",
50
61
  "urn:schemas:httpmail:subject", "DAV:href", "urn:schemas:httpmail:date",
51
62
  "urn:schemas:httpmail:importance", "urn:schemas:httpmail:hasattachment",
@@ -53,13 +64,13 @@ module RExchange
53
64
  FROM SCOPE('shallow traversal of "#{to_s}"')
54
65
  WHERE "DAV:ishidden" = false
55
66
  AND "DAV:isfolder" = false
56
- AND "DAV:contentclass" = 'urn:content-classes:message'
67
+ AND "DAV:contentclass" = 'urn:content-classes:message'
57
68
  </D:sql>
58
69
  </D:searchrequest>
59
70
  DABODY
60
71
 
61
- response = DavSearchRequest.execute(@credentials, :body => body)
62
-
72
+ response = DavSearchRequest.execute(@credentials, :body => body)
73
+
63
74
  mail_messages = []
64
75
  xpath_query = "//a:propstat[a:status/text() = 'HTTP/1.1 200 OK']/a:prop"
65
76
  Document.new(response.body).elements.each(xpath_query) do |m|
@@ -69,18 +80,22 @@ DABODY
69
80
  return mail_messages
70
81
  end
71
82
 
83
+ # Join the strings passed in with '/'s between them
72
84
  def self.join(*args)
73
85
  args.collect { |f| f.to_s.ensure_ends_with('/') }.to_s.squeeze('/')
74
86
  end
75
87
 
88
+ # Return an Array of subfolders for this folder
76
89
  def folders
77
90
  @folders ||= get_folders
78
91
  end
79
92
 
93
+ # Check to see if a particular subfolder exists
80
94
  def subfolder_exist?(folder)
81
95
  folders.include? normalize_folder_name(folder)
82
96
  end
83
97
 
98
+ # Return the absolute path to this folder (but not the full URI)
84
99
  def to_s
85
100
  Folder.join(@parent, @folder)
86
101
  end
@@ -116,4 +131,4 @@ DA_QUERY
116
131
  return folders
117
132
  end
118
133
  end
119
- end
134
+ end
@@ -9,17 +9,34 @@ module RExchange
9
9
 
10
10
  attr_accessor :attributes
11
11
 
12
+ # Used to access the attributes of the message as a hash.
12
13
  def [](key)
13
14
  return @attributes[key]
14
15
  end
15
16
 
17
+ # Used to access the attributes of the message. The following are available:
18
+ # * href
19
+ # * from
20
+ # * to
21
+ # * subject
22
+ # * message-id
23
+ # * date
24
+ # * importance
25
+ # * hasattachment
16
26
  def method_missing(sym, *args)
17
27
  return @attributes[sym.to_s] if @attributes.include?(sym.to_s)
18
28
  end
19
29
 
30
+ # This is an alias for httpmail:hasattachment attribute.
31
+ def has_attachments?
32
+ return self['hasattachment']
33
+ end
34
+
35
+ # Returns the body of the message. This is either a httpmail:textdescription,
36
+ # or a httpmail:htmldescription
20
37
  def body
21
38
  @attributes['textdescription'] || @attributes['htmldescription']
22
- end
39
+ end
23
40
 
24
41
  def initialize(session, dav_property_node)
25
42
  @attributes = {}
@@ -30,14 +47,20 @@ module RExchange
30
47
  end
31
48
 
32
49
  return self
33
- end
34
-
35
- def move_to(folder)
50
+ end
51
+
52
+ # Move this message to the specified folder.
53
+ # The folder can be a string such as 'inbox/archive' or a RExchange::Folder.
54
+ # === Example
55
+ # mailbox.inbox.each do |message|
56
+ # message.move_to mailbox.inbox.archive
57
+ # end
58
+ def move_to(folder)
36
59
  source = URI.parse(self.href).path
37
- destination = @session.uri.path.ensure_ends_with('/') + folder.ensure_ends_with('/') + source.split('/').last
38
-
39
- DavMoveRequest.execute(@session, source, destination)
60
+ destination = @session.uri.path.ensure_ends_with('/') + folder.to_s.ensure_ends_with('/') + source.split('/').last
61
+
62
+ DavMoveRequest.execute(@session, source, destination)
40
63
  end
41
64
 
42
- end
65
+ end
43
66
  end
@@ -22,13 +22,9 @@ module RExchange
22
22
  @parent = @credentials.uri.path
23
23
  @folder = ''
24
24
 
25
- if block_given?
26
- yield self
27
- else
28
- return self
29
- end
25
+ block_given? ? yield self : return self
30
26
  end
31
27
 
32
28
  end
33
29
 
34
- end
30
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: rexchange
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-01-27
6
+ version: 0.1.2
7
+ date: 2006-01-28
8
8
  summary: "A simple wrapper around Microsoft Exchange Server's WebDAV API"
9
9
  require_paths:
10
10
  - lib