zm-ruby-client 0.14.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +1 -0
  4. data/README.md +6 -0
  5. data/lib/zm/client/account/account.rb +29 -17
  6. data/lib/zm/client/account/account_jsns_initializer.rb +44 -0
  7. data/lib/zm/client/account/accounts_builder.rb +6 -3
  8. data/lib/zm/client/account/accounts_collection.rb +11 -20
  9. data/lib/zm/client/account.rb +1 -0
  10. data/lib/zm/client/ace/ace.rb +22 -9
  11. data/lib/zm/client/ace/ace_jsns_builder.rb +38 -0
  12. data/lib/zm/client/ace/ace_jsns_initializer.rb +26 -0
  13. data/lib/zm/client/ace/aces_builder.rb +6 -9
  14. data/lib/zm/client/ace/aces_collection.rb +23 -9
  15. data/lib/zm/client/ace.rb +2 -0
  16. data/lib/zm/client/appointment/appointment.rb +9 -6
  17. data/lib/zm/client/appointment/appointments_collection.rb +6 -90
  18. data/lib/zm/client/backup/backup.rb +8 -4
  19. data/lib/zm/client/base/account_object.rb +34 -0
  20. data/lib/zm/client/base/account_objects_collection.rb +14 -0
  21. data/lib/zm/client/base/account_search_objects_collection.rb +125 -0
  22. data/lib/zm/client/base/admin_object.rb +6 -0
  23. data/lib/zm/client/base/admin_objects_collection.rb +65 -0
  24. data/lib/zm/client/base/base_jsns_builder.rb +19 -0
  25. data/lib/zm/client/base/base_jsns_initializer.rb +29 -0
  26. data/lib/zm/client/base/folder_object.rb +41 -0
  27. data/lib/zm/client/base/ldap_filter.rb +33 -0
  28. data/lib/zm/client/base/object.rb +19 -0
  29. data/lib/zm/client/base/objects_builder.rb +4 -0
  30. data/lib/zm/client/base/objects_collection.rb +11 -32
  31. data/lib/zm/client/base/zimbra_attribute.rb +119 -0
  32. data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -0
  33. data/lib/zm/client/base.rb +15 -0
  34. data/lib/zm/client/cluster/cluster.rb +43 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/connector/rest_account.rb +0 -3
  37. data/lib/zm/client/connector/soap_account.rb +66 -123
  38. data/lib/zm/client/connector/soap_admin.rb +28 -16
  39. data/lib/zm/client/connector/soap_base.rb +11 -3
  40. data/lib/zm/client/contact/contact.rb +2 -1
  41. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  42. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  43. data/lib/zm/client/cos/cos.rb +9 -5
  44. data/lib/zm/client/cos/coses_builder.rb +1 -16
  45. data/lib/zm/client/cos/coses_collection.rb +6 -9
  46. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  47. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  48. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  49. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  50. data/lib/zm/client/distributionlist.rb +1 -0
  51. data/lib/zm/client/document/document.rb +7 -9
  52. data/lib/zm/client/domain/domain.rb +11 -6
  53. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  54. data/lib/zm/client/domain/domains_builder.rb +1 -19
  55. data/lib/zm/client/domain/domains_collection.rb +7 -10
  56. data/lib/zm/client/domain.rb +1 -0
  57. data/lib/zm/client/folder/folder.rb +50 -124
  58. data/lib/zm/client/folder/folder_grant.rb +44 -22
  59. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  60. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  61. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  62. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  63. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  64. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  65. data/lib/zm/client/folder/folders_builder.rb +2 -2
  66. data/lib/zm/client/folder/folders_collection.rb +21 -19
  67. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  68. data/lib/zm/client/folder.rb +6 -0
  69. data/lib/zm/client/identity/identities_builder.rb +4 -15
  70. data/lib/zm/client/identity/identities_collection.rb +7 -13
  71. data/lib/zm/client/identity/identity.rb +7 -5
  72. data/lib/zm/client/message/message.rb +111 -21
  73. data/lib/zm/client/message/messages_builder.rb +1 -1
  74. data/lib/zm/client/message/messages_collection.rb +10 -92
  75. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  76. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  77. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  78. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  79. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  80. data/lib/zm/client/mountpoint.rb +2 -0
  81. data/lib/zm/client/resource/resource.rb +5 -5
  82. data/lib/zm/client/resource/resources_builder.rb +1 -16
  83. data/lib/zm/client/resource/resources_collection.rb +5 -13
  84. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  85. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  86. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  87. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  88. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  89. data/lib/zm/client/search_folder.rb +2 -0
  90. data/lib/zm/client/server/server.rb +7 -14
  91. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  92. data/lib/zm/client/server/servers_builder.rb +4 -16
  93. data/lib/zm/client/server/servers_collection.rb +5 -10
  94. data/lib/zm/client/server.rb +1 -0
  95. data/lib/zm/client/share/share.rb +2 -9
  96. data/lib/zm/client/share/shares_builder.rb +3 -12
  97. data/lib/zm/client/signature/signature.rb +17 -13
  98. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  99. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  100. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  101. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  102. data/lib/zm/client/signature.rb +1 -0
  103. data/lib/zm/client/tag/tag.rb +27 -20
  104. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  105. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  106. data/lib/zm/client/tag/tags_builder.rb +6 -9
  107. data/lib/zm/client/tag/tags_collection.rb +6 -12
  108. data/lib/zm/client/tag.rb +2 -0
  109. data/lib/zm/client/task/tasks_collection.rb +6 -90
  110. data/lib/zm/client/upload/upload.rb +1 -1
  111. data/lib/zm/client/version.rb +2 -2
  112. data/lib/zm/modules/common/dl_common.rb +3 -1
  113. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  114. data/lib/zm/modules/zm_logger.rb +24 -0
  115. data/lib/zm/modules/zm_model.rb +41 -0
  116. data/test/accounts.rb +15 -1
  117. data/test/ace.rb +50 -0
  118. data/test/cluster.rb +41 -0
  119. data/test/cluster_zimbra_attributes.rb +38 -0
  120. data/test/folder.rb +125 -0
  121. data/test/folder_grant.rb +51 -0
  122. data/test/mountpoint.rb +49 -0
  123. data/test/retention_policies.rb +40 -0
  124. data/test/search_folder.rb +67 -0
  125. data/test/signature.rb +53 -0
  126. data/test/tag.rb +65 -0
  127. data/test/zimbra_attributes.rb +35 -0
  128. data/zm-ruby-client.gemspec +1 -0
  129. metadata +59 -3
