zm-ruby-client 0.14.0 → 0.18.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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -5
  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 +76 -177
  38. data/lib/zm/client/connector/soap_admin.rb +82 -51
  39. data/lib/zm/client/connector/soap_base.rb +12 -12
  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 +11 -6
  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 +19 -19
  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 +1 -1
  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 +15 -10
  129. metadata +53 -26
  130. data/lib/zm/client/connector/soap_xml_builder.rb +0 -68
@@ -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
@@ -2,25 +2,18 @@
2
2
 
3
3
  require_relative 'soap_base'
4
4
  require_relative 'soap_error'
5
- require 'gyoku'
6
-
7
- # include OpenSSL
8
- # include Digest
9
5
 
10
6
  module Zm
11
7
  module Client
12
8
  class SoapAccountConnector < SoapBaseConnector
13
-
14
- SOAP_PATH = '/service/soap/'
15
9
  MAILSPACE = 'urn:zimbraMail'
16
10
  ACCOUNTSPACE = 'urn:zimbraAccount'
17
- A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
18
- A_NODE_PROC_NAME = lambda { |n| { name: n.first, _content: n.last } }
19
- A_NODE_PROC_ARROW_NAME = lambda { |n| { :@name => n.first, content!: n.last } }
11
+ A_NODE_PROC = ->(n) { { n: n.first, _content: n.last } }
12
+ A_NODE_PROC_NAME = ->(n) { { name: n.first, _content: n.last } }
13
+ A_NODE_PROC_ARROW_NAME = ->(n) { { :@name => n.first, content!: n.last } }
20
14
 
21
15
  def initialize(scheme, host, port)
22
- @uri = URI::HTTP.new(scheme, nil, host, port, nil, SOAP_PATH, nil, nil, nil)
23
- init_curl_client
16
+ super(scheme, host, port, '/service/soap/')
24
17
  end
25
18
 
26
19
  def auth_template(mail)
@@ -174,75 +167,41 @@ module Zm
174
167
  # -------------------------------
175
168
  # FOLDER
176
169
 
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)
170
+ def get_folder(token, jsns)
171
+ jsns_request(:GetFolderRequest, token, jsns)
183
172
  end
184
173
 
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
174
+ # def get_all_folders(token, view = nil, tr = nil)
175
+ # soap_name = :GetFolderRequest
176
+ # body = init_hash_request(token, soap_name)
177
+ # req = { view: view, tr: tr }.reject { |_, v| v.nil? }
178
+ # body[:Body][soap_name].merge!(req)
179
+ # curl_request(body)
180
+ # end
192
181
 
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)
182
+ def create_folder(token, jsns)
183
+ jsns_request(:CreateFolderRequest, token, jsns)
200
184
  end
201
185
 
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)
186
+ def folder_action(token, jsns)
187
+ jsns_request(:FolderActionRequest, token, jsns)
209
188
  end
210
189
 
211
190
  def get_all_search_folders(token)
212
- body = init_hash_request(token, :GetSearchFolderRequest)
191
+ soap_name = :GetSearchFolderRequest
192
+ body = init_hash_request(token, soap_name)
213
193
  curl_request(body)
214
194
  end
215
195
 
216
196
  # -------------------------------
217
197
  # SEARCH FOLDER
218
198
 
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)
199
+ def create_search_folder(token, jsns)
200
+ jsns_request(:CreateSearchFolderRequest, token, jsns)
233
201
  end
234
202
 
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)
203
+ def modify_search_folder(token, jsns)
204
+ jsns_request(:ModifySearchFolderRequest, token, jsns)
246
205
  end
247
206
 
248
207
  # -------------------------------
@@ -266,12 +225,8 @@ module Zm
266
225
  # -------------------------------
267
226
  # SHARE
268
227
 
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)
228
+ def create_mountpoint(token, jsns)
229
+ jsns_request(:CreateMountpointRequest, token, jsns)
275
230
  end
276
231
 
277
232
  def get_share_info(token, options = {})
@@ -282,49 +237,16 @@ module Zm
282
237
  curl_request(body)
283
238
  end
