viewpoint 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/TODO +2 -0
  2. data/VERSION +1 -1
  3. data/lib/model/generic_folder.rb +34 -1
  4. data/lib/model/item.rb +51 -3
  5. data/lib/model/message.rb +30 -7
  6. data/lib/soap/handsoap/builders/ews_build_helpers.rb +39 -14
  7. data/lib/soap/handsoap/ews_service.rb +66 -18
  8. data/lib/soap/handsoap/parsers/ews_parser.rb +38 -0
  9. data/lib/viewpoint.rb +18 -0
  10. data/test/spec/basic_functions.spec +18 -0
  11. data/test/spec/item_tests.spec +43 -0
  12. data/test/spec/spec.opts +7 -0
  13. metadata +5 -50
  14. data/examples/cal2ical.rb +0 -29
  15. data/examples/ews_fusefs.rb +0 -363
  16. data/examples/webclient/.gems +0 -2
  17. data/examples/webclient/README +0 -1
  18. data/examples/webclient/config.ru +0 -26
  19. data/examples/webclient/ews_access_handler.rb +0 -42
  20. data/examples/webclient/public/css/mail.css +0 -33
  21. data/examples/webclient/public/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  22. data/examples/webclient/public/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  23. data/examples/webclient/public/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  24. data/examples/webclient/public/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  25. data/examples/webclient/public/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  26. data/examples/webclient/public/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  27. data/examples/webclient/public/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  28. data/examples/webclient/public/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  29. data/examples/webclient/public/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  30. data/examples/webclient/public/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  31. data/examples/webclient/public/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  32. data/examples/webclient/public/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  33. data/examples/webclient/public/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  34. data/examples/webclient/public/css/smoothness/jquery-ui-1.7.2.custom.css +0 -406
  35. data/examples/webclient/public/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  36. data/examples/webclient/public/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  37. data/examples/webclient/public/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  38. data/examples/webclient/public/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  39. data/examples/webclient/public/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  40. data/examples/webclient/public/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  41. data/examples/webclient/public/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  42. data/examples/webclient/public/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  43. data/examples/webclient/public/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  44. data/examples/webclient/public/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  45. data/examples/webclient/public/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  46. data/examples/webclient/public/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  47. data/examples/webclient/public/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  48. data/examples/webclient/public/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  49. data/examples/webclient/public/css/ui-lightness/jquery-ui-1.7.2.custom.css +0 -406
  50. data/examples/webclient/public/js/jquery-1.3.2.min.js +0 -19
  51. data/examples/webclient/public/js/jquery-ui-1.7.2.custom.min.js +0 -145
  52. data/examples/webclient/viewpoint_web.rb +0 -295
  53. data/examples/webclient/views/_footer.haml +0 -1
  54. data/examples/webclient/views/_header.haml +0 -11
  55. data/examples/webclient/views/_tagline.haml +0 -1
  56. data/examples/webclient/views/index.haml +0 -20
  57. data/examples/webclient/views/layout.haml +0 -42
  58. data/examples/webclient/views/mail.haml +0 -45
  59. data/examples/webclient/views/welcome.haml +0 -0
  60. data/lib/model/task_list.rb +0 -19
data/lib/viewpoint.rb CHANGED
@@ -21,6 +21,7 @@
21
21
  # We only what one instance of this class so include Singleton
22
22
  require 'singleton'
23
23
  require 'date'
24
+ require 'base64'
24
25
 
25
26
  # Class Extensions
26
27
  require 'extensions/string'
@@ -72,20 +73,37 @@ module Viewpoint
72
73
 
73
74
  attr_reader :ews
74
75
 
76
+ # Set the endpoint for Exchange Web Services.
77
+ # @param [String] endpoint The URL of the endpoint. This should end in
78
+ # 'exchange.asmx' and is typically something like this:
79
+ # https://myexch/ews/exchange.asmx
80
+ # @param [Integer] version The SOAP version to use. This defaults to 1
81
+ # and you should not need to pass this parameter.
75
82
  def self.endpoint=(endpoint, version = 1)
76
83
  @@endpoint = endpoint
77
84
  SOAP::ExchangeWebService.endpoint(:uri => endpoint, :version => version)
78
85
  end
79
86
 
87
+ # Fetch the current endpoint
80
88
  def self.endpoint