@@ -4,31 +4,48 @@ require 'zm/client/connector/soap_admin'
4
4
  require 'zm/client/connector/soap_account'
5
5
  require 'zm/client/common'
6
6
  # require 'zm/client/data_source'
7
- require 'zm/client/domain'
8
7
  require 'zm/client/account'
8
+ require 'zm/client/domain'
9
9
  require 'zm/client/resource'
10
10
  require 'zm/client/distributionlist'
11
11
  require 'zm/client/server'
12
12
  require 'zm/client/cos'
13
13
  require 'zm/client/license'
14
- # require 'zm/client/distributionlist'
15
14
 
16
15
  module Zm
17
16
  module Client
18
17
  # class admin connection
19
18
  class Cluster
20
- attr_reader :soap_admin_connector, :config
19
+
20
+ attr_reader :soap_admin_connector, :config, :zimbra_attributes
21
+
22
+ attr_reader :type, :version, :release, :buildDate, :host, :majorversion, :minorversion, :microversion
21
23
 
22
24
  def initialize(config)
25
+ extend(ZmLogger)
26
+
23
27
  @config = config
28
+ @version = config.zimbra_version
29
+
30
+ @zimbra_attributes = Base::ZimbraAttributesCollection.new(self)
31
+ @zimbra_attributes.set_methods
32
+
24
33
  @soap_admin_connector = SoapAdminConnector.new(
25
34
  @config.zimbra_admin_scheme,
26
35
  @config.zimbra_admin_host,
27
36
  @config.zimbra_admin_port
28
37
  )
38
+ @soap_admin_connector.logger = logger
39
+ end
40
+
41
+ def has_admin_credentials?
42
+ @config.has_admin_credentials?
29
43
  end
30
44
 
31
45
  def login