284
239
 
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)
240
+ def get_rights(token, jsns)
241
+ jsns_request(:GetRightsRequest, token, jsns, ACCOUNTSPACE)
292
242
  end
293
243
 
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)
244
+ def grant_rights(token, jsns)
245
+ jsns_request(:GrantRightsRequest, token, jsns, ACCOUNTSPACE)
310
246
  end
311
247
 
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)
248
+ def revoke_rights(token, jsns)
249
+ jsns_request(:RevokeRightsRequest, token, jsns, ACCOUNTSPACE)
328
250
  end
329
251
 
330
252
  # -------------------------------
@@ -332,7 +254,7 @@ module Zm
332
254
 
333
255
  def get_msg(token, id, options = {})
334
256
  req = { m: { id: id } }
335
- req[:m].merge(options) unless options.empty?
257
+ req[:m].merge!(options) unless options.empty?
336
258
  body = init_hash_request(token, :GetMsgRequest)
337
259
  body[:Body][:GetMsgRequest].merge!(req)
338
260
  curl_request(body)
@@ -350,7 +272,7 @@ module Zm
350
272
  req = { m: m }
351
273
  body = init_hash_request(token, :SendMsgRequest)
352
274
  body[:Body][:SendMsgRequest].merge!(req)
353
- curl_request(body)
275
+ # curl_request(body)
354
276
  end
355
277
 
356
278
  def add_msg(token, l, eml, d = nil, f = nil, tn = nil)
@@ -378,19 +300,12 @@ module Zm
378
300
  curl_request(body)
379
301
  end
380
302
 
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)
303
+ def create_tag(token, jsns)
304
+ jsns_request(:CreateTagRequest, token, jsns)
386
305
  end
387
306
 
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)
307
+ def tag_action(token, jsns)
308
+ jsns_request(:TagActionRequest, token, jsns)
394
309
  end
395
310
 
396
311
  # -------------------------------
@@ -401,26 +316,20 @@ module Zm
401
316
  curl_request(body)
402
317
  end
403
318
 
404
- def create_identity(token, name, attrs = [])
319
+ def create_identity(token, name, attrs = {})
405
320
  soap_name = :CreateIdentityRequest
406
- req = { identity: { :@name => name, a: attrs.to_a.map(&A_NODE_PROC_ARROW_NAME) } }
407
- body = init_hash_arrow_request(token, soap_name, ACCOUNTSPACE)
408
- body[:Envelope][:Body][soap_name].merge!(req)
409
- body_xml = Gyoku.xml(body, { :key_converter => :none })
410
- # puts body_xml
411
- # todo ne fonctionne pas en JS !
412
- curl_xml(body_xml)
321
+ req = { identity: { name: name, _attrs: attrs } }
322
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
323
+ body[:Body][soap_name].merge!(req)
324
+ curl_request(body)
413
325
  end
414
326
 
415
- def modify_identity(token, id, attrs = [])
327
+ def modify_identity(token, id, attrs = {})
416
328
  soap_name = :ModifyIdentityRequest
417
- req = { identity: { :@id => id, a: attrs.to_a.map(&A_NODE_PROC_ARROW_NAME) } }
418
- body = init_hash_arrow_request(token, soap_name, ACCOUNTSPACE)
419
- body[:Envelope][:Body][soap_name].merge!(req)
420
- body_xml = Gyoku.xml(body, { :key_converter => :none })
421
- # puts body_xml
422
- # todo ne fonctionne pas en JS !
423
- curl_xml(body_xml)
329
+ req = { identity: { id: id, _attrs: attrs } }
330
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
331
+ body[:Body][soap_name].merge!(req)
332
+ curl_request(body)
424
333
  end
425
334
 
426
335
  def delete_identity(token, id)
@@ -441,18 +350,6 @@ module Zm
441
350
  curl_request(body)
442
351
  end
443
352
 
