viewpoint 1.1.1 → 2.0.0
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.
- checksums.yaml +4 -4
- data/README.md +13 -8
- data/lib/ews/calendar_accessors.rb +37 -33
- data/lib/ews/connection.rb +151 -124
- data/lib/ews/connection_helper.rb +36 -33
- data/lib/ews/convert_accessors.rb +58 -54
- data/lib/ews/errors.rb +59 -53
- data/lib/ews/ews_client.rb +92 -79
- data/lib/ews/exceptions/exceptions.rb +61 -61
- data/lib/ews/folder_accessors.rb +235 -234
- data/lib/ews/impersonation.rb +29 -23
- data/lib/ews/item_accessors.rb +215 -213
- data/lib/ews/mailbox_accessors.rb +82 -79
- data/lib/ews/meeting_accessors.rb +38 -31
- data/lib/ews/message_accessors.rb +83 -81
- data/lib/ews/push_subscription_accessors.rb +29 -27
- data/lib/ews/room_accessors.rb +48 -46
- data/lib/ews/roomlist_accessors.rb +47 -45
- data/lib/ews/soap/builders/ews_builder.rb +1186 -1188
- data/lib/ews/soap/ews_response.rb +68 -73
- data/lib/ews/soap/ews_soap_availability_response.rb +57 -57
- data/lib/ews/soap/ews_soap_free_busy_response.rb +115 -117
- data/lib/ews/soap/ews_soap_response.rb +99 -101
- data/lib/ews/soap/ews_soap_room_response.rb +45 -45
- data/lib/ews/soap/ews_soap_roomlist_response.rb +45 -46
- data/lib/ews/soap/exchange_availability.rb +54 -52
- data/lib/ews/soap/exchange_data_services.rb +693 -711
- data/lib/ews/soap/exchange_notification.rb +123 -128
- data/lib/ews/soap/exchange_synchronization.rb +82 -82
- data/lib/ews/soap/exchange_time_zones.rb +41 -44
- data/lib/ews/soap/exchange_user_configuration.rb +30 -27
- data/lib/ews/soap/exchange_web_service.rb +237 -233
- data/lib/ews/soap/parsers/ews_parser.rb +46 -42
- data/lib/ews/soap/parsers/ews_sax_document.rb +63 -58
- data/lib/ews/soap/response_message.rb +69 -68
- data/lib/ews/soap/responses/create_attachment_response_message.rb +45 -45
- data/lib/ews/soap/responses/create_item_response_message.rb +26 -25
- data/lib/ews/soap/responses/find_item_response_message.rb +76 -78
- data/lib/ews/soap/responses/get_events_response_message.rb +52 -51
- data/lib/ews/soap/responses/send_notification_response_message.rb +53 -51
- data/lib/ews/soap/responses/subscribe_response_message.rb +37 -34
- data/lib/ews/soap/responses/sync_folder_hierarchy_response_message.rb +38 -35
- data/lib/ews/soap/responses/sync_folder_items_response_message.rb +38 -35
- data/lib/ews/soap.rb +27 -26
- data/lib/ews/templates/calendar_item.rb +64 -60
- data/lib/ews/templates/forward_item.rb +19 -17
- data/lib/ews/templates/message.rb +61 -67
- data/lib/ews/templates/reply_to_item.rb +20 -18
- data/lib/ews/templates/task.rb +55 -55
- data/lib/ews/types/attachment.rb +75 -74
- data/lib/ews/types/attendee.rb +27 -25
- data/lib/ews/types/calendar_folder.rb +60 -44
- data/lib/ews/types/calendar_item.rb +134 -116
- data/lib/ews/types/contact.rb +11 -5
- data/lib/ews/types/contacts_folder.rb +10 -5
- data/lib/ews/types/copied_event.rb +47 -48
- data/lib/ews/types/created_event.rb +22 -20
- data/lib/ews/types/deleted_event.rb +22 -20
- data/lib/ews/types/distribution_list.rb +11 -5
- data/lib/ews/types/event.rb +60 -59
- data/lib/ews/types/export_items_response_message.rb +54 -50
- data/lib/ews/types/file_attachment.rb +63 -61
- data/lib/ews/types/folder.rb +58 -57
- data/lib/ews/types/free_busy_changed_event.rb +22 -20
- data/lib/ews/types/generic_folder.rb +348 -372
- data/lib/ews/types/item.rb +401 -397
- data/lib/ews/types/item_attachment.rb +87 -80
- data/lib/ews/types/item_field_uri_map.rb +201 -200
- data/lib/ews/types/mailbox_user.rb +146 -154
- data/lib/ews/types/meeting_cancellation.rb +11 -5
- data/lib/ews/types/meeting_message.rb +11 -5
- data/lib/ews/types/meeting_request.rb +11 -5
- data/lib/ews/types/meeting_response.rb +11 -5
- data/lib/ews/types/message.rb +11 -5
- data/lib/ews/types/modified_event.rb +43 -45
- data/lib/ews/types/moved_event.rb +47 -48
- data/lib/ews/types/new_mail_event.rb +22 -20
- data/lib/ews/types/out_of_office.rb +145 -144
- data/lib/ews/types/post_item.rb +11 -5
- data/lib/ews/types/search_folder.rb +10 -5
- data/lib/ews/types/status_event.rb +37 -36
- data/lib/ews/types/task.rb +39 -33
- data/lib/ews/types/tasks_folder.rb +32 -22
- data/lib/ews/types.rb +134 -139
- data/lib/viewpoint/logging/config.rb +19 -19
- data/lib/viewpoint/logging.rb +23 -17
- data/lib/viewpoint/string_utils.rb +31 -32
- data/lib/viewpoint.rb +18 -18
- metadata +82 -11
- data/Changelog.txt +0 -1004
data/lib/ews/folder_accessors.rb
CHANGED
|
@@ -1,264 +1,265 @@
|
|
|
1
|
-
|
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
# This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
4
|
+
#
|
|
5
|
+
# Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
module Viewpoint
|
|
19
|
+
module EWS
|
|
20
|
+
# Folder operations mixed into the EWS client.
|
|
21
|
+
module FolderAccessors
|
|
22
|
+
include Viewpoint::EWS
|
|
5
23
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
24
|
+
FOLDER_TYPE_MAP = {
|
|
25
|
+
mail: 'IPF.Note',
|
|
26
|
+
calendar: 'IPF.Appointment',
|
|
27
|
+
task: 'IPF.Task'
|
|
28
|
+
}.freeze
|
|
9
29
|
|
|
10
|
-
|
|
30
|
+
# Find subfolders of the passed root folder. If no parameters are passed this
|
|
31
|
+
# method will search from the Root folder.
|
|
32
|
+
# @param [Hash] opts Misc options to control request
|
|
33
|
+
# @option opts [String,Symbol] :root Either a FolderId(String) or a
|
|
34
|
+
# DistinguishedFolderId(Symbol) . This is where to start the search from.
|
|
35
|
+
# Usually :root,:msgfolderroot, or :publicfoldersroot
|
|
36
|
+
# @option opts [Symbol] :traversal :shallow/:deep/:soft_deleted
|
|
37
|
+
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
38
|
+
# @option opts [optional, String] :folder_type an optional folder type to
|
|
39
|
+
# limit the search to like 'IPF.Task'
|
|
40
|
+
# @return [Array] Returns an Array of Folder or subclasses of Folder
|
|
41
|
+
# @raise [EwsError] raised when the backend SOAP method returns an error.
|
|
42
|
+
def folders(opts = {})
|
|
43
|
+
opts = opts.clone
|
|
44
|
+
args = find_folders_args(opts)
|
|
45
|
+
obj = OpenStruct.new(opts: args, restriction: {})
|
|
46
|
+
yield obj if block_given?
|
|
47
|
+
merge_restrictions! obj
|
|
48
|
+
resp = ews.find_folder(args)
|
|
49
|
+
find_folders_parser(resp)
|
|
50
|
+
end
|
|
51
|
+
alias find_folders folders
|
|
11
52
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
53
|
+
# Get a specific folder by id or symbol
|
|
54
|
+
# @param [String,Symbol,Hash] folder_id Either a FolderId(String) or a
|
|
55
|
+
# DistinguishedFolderId(Symbol). You can also pass a Hash in the form:
|
|
56
|
+
# {id: <fold_id>, change_key: <change_key>}
|
|
57
|
+
# @param [Hash] opts Misc options to control request
|
|
58
|
+
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
59
|
+
# @option opts [String,nil] :act_as User to act on behalf as. This user must
|
|
60
|
+
# have been given delegate access to the folder or this operation will fail.
|
|
61
|
+
# @raise [EwsError] raised when the backend SOAP method returns an error.
|
|
62
|
+
def get_folder(folder_id, opts = {})
|
|
63
|
+
opts = opts.clone
|
|
64
|
+
args = get_folder_args(folder_id, opts)
|
|
65
|
+
resp = ews.get_folder(args)
|
|
66
|
+
get_folder_parser(resp)
|
|
67
|
+
end
|
|
20
68
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
69
|
+
# Get a specific folder by its name
|
|
70
|
+
# @param [String] name The folder name
|
|
71
|
+
# @param [Hash] opts Misc options to control request
|
|
72
|
+
# @option opts [String,Symbol] :parent Either a FolderId(String) or a
|
|
73
|
+
# DistinguishedFolderId(Symbol) . This is the parent folder.
|
|
74
|
+
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
75
|
+
# @option opts [String,nil] :act_as User to act on behalf as. This user must
|
|
76
|
+
# have been given delegate access to the folder or this operation will fail.
|
|
77
|
+
# @raise [EwsError] raised when the backend SOAP method returns an error.
|
|
78
|
+
def get_folder_by_name(name, opts = {})
|
|
79
|
+
opts = opts.clone
|
|
80
|
+
opts[:root] = opts.delete(:parent)
|
|
81
|
+
folders(opts) { |obj|
|
|
82
|
+
obj.restriction = {
|
|
83
|
+
is_equal_to: [
|
|
84
|
+
{ field_uRI: { field_uRI: 'folder:DisplayName' } },
|
|
85
|
+
{ field_uRI_or_constant: { constant: { value: name } } }
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}.first
|
|
89
|
+
end
|
|
26
90
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
args = find_folders_args(opts)
|
|
42
|
-
obj = OpenStruct.new(opts: args, restriction: {})
|
|
43
|
-
yield obj if block_given?
|
|
44
|
-
merge_restrictions! obj
|
|
45
|
-
resp = ews.find_folder( args )
|
|
46
|
-
find_folders_parser(resp)
|
|
47
|
-
end
|
|
48
|
-
alias :find_folders :folders
|
|
91
|
+
# @param [String] name The name of the new folder
|
|
92
|
+
# @param [Hash] opts
|
|
93
|
+
# @option opts [String,Symbol] :parent Either a FolderId(String) or a
|
|
94
|
+
# DistinguishedFolderId(Symbol) . This is the parent folder.
|
|
95
|
+
# @option opts [Symbol] :type the type of folder to create. must be one of
|
|
96
|
+
# :folder, :calendar, :contacts, :search, or :tasks
|
|
97
|
+
# @see http://msdn.microsoft.com/en-us/library/aa580808.aspx
|
|
98
|
+
def make_folder(name, opts = {})
|
|
99
|
+
parent = opts[:parent] || :msgfolderroot
|
|
100
|
+
resp = ews.create_folder parent_folder_id: { id: parent },
|
|
101
|
+
folders: [{ folder_type(opts[:type]) => { display_name: name } }]
|
|
102
|
+
create_folder_parser(resp).first
|
|
103
|
+
end
|
|
104
|
+
alias mkfolder make_folder
|
|
49
105
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
106
|
+
# Get a specific folder by id or symbol
|
|
107
|
+
# @param [Hash] opts Misc options to control request
|
|
108
|
+
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
109
|
+
# @option opts [String,Symbol,Hash] :folder_id You can optionally specify a
|
|
110
|
+
# folder_id to limit the hierarchy synchronization to it. It must be a
|
|
111
|
+
# FolderId(String), a DistinguishedFolderId(Symbol) or you can pass a Hash
|
|
112
|
+
# in the form: {id: <fold_id>, change_key: <change_key>}
|
|
113
|
+
# @option opts [String] :sync_state an optional Base64 encoded SyncState
|
|
114
|
+
# String from a previous sync call.
|
|
115
|
+
# @yield [Hash] yields the formatted argument Hash for last-minute
|
|
116
|
+
# modification before calling the backend EWS method.
|
|
117
|
+
# @return [Hash] A hash with the following keys
|
|
118
|
+
# :all_synced, whether or not additional calls are needed to get all folders
|
|
119
|
+
# :sync_state, the sync state to use for the next call
|
|
120
|
+
# and the following optional keys depending on the changes
|
|
121
|
+
# :create, :update, :delete
|
|
122
|
+
# @raise [EwsError] raised when the backend SOAP method returns an error.
|
|
123
|
+
def sync_folders(opts = {})
|
|
124
|
+
opts = opts.clone
|
|
125
|
+
args = sync_folders_args(opts)
|
|
126
|
+
yield args if block_given?
|
|
127
|
+
resp = ews.sync_folder_hierarchy(args)
|
|
128
|
+
sync_folders_parser(resp)
|
|
129
|
+
end
|
|
65
130
|
|
|
66
|
-
|
|
67
|
-
# @param [String] name The folder name
|
|
68
|
-
# @param [Hash] opts Misc options to control request
|
|
69
|
-
# @option opts [String,Symbol] :parent Either a FolderId(String) or a
|
|
70
|
-
# DistinguishedFolderId(Symbol) . This is the parent folder.
|
|
71
|
-
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
72
|
-
# @option opts [String,nil] :act_as User to act on behalf as. This user must
|
|
73
|
-
# have been given delegate access to the folder or this operation will fail.
|
|
74
|
-
# @raise [EwsError] raised when the backend SOAP method returns an error.
|
|
75
|
-
def get_folder_by_name(name, opts={})
|
|
76
|
-
opts = opts.clone
|
|
77
|
-
opts[:root] = opts.delete(:parent)
|
|
78
|
-
folders(opts) do |obj|
|
|
79
|
-
obj.restriction = {
|
|
80
|
-
:is_equal_to =>
|
|
81
|
-
[
|
|
82
|
-
{:field_uRI => {:field_uRI=>'folder:DisplayName'}},
|
|
83
|
-
{:field_uRI_or_constant => {:constant => {:value=>name}}}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
end.first
|
|
87
|
-
end
|
|
131
|
+
private
|
|
88
132
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
133
|
+
# Build up the arguements for #find_folders
|
|
134
|
+
def find_folders_args(opts)
|
|
135
|
+
opts[:root] = opts[:root] || :msgfolderroot
|
|
136
|
+
opts[:traversal] = opts[:traversal] || :shallow
|
|
137
|
+
opts[:shape] = opts[:shape] || :default
|
|
138
|
+
folder_id = { id: opts[:root] }
|
|
139
|
+
folder_id[:act_as] = opts[:act_as] if opts[:act_as]
|
|
140
|
+
if opts[:folder_type]
|
|
141
|
+
restr = { is_equal_to: [
|
|
142
|
+
{ field_uRI: { field_uRI: 'folder:FolderClass' } },
|
|
143
|
+
{ field_uRI_or_constant: { constant: { value: map_folder_type(opts[:folder_type]) } } }
|
|
144
|
+
] }
|
|
145
|
+
end
|
|
146
|
+
args = {
|
|
147
|
+
parent_folder_ids: [folder_id],
|
|
148
|
+
traversal: opts[:traversal],
|
|
149
|
+
folder_shape: { base_shape: opts[:shape] }
|
|
150
|
+
}
|
|
151
|
+
args[:restriction] = restr if restr
|
|
152
|
+
args
|
|
153
|
+
end
|
|
103
154
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# in the form: {id: <fold_id>, change_key: <change_key>}
|
|
111
|
-
# @option opts [String] :sync_state an optional Base64 encoded SyncState
|
|
112
|
-
# String from a previous sync call.
|
|
113
|
-
# @yield [Hash] yields the formatted argument Hash for last-minute
|
|
114
|
-
# modification before calling the backend EWS method.
|
|
115
|
-
# @return [Hash] A hash with the following keys
|
|
116
|
-
# :all_synced, whether or not additional calls are needed to get all folders
|
|
117
|
-
# :sync_state, the sync state to use for the next call
|
|
118
|
-
# and the following optional keys depending on the changes
|
|
119
|
-
# :create, :update, :delete
|
|
120
|
-
# @raise [EwsError] raised when the backend SOAP method returns an error.
|
|
121
|
-
def sync_folders(opts = {})
|
|
122
|
-
opts = opts.clone
|
|
123
|
-
args = sync_folders_args(opts)
|
|
124
|
-
yield args if block_given?
|
|
125
|
-
resp = ews.sync_folder_hierarchy( args )
|
|
126
|
-
sync_folders_parser(resp)
|
|
127
|
-
end
|
|
155
|
+
# @param [Viewpoint::EWS::SOAP::EwsSoapResponse] resp
|
|
156
|
+
def find_folders_parser(resp)
|
|
157
|
+
unless resp.status == 'Success'
|
|
158
|
+
raise EwsFolderNotFound,
|
|
159
|
+
"Could not retrieve folders. #{resp.code}: #{resp.message}"
|
|
160
|
+
end
|
|
128
161
|
|
|
162
|
+
folders = resp.response_message[:elems][:root_folder][:elems][0][:folders][:elems]
|
|
163
|
+
return [] if folders.nil?
|
|
129
164
|
|
|
130
|
-
|
|
165
|
+
folders.collect do |f|
|
|
166
|
+
ftype = f.keys.first
|
|
167
|
+
class_by_name(ftype).new(ews, f[ftype])
|
|
168
|
+
end
|
|
169
|
+
end
|
|
131
170
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
opts[:root] = opts[:root] || :msgfolderroot
|
|
135
|
-
opts[:traversal] = opts[:traversal] || :shallow
|
|
136
|
-
opts[:shape] = opts[:shape] || :default
|
|
137
|
-
folder_id = {:id => opts[:root]}
|
|
138
|
-
folder_id[:act_as] = opts[:act_as] if opts[:act_as]
|
|
139
|
-
if( opts[:folder_type] )
|
|
140
|
-
restr = { :is_equal_to =>
|
|
141
|
-
[
|
|
142
|
-
{:field_uRI => {:field_uRI=>'folder:FolderClass'}},
|
|
143
|
-
{:field_uRI_or_constant=>{:constant =>
|
|
144
|
-
{:value => map_folder_type(opts[:folder_type])}}},
|
|
145
|
-
]
|
|
146
|
-
}
|
|
147
|
-
end
|
|
148
|
-
args = {
|
|
149
|
-
:parent_folder_ids => [folder_id],
|
|
150
|
-
:traversal => opts[:traversal],
|
|
151
|
-
:folder_shape => {:base_shape => opts[:shape]}
|
|
152
|
-
}
|
|
153
|
-
args[:restriction] = restr if restr
|
|
154
|
-
args
|
|
155
|
-
end
|
|
171
|
+
def create_folder_parser(resp)
|
|
172
|
+
raise EwsError, "Could not create folder. #{resp.code}: #{resp.message}" unless resp.status == 'Success'
|
|
156
173
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
folders.collect do |f|
|
|
163
|
-
ftype = f.keys.first
|
|
164
|
-
class_by_name(ftype).new(ews, f[ftype])
|
|
174
|
+
folders = resp.response_message[:elems][:folders][:elems]
|
|
175
|
+
folders.collect do |f|
|
|
176
|
+
ftype = f.keys.first
|
|
177
|
+
class_by_name(ftype).new(ews, f[ftype])
|
|
178
|
+
end
|
|
165
179
|
end
|
|
166
|
-
else
|
|
167
|
-
raise EwsFolderNotFound, "Could not retrieve folders. #{resp.code}: #{resp.message}"
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
180
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
181
|
+
# Build up the arguements for #get_folder
|
|
182
|
+
def get_folder_args(folder_id, opts)
|
|
183
|
+
opts[:shape] ||= :default
|
|
184
|
+
default_args = {
|
|
185
|
+
folder_shape: { base_shape: opts[:shape] }
|
|
186
|
+
}
|
|
187
|
+
default_args[:folder_ids] = if folder_id.is_a?(Hash)
|
|
188
|
+
[folder_id]
|
|
189
|
+
else
|
|
190
|
+
[{ id: folder_id }]
|
|
191
|
+
end
|
|
192
|
+
default_args.merge opts
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# @param [Viewpoint::EWS::SOAP::EwsSoapResponse] resp
|
|
196
|
+
def get_folder_parser(resp)
|
|
197
|
+
unless resp.status == 'Success'
|
|
198
|
+
raise EwsFolderNotFound,
|
|
199
|
+
"Could not retrieve folder. #{resp.code}: #{resp.message}"
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
f = resp.response_message[:elems][:folders][:elems][0]
|
|
175
203
|
ftype = f.keys.first
|
|
176
204
|
class_by_name(ftype).new(ews, f[ftype])
|
|
177
205
|
end
|
|
178
|
-
else
|
|
179
|
-
raise EwsError, "Could not create folder. #{resp.code}: #{resp.message}"
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
206
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
def sync_folders_args(opts)
|
|
208
|
+
opts[:shape] = opts[:shape] || :default
|
|
209
|
+
args = { folder_shape: { base_shape: opts[:shape] } }
|
|
210
|
+
if opts[:folder_id]
|
|
211
|
+
folder_id = opts[:folder_id]
|
|
212
|
+
args[:sync_folder_id] = if folder_id.is_a?(Hash)
|
|
213
|
+
folder_id
|
|
214
|
+
else
|
|
215
|
+
{ id: folder_id }
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
args[:sync_state] = opts[:sync_state] if opts[:sync_state]
|
|
219
|
+
args
|
|
220
|
+
end
|
|
196
221
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
else
|
|
204
|
-
raise EwsFolderNotFound, "Could not retrieve folder. #{resp.code}: #{resp.message}"
|
|
205
|
-
end
|
|
206
|
-
end
|
|
222
|
+
def sync_folders_parser(resp)
|
|
223
|
+
rmsg = resp.response_messages[0]
|
|
224
|
+
unless rmsg.success?
|
|
225
|
+
raise EwsError,
|
|
226
|
+
"Could not synchronize folders. #{rmsg.response_code}: #{rmsg.message_text}"
|
|
227
|
+
end
|
|
207
228
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
229
|
+
rhash = {}
|
|
230
|
+
rhash[:all_synced] = rmsg.includes_last_folder_in_range?
|
|
231
|
+
rhash[:sync_state] = rmsg.sync_state
|
|
232
|
+
rmsg.changes.each do |c|
|
|
233
|
+
ctype = c.keys.first
|
|
234
|
+
rhash[ctype] = [] unless rhash.key?(ctype)
|
|
235
|
+
if ctype == :delete
|
|
236
|
+
rhash[ctype] << c[ctype][:elems][0][:folder_id][:attribs]
|
|
237
|
+
else
|
|
238
|
+
type = c[ctype][:elems][0].keys.first
|
|
239
|
+
item = class_by_name(type).new(ews, c[ctype][:elems][0][type])
|
|
240
|
+
rhash[ctype] << item
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
rhash
|
|
217
244
|
end
|
|
218
|
-
end
|
|
219
|
-
args[:sync_state] = opts[:sync_state] if opts[:sync_state]
|
|
220
|
-
args
|
|
221
|
-
end
|
|
222
245
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
246
|
+
# Map a passed parameter to a know folder type mapping. If no mapping
|
|
247
|
+
# exits simply allow the passed in type to be passed to the SOAP call.
|
|
248
|
+
# @param [Symbol] type a symbol in FOLDER_TYPE_MAP
|
|
249
|
+
def map_folder_type(type)
|
|
250
|
+
FOLDER_TYPE_MAP[type] || type
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def folder_type(type)
|
|
254
|
+
case type
|
|
255
|
+
when nil, :folder
|
|
256
|
+
:folder
|
|
257
|
+
when :calendar, :contacts, :search, :tasks
|
|
258
|
+
"#{type}_folder".to_sym
|
|
234
259
|
else
|
|
235
|
-
|
|
236
|
-
item = class_by_name(type).new(ews, c[ctype][:elems][0][type])
|
|
237
|
-
rhash[ctype] << item
|
|
260
|
+
raise EwsBadArgumentError, "Not a proper folder type: :#{type}"
|
|
238
261
|
end
|
|
239
262
|
end
|
|
240
|
-
rhash
|
|
241
|
-
else
|
|
242
|
-
raise EwsError, "Could not synchronize folders. #{rmsg.response_code}: #{rmsg.message_text}"
|
|
243
263
|
end
|
|
244
264
|
end
|
|
245
|
-
|
|
246
|
-
# Map a passed parameter to a know folder type mapping. If no mapping
|
|
247
|
-
# exits simply allow the passed in type to be passed to the SOAP call.
|
|
248
|
-
# @param [Symbol] type a symbol in FOLDER_TYPE_MAP
|
|
249
|
-
def map_folder_type(type)
|
|
250
|
-
FOLDER_TYPE_MAP[type] || type
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
def folder_type(type)
|
|
254
|
-
case type
|
|
255
|
-
when nil, :folder
|
|
256
|
-
:folder
|
|
257
|
-
when :calendar, :contacts, :search, :tasks
|
|
258
|
-
"#{type}_folder".to_sym
|
|
259
|
-
else
|
|
260
|
-
raise EwsBadArgumentError, "Not a proper folder type: :#{type}"
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
265
|
end
|
data/lib/ews/impersonation.rb
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
:
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
module Viewpoint
|
|
4
|
+
# Exchange Web Services (EWS) client namespace.
|
|
5
|
+
module EWS
|
|
6
|
+
# rubocop:disable Naming/ConstantName -- public API name
|
|
7
|
+
ConnectingSID = {
|
|
8
|
+
UPN: 'PrincipalName',
|
|
9
|
+
SID: 'SID',
|
|
10
|
+
PSMTP: 'PrimarySmtpAddress',
|
|
11
|
+
SMTP: 'SmtpAddress'
|
|
12
|
+
}.freeze
|
|
13
|
+
# rubocop:enable Naming/ConstantName
|
|
14
|
+
|
|
15
|
+
# @param connecting_type [String] should be one of the ConnectingSID variables
|
|
16
|
+
# ConnectingSID[:UPN] - use User Principal Name method
|
|
17
|
+
# ConnectingSID[:SID] - use Security Identifier method
|
|
18
|
+
# ConnectingSID[:PSMTP] - use primary Simple Mail Transfer Protocol method
|
|
19
|
+
# ConnectingSID[:SMTP] - use Simple Mail Transfer Protocol method
|
|
20
|
+
# you can add any other string, it will be converted into xml tag on soap request
|
|
21
|
+
# @param address [String] an address to include to requests for impersonation
|
|
22
|
+
def set_impersonation(connecting_type, address)
|
|
23
|
+
unless ConnectingSID.value?(connecting_type) || connecting_type.is_a?(String)
|
|
24
|
+
raise EwsBadArgumentError, "Not a proper connecting method: #{connecting_type.class}"
|
|
25
|
+
end
|
|
9
26
|
|
|
10
|
-
# @param connecting_type [String] should be one of the ConnectingSID variables
|
|
11
|
-
# ConnectingSID[:UPN] - use User Principal Name method
|
|
12
|
-
# ConnectingSID[:SID] - use Security Identifier method
|
|
13
|
-
# ConnectingSID[:PSMTP] - use primary Simple Mail Transfer Protocol method
|
|
14
|
-
# ConnectingSID[:SMTP] - use Simple Mail Transfer Protocol method
|
|
15
|
-
# you can add any other string, it will be converted into xml tag on soap request
|
|
16
|
-
# @param address [String] an address to include to requests for impersonation
|
|
17
|
-
def set_impersonation(connecting_type, address)
|
|
18
|
-
if ConnectingSID.has_value? connecting_type or connecting_type.is_a? String then
|
|
19
27
|
ews.impersonation_type = connecting_type
|
|
20
28
|
ews.impersonation_address = address
|
|
21
|
-
else
|
|
22
|
-
raise EwsBadArgumentError, "Not a proper connecting method: #{connecting_type.class}"
|
|
23
29
|
end
|
|
24
|
-
end
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
def remove_impersonation
|
|
32
|
+
ews.impersonation_type = ''
|
|
33
|
+
ews.impersonation_address = ''
|
|
34
|
+
end
|
|
29
35
|
end
|
|
30
|
-
end
|
|
36
|
+
end
|