46
+ raise ClusterConfigError, 'admin credentials are missing' unless @config.has_admin_credentials?
47
+
48
+ logger.info "Get Admin session token"
32
49
  @soap_admin_connector.auth(
33
50
  @config.zimbra_admin_login,
34
51
  @config.zimbra_admin_password
@@ -42,16 +59,21 @@ module Zm
42
59
  def alive?
43
60
  @soap_admin_connector.noop
44
61
  true
45
- rescue Zm::Client::SoapError => _
62
+ rescue Zm::Client::SoapError => e
63
+ logger.error "Admin session token alive ? #{e.message}"
46
64
  false
47
65
  end
48
66
 
49
67
  def soap_account_connector
50
- @soap_account_connector ||= SoapAccountConnector.new(
68
+ return @soap_account_connector unless @soap_account_connector.nil?
69
+
70
+ @soap_account_connector = SoapAccountConnector.new(
51
71
  @config.zimbra_public_scheme,
52
72
  @config.zimbra_public_host,
53
73
  @config.zimbra_public_port
54
74
  )
75
+ @soap_account_connector.logger = logger
76
+ @soap_account_connector
55
77
  end
56
78
 
57
79
  def token_metadata
@@ -61,7 +83,7 @@ module Zm
61
83
  def license
62
84
  @license ||= LicensesCollection.new(self).find
63
85
  rescue Zm::Client::SoapError => e
64
- puts e.message
86
+ logger.error "Get License info #{e.message}"
65
87
  nil
66
88
  end
67
89
 
@@ -111,10 +133,24 @@ module Zm
111
133
  !num.zero?
112
134
  end
113
135
 
136
+ def infos!
137
+ rep = soap_admin_connector.get_version_info
138
+ json = rep[:Body][:GetVersionInfoResponse][:info].first
139
+
140
+ instance_variable_set(:@type, json[:type])
141
+ instance_variable_set(:@version, json[:version])
142
+ instance_variable_set(:@release, json[:release])
143
+ instance_variable_set(:@buildDate, json[:buildDate])
144
+ instance_variable_set(:@host, json[:host])
145
+ instance_variable_set(:@majorversion, json[:majorversion])
146
+ instance_variable_set(:@minorversion, json[:minorversion])
147
+ instance_variable_set(:@microversion, json[:microversion])
148
+ end
149
+
114
150
  private
115
151
 
116
152
  def find_domain_key(domain_name)
117
- domains.find_by({ name: domain_name }, 'zimbraPreAuthKey').zimbraPreAuthKey
153
+ domains.attrs('zimbraPreAuthKey').find_by(name: domain_name).zimbraPreAuthKey
118
154
  end
119
155
  end
120
156
  end
@@ -11,18 +11,16 @@ module Zm
11
11
  :zimbra_admin_port, :zimbra_admin_login,
12
12
  :zimbra_admin_password, :zimbra_public_host,
13
13
  :zimbra_public_scheme, :zimbra_public_port,
14
- :domains
14
+ :domains, :zimbra_version
15
15
 
16
16
  def initialize(parameters = nil)
17
- @zimbra_admin_scheme = 'https'
18
- @zimbra_admin_port = 7071
19
- @zimbra_public_scheme = 'https'
20
- @zimbra_public_port = 443
21
17
  @domains = []
18
+ @zimbra_version = '8.8.15'
22
19
 
23
- if parameters.is_a?(String)
20
+ case parameters
21
+ when String
24
22
  init_from_file(parameters)
25
- elsif parameters.is_a?(Hash)
23
+ when Hash
26
24
  @to_h = parameters
27
25
  end
28
26
 
@@ -45,14 +43,15 @@ module Zm
45
43
  end
46
44
 
47
45
  def init_from_h
48
- @zimbra_admin_host = @to_h[:zimbra_admin_host] unless @to_h[:zimbra_admin_host].nil?
49
- @zimbra_admin_scheme = @to_h[:zimbra_admin_scheme] unless @to_h[:zimbra_admin_scheme].nil?
50
- @zimbra_admin_port = @to_h[:zimbra_admin_port] unless @to_h[:zimbra_admin_port].nil?
51
- @zimbra_admin_login = @to_h[:zimbra_admin_login] unless @to_h[:zimbra_admin_login].nil?
52
- @zimbra_admin_password = @to_h[:zimbra_admin_password] unless @to_h[:zimbra_admin_password].nil?
53
- @zimbra_public_host = @to_h[:zimbra_public_host] unless @to_h[:zimbra_public_host].nil?
54
- @zimbra_public_scheme = @to_h[:zimbra_public_scheme] unless @to_h[:zimbra_public_scheme].nil?
55
- @zimbra_public_port = @to_h[:zimbra_public_port] unless @to_h[:zimbra_public_port].nil?
46
+ @zimbra_admin_host = @to_h.fetch(:zimbra_admin_host, nil)
47
+ @zimbra_admin_scheme = @to_h.fetch(:zimbra_admin_scheme, 'https')
48
+ @zimbra_admin_port = @to_h.fetch(:zimbra_admin_port, 7071)
49
+ @zimbra_admin_login = @to_h.fetch(:zimbra_admin_login, nil)
50
+ @zimbra_admin_password = @to_h.fetch(:zimbra_admin_password, nil)
51
+ @zimbra_public_host = @to_h.fetch(:zimbra_public_host, nil)
52
+ @zimbra_public_scheme = @to_h.fetch(:zimbra_public_scheme, 'https')
53
+ @zimbra_public_port = @to_h.fetch(:zimbra_public_port, 443)
54
+ @zimbra_version = @to_h.fetch(:zimbra_version, '8.8.15')
56
55
  end
57
56
 
58
57
  def init_from_yml(file_config_path)
@@ -81,6 +80,10 @@ module Zm
81
80
 
82
81
  domain.key
83
82
  end
83
+
84
+ def has_admin_credentials?
85
+ !@zimbra_admin_host.nil? && !@zimbra_admin_login.nil? && !@zimbra_admin_password.nil?
86
+ end
84
87
  end
85
88
 
86
89
  # class config for connection
@@ -94,7 +97,6 @@ module Zm
94
97
  end
95
98
 
96
99
  # class error for config
97
- class ClusterConfigError < StandardError
98
- end
100
+ class ClusterConfigError < StandardError; end
99
101
  end
100
102
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'openssl'
4
- require 'curb'
5
-
6
3
  module Zm
7
4
  module Client
8
5
  class RestAccountConnector
@@ -11,7 +11,7 @@ module Zm
11
11
  module Client
12
12
  class SoapAccountConnector < SoapBaseConnector
13
13
 
14
- SOAP_PATH = '/service/soap/'
14
+ # SOAP_PATH = '/service/soap/'
15
15
  MAILSPACE = 'urn:zimbraMail'
16
16
  ACCOUNTSPACE = 'urn:zimbraAccount'
17
17
  A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
@@ -19,8 +19,7 @@ module Zm
19
19
  A_NODE_PROC_ARROW_NAME = lambda { |n| { :@name => n.first, content!: n.last } }
20
20
 
21
21
  def initialize(scheme, host, port)
22
- @uri = URI::HTTP.new(scheme, nil, host, port, nil, SOAP_PATH, nil, nil, nil)
23
- init_curl_client
22
+ super(scheme, host, port, '/service/soap/')
24
23
  end
25
24
 
26
25
  def auth_template(mail)
@@ -174,75 +173,41 @@ module Zm
174
173
  # -------------------------------
175
174
  # FOLDER
176
175
 
177
- def get_folder(token, id)
178
- soap_name = :GetFolderRequest
179
- body = init_hash_request(token, soap_name)
180
- req = { folder: { l: id } }
181
- body[:Body][soap_name].merge!(req)
182
- curl_request(body)
176
+ def get_folder(token, jsns)
177
+ jsns_request(:GetFolderRequest, token, jsns)
183
178
  end
184
179
 
185
- def get_all_folders(token, view = nil, tr = nil)
186
- soap_name = :GetFolderRequest
187
- body = init_hash_request(token, soap_name)
188
- req = { view: view, tr: tr }.reject { |_, v| v.nil? }
189
- body[:Body][soap_name].merge!(req)
190
- curl_request(body)
191
- end
180
+ # def get_all_folders(token, view = nil, tr = nil)
181
+ # soap_name = :GetFolderRequest
182
+ # body = init_hash_request(token, soap_name)
183
+ # req = { view: view, tr: tr }.reject { |_, v| v.nil? }
184
+ # body[:Body][soap_name].merge!(req)
185
+ # curl_request(body)
186
+ # end
192
187
 
193
- def create_folder(token, folder_options)
194
- soap_name = :CreateFolderRequest
195
- # folder = { l: parent_id, name: name, view: view, color: color }.merge(options)
196
- req = { folder: folder_options }
197
- body = init_hash_request(token, soap_name)
198
- body[:Body][soap_name].merge!(req)
199
- curl_request(body)
188
+ def create_folder(token, jsns)
189
+ jsns_request(:CreateFolderRequest, token, jsns)
200
190
  end
201
191
 
202
- def folder_action(token, op, id, options = {})
203
- soap_name = :FolderActionRequest
204
- action = { op: op, id: id }.merge(options)
205
- req = { action: action }
206
- body = init_hash_request(token, soap_name)
207
- body[:Body][soap_name].merge!(req)
208
- curl_request(body)
192
+ def folder_action(token, jsns)
193
+ jsns_request(:FolderActionRequest, token, jsns)
209
194
  end
210
195
 
211
196
  def get_all_search_folders(token)
212
- body = init_hash_request(token, :GetSearchFolderRequest)
197
+ soap_name = :GetSearchFolderRequest
198
+ body = init_hash_request(token, soap_name)
213
199
  curl_request(body)
214
200
  end
215
201
 
216
202
  # -------------------------------
217
203
  # SEARCH FOLDER
218
204
 
219
- def create_search_folder(token, name, query, types = 'messages', l = 1, color = nil, sort_by = nil)
220
- search = {
221
- name: name,
222
- query: query,
223
- types: types,
224
- sortBy: sort_by,
225
- color: color,
226
- l: l
227
- }.reject { |_, v| v.nil? }
228
-
229
- req = { search: search }
230
- body = init_hash_request(token, :CreateSearchFolderRequest)
231
- body[:Body][:CreateSearchFolderRequest].merge!(req)
232
- curl_request(body)
205
+ def create_search_folder(token, jsns)
206
+ jsns_request(:CreateSearchFolderRequest, token, jsns)
233
207
  end
234
208
 
235
- def modify_search_folder(token, id, query, types = 'messages')
236
- search = {
237
- id: id,
238
- query: query,
239
- types: types
240
- }.reject { |_, v| v.nil? }
241
-
242
- req = { search: search }
243
- body = init_hash_request(token, :ModifySearchFolderRequest)
244
- body[:Body][:ModifySearchFolderRequest].merge!(req)
245
- curl_request(body)
209
+ def modify_search_folder(token, jsns)
210
+ jsns_request(:ModifySearchFolderRequest, token, jsns)
246
211
  end
247
212
 
248
213
  # -------------------------------
@@ -266,12 +231,8 @@ module Zm
266
231
  # -------------------------------
267
232
  # SHARE
268
233
 
269
- def create_mountpoint(token, link_option)
270
- soap_name = :CreateMountpointRequest
271
- req = { link: link_option }
272
- body = init_hash_request(token, soap_name)
273
- body[:Body][soap_name].merge!(req)
274
- curl_request(body)
234
+ def create_mountpoint(token, jsns)
235
+ jsns_request(:CreateMountpointRequest, token, jsns)
275
236
  end
276
237
 
277
238
  def get_share_info(token, options = {})
@@ -282,49 +243,16 @@ module Zm
282
243
  curl_request(body)
283
244
  end
284
245
 
285
- def get_rights(token, rights)
286
- soap_name = :GetRightsRequest
287
- ace = rights.map { |r| { right: r } }
288
- req = { ace: ace }
289
- body = init_hash_request(token, soap_name, ACCOUNTSPACE)
290
- body[:Body][soap_name].merge!(req)
291
- curl_request(body)
246
+ def get_rights(token, jsns)
247
+ jsns_request(:GetRightsRequest, token, jsns, ACCOUNTSPACE)
292
248
  end
293
249
 
294
- def grant_rights(token, zid = nil, gt = nil, right = nil, d = nil, key = nil, pw = nil, deny = nil, chkgt = nil)
295
- ace = {
296
- zid: zid,
297
- gt: gt,
298
- right: right,
299
- d: d,
300
- key: key,
301
- pw: pw,
302
- deny: deny,
303
- chkgt: chkgt
304
- }.reject { |_, v| v.nil? }
305
-
306
- req = { ace: ace }
307
- body = init_hash_request(token, :GrantRightsRequest, ACCOUNTSPACE)
308
- body[:Body][:GrantRightsRequest].merge!(req)
309
- curl_request(body)
250
+ def grant_rights(token, jsns)
251
+ jsns_request(:GrantRightsRequest, token, jsns, ACCOUNTSPACE)
310
252
  end
311
253
 
312
- def revoke_rights(token, zid = nil, gt = nil, right = nil, d = nil, key = nil, pw = nil, deny = nil, chkgt = nil)
313
- ace = {
314
- zid: zid,
315
- gt: gt,
316
- right: right,
317
- d: d,
318
- key: key,
319
- pw: pw,
320
- deny: deny,
321
- chkgt: chkgt
322
- }.reject { |_, v| v.nil? }
323
-
324
- req = { ace: ace }
325
- body = init_hash_request(token, :RevokeRightsRequest, ACCOUNTSPACE)
326
- body[:Body][:RevokeRightsRequest].merge!(req)
327
- curl_request(body)
254
+ def revoke_rights(token, jsns)
255
+ jsns_request(:RevokeRightsRequest, token, jsns, ACCOUNTSPACE)
328
256
  end
329
257
 
330
258
  # -------------------------------
@@ -332,7 +260,7 @@ module Zm
332
260
 
333
261
  def get_msg(token, id, options = {})
334
262
  req = { m: { id: id } }
335
- req[:m].merge(options) unless options.empty?
263
+ req[:m].merge!(options) unless options.empty?
336
264
  body = init_hash_request(token, :GetMsgRequest)
337
265
  body[:Body][:GetMsgRequest].merge!(req)
338
266
  curl_request(body)
@@ -350,7 +278,7 @@ module Zm
350
278
  req = { m: m }
351
279
  body = init_hash_request(token, :SendMsgRequest)
352
280
  body[:Body][:SendMsgRequest].merge!(req)
353
- curl_request(body)
281
+ # curl_request(body)
354
282
  end
355
283
 
356
284
  def add_msg(token, l, eml, d = nil, f = nil, tn = nil)
@@ -378,19 +306,12 @@ module Zm
378
306
  curl_request(body)
379
307
  end
380
308
 
381
- def create_tag(token, name, color, rgb)
382
- body = init_hash_request(token, :CreateTagRequest)
383
- req = { tag: { name: name, color: color, rgb: rgb }.reject { |_, v| v.nil? } }
384
- body[:Body][:CreateTagRequest].merge!(req)
385
- curl_request(body)
309
+ def create_tag(token, jsns)
310
+ jsns_request(:CreateTagRequest, token, jsns)
386
311
  end
387
312
 
388
- def tag_action(token, op, id, options = {})
389
- action = { op: op, id: id }.merge(options)
390
- req = { action: action }
391
- body = init_hash_request(token, :TagActionRequest)
392
- body[:Body][:TagActionRequest].merge!(req)
393
- curl_request(body)
313
+ def tag_action(token, jsns)
314
+ jsns_request(:TagActionRequest, token, jsns)
394
315
  end
395
316
 
396
317
  # -------------------------------
@@ -487,18 +408,17 @@ module Zm
487
408
  curl_request(body)
488
409
  end
489
410
 
490
- def delete_signature(token, id)
411
+ def delete_signature(token, jsns)
491
412
  soap_name = :DeleteSignatureRequest
492
- req = { signature: { id: id } }
493
413
  body = init_hash_request(token, soap_name, ACCOUNTSPACE)
494
- body[:Body][soap_name].merge!(req)
414
+ body[:Body][soap_name].merge!(jsns)
495
415
  curl_request(body)
496
416
  end
497
417
 
498
418
  # -------------------------------
499
419
  # GENERIC
500
420
 
501
- def get_info(token, sections = 'mbox', rights = nil)
421
+ def get_info(token, sections = 'mbox,prefs,attrs,zimlets,props,idents,sigs,dsrcs,children', rights = nil)
502
422
  req = { rights: rights, sections: sections }.reject { |_, v| v.nil? }
503
423
  body = init_hash_request(token, :GetInfoRequest, ACCOUNTSPACE)
504
424
  body[:Body][:GetInfoRequest].merge!(req) if req.any?
@@ -513,7 +433,8 @@ module Zm
513
433
  offset: offset,
514
434
  limit: limit,
515
435
  sortBy: sortBy,
516
- query: query
436
+ query: query,
437
+ header: [{ n: 'messageIdHeader' }]
517
438
  }.merge!(options)
518
439
  req.reject! { |_, v| v.nil? }
519
440
 
@@ -522,6 +443,28 @@ module Zm
522
443
  curl_request(body)
523
444
  end
524
445
 
446
+ def jsns_request(soap_name, token, jsns, namespace = MAILSPACE)
447
+ body = init_hash_request(token, soap_name, namespace)
448
+ body[:Body][soap_name].merge!(jsns) if jsns.is_a?(Hash)
449
+ curl_request(body)
450
+ end
451
+
452
+ def ranking_action(token, op, email = nil)
453
+ soap_name = :RankingActionRequest
454
+ req = {
455
+ action: {
456
+ op: op,
457
+ email: email
458
+ }
459
+ }
460
+ req[:action].delete_if { |_, v| v.nil? }
461
+
462
+ body = init_hash_request(token, soap_name)
463
+ body[:Body][soap_name].merge!(req) if req.any?
464
+
465
+ curl_request(body)
466
+ end
467
+
525
468
  private
526
469
 
527
470
  def compute_preauth(mail, ts, domainkey)
@@ -531,15 +474,15 @@ module Zm
531
474
  hmac.to_s
532
475
  end
533
476
 
534
- def init_hash_request(token, soap_name, jsns = MAILSPACE)
477
+ def init_hash_request(token, soap_name, namespace = MAILSPACE)
535
478
  {
536
479
  Body: {
537
- soap_name => { _jsns: jsns }
480
+ soap_name => { _jsns: namespace }
538
481
  }
539
482
  }.merge(hash_header(token))
540
483
  end
541
484
 
542
- def init_hash_arrow_request(token, soap_name, jsns = MAILSPACE)
485
+ def init_hash_arrow_request(token, soap_name, namespace = MAILSPACE)
543
486
  { Envelope: {
544
487
  :@xmlns => 'http://schemas.xmlsoap.org/soap/envelope/',
545
488
  '@xmlns:urn' => 'urn:zimbra',
@@ -553,7 +496,7 @@ module Zm
553
496
  }
554
497
  },
555
498
  Body: {
556
- soap_name => { :@xmlns => jsns }
499
+ soap_name => { :@xmlns => namespace }
557
500
  }
558
501
  }