444
- def modify_prefs(token, prefs)
445
- soap_name = :ModifyPrefsRequest
446
- req = { pref: prefs.map { |pref, value| { name: pref, _content: value } } }
447
- body = init_hash_request(token, soap_name, ACCOUNTSPACE)
448
- body[:Body][soap_name].merge!(req) if req.any?
449
- #puts body
450
- #curl_request(body)
451
- #puts SoapXmlBuilder.new(body).to_xml
452
- # todo ne fonctionne pas en JS !
453
- curl_xml(SoapXmlBuilder.new(body).to_xml)
454
- end
455
-
456
353
  def get_filter_rules(token)
457
354
  soap_name = :GetFilterRulesRequest
458
355
  body = init_hash_request(token, soap_name)
@@ -487,18 +384,17 @@ module Zm
487
384
  curl_request(body)
488
385
  end
489
386
 
490
- def delete_signature(token, id)
387
+ def delete_signature(token, jsns)
491
388
  soap_name = :DeleteSignatureRequest
492
- req = { signature: { id: id } }
493
389
  body = init_hash_request(token, soap_name, ACCOUNTSPACE)
494
- body[:Body][soap_name].merge!(req)
390
+ body[:Body][soap_name].merge!(jsns)
495
391
  curl_request(body)
496
392
  end
497
393
 
498
394
  # -------------------------------
499
395
  # GENERIC
500
396
 
501
- def get_info(token, sections = 'mbox', rights = nil)
397
+ def get_info(token, sections = 'mbox,prefs,attrs,zimlets,props,idents,sigs,dsrcs,children', rights = nil)
502
398
  req = { rights: rights, sections: sections }.reject { |_, v| v.nil? }
503
399
  body = init_hash_request(token, :GetInfoRequest, ACCOUNTSPACE)
504
400
  body[:Body][:GetInfoRequest].merge!(req) if req.any?
@@ -513,7 +409,8 @@ module Zm
513
409
  offset: offset,
514
410
  limit: limit,
515
411
  sortBy: sortBy,
516
- query: query
412
+ query: query,
413
+ header: [{ n: 'messageIdHeader' }]
517
414
  }.merge!(options)
518
415
  req.reject! { |_, v| v.nil? }
519
416
 
@@ -522,6 +419,28 @@ module Zm
522
419
  curl_request(body)
523
420
  end
524
421
 
422
+ def jsns_request(soap_name, token, jsns, namespace = MAILSPACE)
423
+ body = init_hash_request(token, soap_name, namespace)
424
+ body[:Body][soap_name].merge!(jsns) if jsns.is_a?(Hash)
425
+ curl_request(body)
426
+ end
427
+
428
+ def ranking_action(token, op, email = nil)
429
+ soap_name = :RankingActionRequest
430
+ req = {
431
+ action: {
432
+ op: op,
433
+ email: email
434
+ }
435
+ }
436
+ req[:action].delete_if { |_, v| v.nil? }
437
+
438
+ body = init_hash_request(token, soap_name)
439
+ body[:Body][soap_name].merge!(req) if req.any?
440
+
441
+ curl_request(body)
442
+ end
443
+
525
444
  private
526
445
 
527
446
  def compute_preauth(mail, ts, domainkey)
@@ -531,33 +450,13 @@ module Zm
531
450
  hmac.to_s
532
451
  end
533
452
 
534
- def init_hash_request(token, soap_name, jsns = MAILSPACE)
453
+ def init_hash_request(token, soap_name, namespace = MAILSPACE)
535
454
  {
536
455
  Body: {
537
- soap_name => { _jsns: jsns }
456
+ soap_name => { _jsns: namespace }
538
457
  }
539
458
  }.merge(hash_header(token))
540
459
  end
541
-
542
- def init_hash_arrow_request(token, soap_name, jsns = MAILSPACE)
543
- { Envelope: {
544
- :@xmlns => 'http://schemas.xmlsoap.org/soap/envelope/',
545
- '@xmlns:urn' => 'urn:zimbra',
546
- Header: {
547
- context: {
548
- authToken: token,
549
- :@xmlns => BASESPACE,
550
- format: {
551
- :@type => 'js'
552
- }
553
- }
554
- },
555
- Body: {
556
- soap_name => { :@xmlns => jsns }
557
- }
558
- }
559
- }
560
- end
561
460
  end
562
461
  end
563
462
  end