81
89
  @@endpoint
82
90
  end
83
91
 
92
+ # Set the SOAP username and password.
93
+ # @param [String] user The user name
94
+ # @param [String] pass The password
84
95
  def self.set_auth(user,pass)
85
96
  @@user = user
86
97
  SOAP::ExchangeWebService.set_auth(user,pass)
87
98
  end
88
99
 
100
+ # Set the http driver that the SOAP back-end will use.
101
+ # @param [Symbol] driver The HTTP driver. Available drivers:
102
+ # :curb, :net_http, :http_client(Default)
103
+ def self.set_http_driver(driver)
104
+ Handsoap.http_driver = driver
105
+ end
106
+
89
107
  def initialize
90
108
  @ews = SOAP::ExchangeWebService.new
91
109
  end
@@ -22,6 +22,15 @@ describe "Test the basic features of Viewpoint" do
22
22
  (Viewpoint::EWS::GenericFolder.get_folder :tasks).should be_instance_of(Viewpoint::EWS::TasksFolder)
23
23
  end
24
24
 
25
+ it 'should retrive the Inbox by name' do
26
+ (Viewpoint::EWS::GenericFolder.get_folder_by_name 'Inbox').should be_instance_of(Viewpoint::EWS::Folder)
27
+ end
28
+
29
+ it 'should retrive the Inbox by FolderId' do
30
+ inbox = Viewpoint::EWS::GenericFolder.get_folder_by_name 'Inbox'
31
+ (Viewpoint::EWS::GenericFolder.get_folder inbox.id).should be_instance_of(Viewpoint::EWS::Folder)
32
+ end
33
+
25
34
  it 'should retrieve an Array of Folder Types' do
26
35
  flds = Viewpoint::EWS::GenericFolder.find_folders
27
36
  flds.should be_instance_of(Array)
@@ -48,4 +57,13 @@ describe "Test the basic features of Viewpoint" do
48
57
  end
49
58
  end
50
59
 
60
+ it 'should retrieve a folder by name' do
61
+ inbox = Viewpoint::EWS::GenericFolder.get_folder_by_name("Inbox")
62
+ inbox.should be_instance_of(Viewpoint::EWS::Folder)
63
+ end
64
+
65
+ it 'should retrieve a list of folder names' do
66
+ Viewpoint::EWS::GenericFolder.folder_names.should_not be_empty
67
+ end
68
+
51
69
  end
@@ -0,0 +1,43 @@
1
+ $: << File.dirname(__FILE__) + '/../../lib/'
2
+ require 'kconv'
3
+ require 'viewpoint'
4
+ require 'json'
5
+
6
+ # To run this test put a file called 'creds.json' in this directory with the following format:
7
+ # {"user":"myuser","pass":"mypass","endpoint":"https://mydomain.com/ews/exchange.asmx"}
8
+
9
+
10
+ describe "Test the basic functionality of Items" do
11
+ before(:all) do
12
+ creds = JSON.load(File.open('spec/creds.json','r'))
13
+ Viewpoint::EWS::EWS.endpoint = creds['endpoint']
14
+ Viewpoint::EWS::EWS.set_auth(creds['user'],creds['pass'])
15
+ @ews = Viewpoint::EWS::EWS.instance
16
+ end
17
+
18
+ it 'should create a new Message Item that we can test with.' do
19
+ $message = Viewpoint::EWS::Message.send('RSPEC test subject', 'RSPEC test body', [@ews.me.email_address],nil,nil,nil,true)
20
+ $message.should be_instance_of(Viewpoint::EWS::Message)
21
+ end
22
+
23
+ it 'should move the Message Item to the Inbox folder' do
24
+ inbox = Viewpoint::EWS::GenericFolder.get_folder :inbox
25
+ $message.move!(inbox).should be_true
26
+ end
27
+ it 'should copy the Message Item to the Drafts folder' do
28
+ drafts = Viewpoint::EWS::GenericFolder.get_folder :drafts
29
+ $msg_copy = $message.copy(drafts)
30
+ $msg_copy.should be_instance_of(Viewpoint::EWS::Message)
31
+ end
32
+
33
+ describe "Clean up after ourselves." do
34
+ it 'should delete the initial Message' do
35
+ $message.delete!.should be_true
36
+ end
37
+
38
+ it 'should send the copy message to Deleted Items' do
39
+ $msg_copy.recycle!.should be_true
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,7 @@
1
+ spec/basic_functions.spec
2
+ spec/item_tests.spec
3
+ spec/folder_subscriptions.spec
4
+ spec/folder_synchronization.spec
5
+ --format
6
+ nested
7
+ --color
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Wanek
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-02 00:00:00 -05:00
17
+ date: 2010-08-04 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -97,52 +97,6 @@ files:
97
97
  - Rakefile