559
502
  }
@@ -8,16 +8,14 @@ module Zm
8
8
  module Client
9
9
  class SoapAdminConnector < SoapBaseConnector
10
10
 
11
- SOAP_PATH = '/service/admin/soap/'
11
+ # SOAP_PATH = '/service/admin/soap/'
12
12
  ADMINSPACE = 'urn:zimbraAdmin'
13
13
  A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
14
14
 
15
15
  attr_accessor :token
16
16
 
17
17
  def initialize(scheme, host, port)
18
- @verbose = false
19
- @uri = URI::HTTP.new(scheme, nil, host, port, nil, SOAP_PATH, nil, nil, nil)
20
- init_curl_client
18
+ super(scheme, host, port, '/service/admin/soap/')
21
19
  end
22
20
 
23
21
  def auth(mail, password)
@@ -156,7 +154,6 @@ module Zm
156
154
  # req = { _jsns: ADMINSPACE, id: id, a: attrs.to_a.map{ |n| { n: n.first, _content: n.last } } }
157
155
  req = { _jsns: ADMINSPACE, id: id }
158
156
  body = { Body: { ModifyCosRequest: req } }.merge(hash_header(@token))
159
- # puts body
160
157
  # todo ne fonctionne pas !
161
158
  # peut-être seul la version xml fonctionne. Il faudrait créer une fonction qui converti le json en xml
162
159
  curl_request(body)
@@ -169,7 +166,6 @@ module Zm
169
166
  # req[:a] = attrs.map{|i|i.last.is_a?(Array) ? i.last.map{|j|[i.first, j]} : [i]}.flatten(1).map { |n| { n: n.first, _content: n.last } }
170
167
  body = init_hash_request(soap_name)
171
168
  body[:Body][soap_name].merge!(req)
172
- # puts body
173
169
  curl_request(body)
174
170
  end
175
171
 
@@ -189,7 +185,6 @@ module Zm
189
185
  req[:a] = attrs.map { |i| i.last.is_a?(Array) ? i.last.map{|j|[i.first, j]} : [i] }.flatten(1).map(&A_NODE_PROC)
190
186
  body = init_hash_request(soap_name)
191
187
  body[:Body][soap_name].merge!(req)
192
- # puts body
193
188
  curl_request(body)
194
189
  end
195
190
 
@@ -263,7 +258,6 @@ module Zm
263
258
  req = { id: id, alias: email }
264
259
  body = init_hash_request(soap_name)
265
260
  body[:Body][soap_name].merge!(req)
266
- # puts body
267
261
  curl_request(body)
268
262
  end
269
263
 
@@ -284,7 +278,6 @@ module Zm
284
278
  body = init_hash_request(:GetDomainRequest)