98
98
  - TODO
99
99
  - VERSION
100
- - examples/cal2ical.rb
101
- - examples/ews_fusefs.rb
102
- - examples/webclient/.gems
103
- - examples/webclient/README
104
- - examples/webclient/config.ru
105
- - examples/webclient/ews_access_handler.rb
106
- - examples/webclient/public/css/mail.css
107
- - examples/webclient/public/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
108
- - examples/webclient/public/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
109
- - examples/webclient/public/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
110
- - examples/webclient/public/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
111
- - examples/webclient/public/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png
112
- - examples/webclient/public/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
113
- - examples/webclient/public/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
114
- - examples/webclient/public/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
115
- - examples/webclient/public/css/smoothness/images/ui-icons_222222_256x240.png
116
- - examples/webclient/public/css/smoothness/images/ui-icons_2e83ff_256x240.png
117
- - examples/webclient/public/css/smoothness/images/ui-icons_454545_256x240.png
118
- - examples/webclient/public/css/smoothness/images/ui-icons_888888_256x240.png
119
- - examples/webclient/public/css/smoothness/images/ui-icons_cd0a0a_256x240.png
120
- - examples/webclient/public/css/smoothness/jquery-ui-1.7.2.custom.css
121
- - examples/webclient/public/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png
122
- - examples/webclient/public/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png
123
- - examples/webclient/public/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png
124
- - examples/webclient/public/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png
125
- - examples/webclient/public/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png
126
- - examples/webclient/public/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png
127
- - examples/webclient/public/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png
128
- - examples/webclient/public/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png
129
- - examples/webclient/public/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png
130
- - examples/webclient/public/css/ui-lightness/images/ui-icons_222222_256x240.png
131
- - examples/webclient/public/css/ui-lightness/images/ui-icons_228ef1_256x240.png
132
- - examples/webclient/public/css/ui-lightness/images/ui-icons_ef8c08_256x240.png
133
- - examples/webclient/public/css/ui-lightness/images/ui-icons_ffd27a_256x240.png
134
- - examples/webclient/public/css/ui-lightness/images/ui-icons_ffffff_256x240.png
135
- - examples/webclient/public/css/ui-lightness/jquery-ui-1.7.2.custom.css
136
- - examples/webclient/public/js/jquery-1.3.2.min.js
137
- - examples/webclient/public/js/jquery-ui-1.7.2.custom.min.js
138
- - examples/webclient/viewpoint_web.rb
139
- - examples/webclient/views/_footer.haml
140
- - examples/webclient/views/_header.haml
141
- - examples/webclient/views/_tagline.haml
142
- - examples/webclient/views/index.haml
143
- - examples/webclient/views/layout.haml
144
- - examples/webclient/views/mail.haml
145
- - examples/webclient/views/welcome.haml
146
100
  - lib/exceptions/exceptions.rb
147
101
  - lib/extensions/string.rb
148
102
  - lib/model/calendar_folder.rb
@@ -163,7 +117,6 @@ files:
163
117
  - lib/model/model.rb
164
118
  - lib/model/search_folder.rb
165
119
  - lib/model/task.rb
166
- - lib/model/task_list.rb
167
120
  - lib/model/tasks_folder.rb
168
121
  - lib/soap/handsoap/builder.rb
169
122
  - lib/soap/handsoap/builders/ews_build_helpers.rb
@@ -177,6 +130,8 @@ files:
177
130
  - test/spec/basic_functions.spec
178
131
  - test/spec/folder_subscriptions.spec
179
132
  - test/spec/folder_synchronization.spec
133
+ - test/spec/item_tests.spec
134
+ - test/spec/spec.opts
180
135
  - utils/ewsWSDL2rb.rb