285
279
  body[:Body][:GetDomainRequest].merge!(req)
286
280
  # TODO: tester param attrs
287
- # puts body
288
281
  curl_request(body)
289
282
  end
290
283
 
@@ -309,7 +302,6 @@ module Zm
309
302
  req[:attrs] = attrs unless attrs.nil? || attrs.empty?
310
303
  body = init_hash_request(soap_name)
311
304
  body[:Body][soap_name].merge!(req)
312
- # puts body
313
305
  curl_request(body)
314
306
  end
315
307
 
@@ -341,6 +333,16 @@ module Zm
341
333
  curl_request(body)
342
334
  end
343
335
 
336
+ def get_distribution_list_membership(by_key, by = 'name', limit = nil, offset = nil)
337
+ soap_name = :GetDistributionListMembershipRequest
338
+ req = { dl: { by: by, _content: by_key }, limit: limit, offset: offset }
339
+ req.reject! { |_, v| v.nil? }
340
+ body = init_hash_request(soap_name)
341
+ body[:Body][soap_name].merge!(req)
342
+
343
+ curl_request(body)
344
+ end
345
+
344
346
  def delete_account(id)
345
347
  generic_delete(:DeleteAccountRequest, id)
346
348
  end
@@ -394,7 +396,6 @@ module Zm
394
396
  # body = { Body: { SearchDirectoryRequest: { _jsns: ADMINSPACE } } }.merge(hash_header(@token))
395
397
  body = init_hash_request(soap_name)
396
398
  body[:Body][soap_name].merge!(req)
397
- # puts body
398
399
 
399
400
  curl_request(body)
400
401
  end
@@ -429,11 +430,11 @@ module Zm
429
430
  curl_request(body)
430
431
  end
431
432
 
432
- def flush_cache(type, all_servers, id = nil)
433
+ def flush_cache(type, all_servers, id = nil, target_server_id = nil)
433
434
  soap_name = :FlushCacheRequest
434
435
  req = { cache: { type: type, allServers: all_servers } }
435
436
  req[:cache].merge!({ entry: { by: :id, _content: id } }) unless id.nil?
436
- body = init_hash_request(soap_name)
437
+ body = init_hash_request(soap_name, target_server_id)
437
438
  body[:Body][soap_name].merge!(req)
438
439
  curl_request(body)
439
440
  end
@@ -467,7 +468,6 @@ module Zm
467
468
  body = init_hash_request(soap_name)
468
469
  req = { server: { name: server_name } }
469
470
  body[:Body][soap_name].merge!(req)
470
- # puts body.to_json
471
471
  curl_request(body)
472
472
  end
473
473
 
@@ -495,7 +495,6 @@ module Zm
495
495
  }
496
496
  }
497
497
  body[:Body][soap_name].merge!(req)