181
136
  has_rdoc: true
182
137
  homepage: http://github.com/zenchild/Viewpoint
data/examples/cal2ical.rb DELETED
@@ -1,29 +0,0 @@
1
- #############################################################################
2
- # Copyright © 2009 Dan Wanek <dan.wanek@gmail.com>
3
- #
4
- #
5
- # This file is part of Viewpoint.
6
- #
7
- # Viewpoint is free software: you can redistribute it and/or
8
- # modify it under the terms of the GNU General Public License as published
9
- # by the Free Software Foundation, either version 3 of the License, or (at
10
- # your option) any later version.
11
- #
12
- # Viewpoint is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
- # Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License along
18
- # with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
19
- #############################################################################
20
- require File.dirname(__FILE__) + '/../lib/exchwebserv'
21
- include Viewpoint
22
-
23
- vp = ExchWebServ.instance
24
- vp.authenticate
25
- vp.find_folders
26
- cal = vp.get_folder("Calendar")
27
- ical = cal.to_ical
28
- puts ical.to_ical
29
-
@@ -1,363 +0,0 @@
1
- #############################################################################
2
- # Copyright © 2009 Dan Wanek <dan.wanek@gmail.com>
3
- #
4
- #
5
- # This file is part of Viewpoint.
6
- #
7
- # Viewpoint is free software: you can redistribute it and/or
8
- # modify it under the terms of the GNU General Public License as published
9
- # by the Free Software Foundation, either version 3 of the License, or (at
10
- # your option) any later version.
11
- #
12
- # Viewpoint is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
- # Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License along
18
- # with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
19
- #############################################################################
20
- $: << File.dirname(__FILE__) + '/../lib/'
21
- require 'fusefs'
22
- require 'time'
23
- include FuseFS
24
- require 'viewpoint'
25
- include Viewpoint
26
-
27
-
28
- class EWSFuse < FuseDir
29
-
30
- @@maildir_dirs = ['cur','new', 'tmp']
31
- @@ewsfuse_dir = "#{ENV['HOME']}/.ewsfuse"
32
-
33
- def initialize(mountpoint)
34
- @vp = ExchWebServ.instance
35
- @vp.authenticate
36
- @vp.find_folders
37
- @mf = (@vp.get_mail_folders)
38
- @messages = {} # Message objects
39
- @open_files = {} # Files open for RAW IO
40
- @mountpoint = mountpoint
41
-
42
- #File::umask(0077)
43
- if( !File.directory?(@@ewsfuse_dir) )
44
- Dir.mkdir(@@ewsfuse_dir)
45
- end
46
- end
47
-
48
- # ----- FuserFS Methods ----- #
49
- def contents(path)
50
- puts "--- IN: contents ---"
51
- if (local_path?(path))
52
- puts "--- IN: contents: if ---"
53
- Dir.entries(local_path(path))
54
- else
55
- puts "--- IN: contents: else ---"
56
- parts = scan_path(path)
57
- case parts.pop
58
- when nil
59
- puts "--- IN: contents: else --- while 'nil'"
60
- output = @mf.keys do |folder_name|
61
- folder_name
62
- end
63
- output + Dir.entries(local_path(path))
64
- when 'cur'
65
- np = parts.pop
66
- puts "folder: #{np}"
67
- mdir = @mf[np]
68
- if( mdir == nil )
69
- []
70
- else
71
- mdir = @vp.get_folder(mdir.display_name)
72
- puts "Fetching todays messages for #{mdir.display_name} of type #{mdir.class.to_s}"
73
- mdir.get_todays_messages.map do |msg|
74
- puts "Got message of type: #{msg.class.to_s}"
75
- msg_hash = msg.item_id.hash.abs
76
- @messages[msg_hash.to_s] = msg
77
- "#{msg.date_time_recieved.strftime('%s')}_#{msg_hash}"
78
- end
79
- end
80
- when 'new','tmp'
81
- []
82
- else
83
- ['cur','new','tmp']
84
- end
85
- end
86
- end
87
-
88
- def directory?(path)
89
- if( local_path?(path) )
90
- puts "Checking for Local_dir?"
91
- File.directory?( local_path(path) )
92
- else
93
- parts = scan_path(path)
94
- part = parts.pop
95
- case part
96
- when /^[0-9]{10,}_/
97
- puts "NOT DIR: #{path}"
98
- return false
99
- when nil, 'cur','new','tmp'
100
- puts "IS DIR: #{path}"
101
- return true
102
- else
103
- if( (@mf[part] ) != nil )
104
- puts "IS DIR: #{path}"
105
- return true
106
- else
107
- puts "NOT DIR: #{path}"
108
- return false
109
- end
110
- end
111
- end
112
- end
113
-
114
- def file?(path)
115
- if( local_path?(path) )
116
- if(File.exists?(local_path(path)))
117
- ans = !directory?(path)
118
- else
119
- ans = false
120
- end
121
- else
122
- ans = !directory?(path)
123
- end
124
- puts "=> file?(#{path}) ... " + (ans ? "yes" : "no")
125
- return ans
126
- end
127
-
128
- def executable?(path)
129
- if( local_path?(path) )
130
- return File.executable?(local_path(path))
131
- else
132
- return directory?(path)
133
- end
134
- end
135
-
136
- def read_file(path)
137
- if( local_path?(path) )
138
- IO.read(local_path(path))
139
- else
140
- parts = scan_path(path)
141
- msg_hash = parts.last.split('_').last
142
- @messages[msg_hash.to_s].to_rfc822
143
- end
144
- end
145
-
146
- def can_write?(path)
147
- return false if path =~ /folders.db/
148
- parts = scan_path(path)
149
-
150
- ans = local_path?(path) || path == '/' #||
151
- #parts.last =~ /^[0-9]{10,}_/
152
-
153
- puts "=> can_write?(#{path}) ... " + (ans ? "yes" : "no")
154
- return ans
155
- end
156
-
157
- def write_to(path, str)
158
- puts "=> write_to(#{path}, str...)"
159
- io = File.open(local_path(path),'w+')
160
- io.write(str)
161
- io.close
162
- end
163
-
164
- def can_delete?(path)
165
- parts = scan_path(path)
166
-
167
- ans = local_path?(path) ||
168
- parts.last =~ /^[0-9]{10,}_/
169
-
170
- puts "=> can_delete?(#{path}) ... " + (ans ? "yes" : "no")
171
- ans
172
- end
173
-
174
- def delete(path)
175
- puts "=> delete(#{path})"
176
- if( local_path?(path) )
177
- puts "In LOCAL DELETE"
178
- lpath = local_path(path)
179
- if( File.directory?(lpath) )
180
- puts "Removing local directory #{lpath}"
181
- else
182
- puts "Removing local file #{lpath}"
183
- File.unlink(lpath)
184
- end
185
- else
186
- puts "In NON LOCAL DELETE"
187
- parts = scan_path(path)
188
- msg_hash = parts.last.split('_').last
189
- puts "In NON LOCAL DELETE 2: #{msg_hash}"
190
- puts "In NON LOCAL DELETE 3: #{parts[-3]}"
191
- #mdir = @vp.get_folder(parts[-3])
192
- if ( (msg = @messages[msg_hash.to_s]) == nil)
193
- npath = parts
194
- npath.pop
195
- contents(npath.join('/'))
196
- msg = @messages[msg_hash.to_s]
197
- end
198
- puts "In NON LOCAL DELETE 4: #{msg.class.to_s}"
199
- puts "MESG: #{msg.class.to_s}, ID: #{msg.item_id}, PARENT: #{msg.parent_folder.class.to_s}"
200
- #puts "MESG: #{mdir.class.to_s}"
201
- msg.parent_folder.recycle_item(msg.item_id)
202
- true
203
- end
204
- end
205
-
206
- def can_mkdir?(path)
207
- ans = local_path?(path)
208
- puts "=> can_mkdir?(#{path}) ... " + (ans ? "yes" : "no")
209
- ans
210
- end
211
-
212
- def mkdir(path)
213
- puts "=> mkdir(#{path})"
214
- lpath = local_path(path)
215
- Dir.mkdir lpath
216
- end
217
-
218
- def can_rmdir?(path)
219
- puts "=> can_rmdir?(#{path})"
220
- local_path?(path)
221
- end
222
-
223
- def rmdir(path)
224
- lpath = local_path(path)
225
- puts "=> rmdir(#{lpath})"
226
- Dir.rmdir(lpath)
227
- end
228
-
229
- def size(path)
230
- if(local_path?(path))
231
- File.size(local_path(path))
232
- end
233
- end
234
-
235
- # --- RAW FuserFS Methods --- #
236
- def raw_open(path,mode) # mode is "r" "w" or "rw", with "a" if the file
237
- puts "** => raw_open(#{path}, '#{mode}')"
238
-
239
- if( !local_path?(path) )
240
- return false
241
- end
242
-
243
- lpath = local_path(path)
244
-
245
- case mode
246
- when /^r$/
247
- mode = 'r'
248
- when /^w$/
249
- mode = 'a'
250
- when /^[wr]{2}$/, /a/
251
- if(File.exists?(lpath))
252
- mode = 'r+'
253
- else
254
- mode = 'w+'
255
- end
256
- else
257
- raise "Unknown mode error #{mode}"
258
- end
259
-
260
- puts "Setting mode to '#{mode}'"
261
-
262
- return true if @open_files.has_key?(path)
263
- begin
264
- puts "Raw opening.... File.open(#{lpath}, #{mode})"
265
- @open_files[path] = File.open(lpath, mode)
266
- return true
267
- rescue => error
268
- puts "Error opening raw file: #{error}"
269
- return false
270
- end
271
- end
272
-
273
- def raw_read(path,offset,size)
274
- begin
275
- puts "** => raw_read(#{path}, #{offset}, #{size})"
276
- file = @open_files[path]
277
- return unless file
278
- #file.sysseek(offset,IO::SEEK_SET)
279
- #file.sysread(size)
280
- file.seek(offset, File::SEEK_SET)
281
- file.read(size)
282
- rescue => error
283
- puts "Error reading raw file: #{error}"
284
- nil
285
- end
286
- end
287
-
288
- def raw_write(path,offset,size,buf)
289
- begin
290
- puts "** => raw_write(#{path}, #{offset}, #{size}, ... buf)"
291
- file = @open_files[path]
292
- return unless file
293
- file.seek(offset, File::SEEK_CUR)
294
- file.write(buf[0, size])
295
- #file.sysseek(offset,IO::SEEK_CUR)
296
- #file.syswrite(buf[0, size])
297
- rescue => error
298
- puts "Error writing to raw file: #{error}"
299
- end
300
- end
301
-
302
- def raw_close(path)
303
- begin
304
- puts "** => raw_close(#{path})"
305
- file = @open_files[path]
306
- return unless file
307
- file.close
308
- @open_files.delete path
309
- rescue => error
310
- puts "Error closing raw file: #{error}"
311
- end
312
- end
313
-
314
-
315
- # --- End FuserFS Methods --- #
316
-
317
- # Is this a virtual dir/file or a local file
318
- def local_path?(path)
319
- parts = scan_path(path)
320
-
321
- if parts.empty?
322
- ans = false
323
- else
324
- ans = ((!@@maildir_dirs.include? parts.last) &&
325
- parts.last !~ /^[0-9]{10,}_/ &&
326
- ((@mf[parts.last]) == nil)
327
- )
328
- end
329
-
330
- puts "==> local_path?(#{path}) ... " + (ans ? "yes" : "no")
331
- return ans
332
- end
333
-
334
- # Return local path as a string
335
- def local_path(path)
336
- puts "==> local_path(#{path})"
337
- #lpath = path.gsub(/#{@mountpoint}\/?/,'')
338
- lpath = path.gsub(/^\/?/,'')
339
- return "#{@@ewsfuse_dir}/#{lpath}"
340
- end
341
- end
342
-
343
- # FuserFS set-up
344
- if (File.basename($0) == File.basename(__FILE__))
345
- if (ARGV.size != 1)
346
- puts "Usage: #{$0} <directory>"
347
- exit
348
- end
349
-
350
- dirname = ARGV.shift
351
-
352
- unless File.directory?(dirname)
353
- puts "Usage: #{dirname} is not a directory."
354
- exit
355
- end
356
-
357
- root = EWSFuse.new(dirname)
358
-
359
- # Set the root FuseFS
360
- FuseFS.set_root(root)
361
- FuseFS.mount_under(dirname)
362
- FuseFS.run # This doesn't return until we're unmounted.
363
- end