498
- # puts body.to_json
499
498
  curl_request(body)
500
499
  end
501
500
 
@@ -515,11 +514,24 @@ module Zm
515
514
  body = init_hash_request(soap_name, dest_id)
516
515
  req = { query: {} }
517
516
  body[:Body][soap_name].merge!(req)
518
- # puts body
519
517
  curl_request(body)
520
518
  # curl_xml(SoapXmlBuilder.new(body).to_xml)
521
519
  end
522
520
 
521
+ def set_password(id, new_password)
522
+ soap_name = :SetPasswordRequest
523
+ body = init_hash_request(soap_name)
524
+ req = { id: id, newPassword: new_password }
525
+ body[:Body][soap_name].merge!(req)
526
+ curl_request(body)
527
+ end
528
+
529
+ def get_version_info
530
+ soap_name = :GetVersionInfoRequest
531
+ body = init_hash_request(soap_name)
532
+ curl_request(body)
533
+ end
534
+
523
535
  def init_hash_request(soap_name, target_server = nil)
524
536
  {
525
537
  Body: {
@@ -16,6 +16,13 @@ module Zm
16
16
  }.freeze
17
17
  BODY = :Body
18
18
 
19
+ def initialize(scheme, host, port, soap_path)
20
+ extend(ZmLogger)
21
+ @verbose = false
22
+ @uri = URI::HTTP.new(scheme, nil, host, port, nil, soap_path, nil, nil, nil)
23
+ init_curl_client
24
+ end
25
+
19
26
  def verbose!
20
27
  @verbose = true
21
28
  @curl.verbose = @verbose
@@ -36,10 +43,11 @@ module Zm
36
43
  end
37
44
 
38
45
  def curl_request(body, error_handler = SoapError)
39
- puts body.to_json if @verbose
46
+ logger.debug body.to_json
40
47
  @curl.http_post(body.to_json)
41
48
 
42
- puts @curl.body_str if @verbose
49
+ logger.debug @curl.body_str
50
+
43
51
  soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
44
52
  raise(error_handler, soapbody) if @curl.status.to_i >= 400
45
53
 
@@ -47,7 +55,7 @@ module Zm
47
55
  end
48
56
 
49
57
  def curl_xml(xml, error_handler = SoapError)
50
- # puts xml
58
+ logger.debug xml
51
59
  @curl.http_post(xml)
52
60
 
53
61
  soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
@@ -108,7 +108,8 @@ module Zm
108
108
  end
109
109
 
110
110
  def delete!
111
- @parent.sacc.contact_action(@parent.token, :delete, id)
111
+ @parent.sacc.contact_action(@parent.token, :delete, @id)
112
+ super
112
113
  end
113
114
 
114
115
  def update!(hash)