zm-ruby-client 0.10.4 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) 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 +39 -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 +47 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/common/token_metadata.rb +44 -0
  37. data/lib/zm/client/common.rb +2 -1
  38. data/lib/zm/client/connector/rest_account.rb +0 -3
  39. data/lib/zm/client/connector/soap_account.rb +66 -122
  40. data/lib/zm/client/connector/soap_admin.rb +47 -15
  41. data/lib/zm/client/connector/soap_base.rb +11 -3
  42. data/lib/zm/client/contact/contact.rb +2 -1
  43. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  44. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  45. data/lib/zm/client/cos/cos.rb +9 -5
  46. data/lib/zm/client/cos/coses_builder.rb +1 -16
  47. data/lib/zm/client/cos/coses_collection.rb +6 -9
  48. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  49. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  50. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  51. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  52. data/lib/zm/client/distributionlist.rb +1 -0
  53. data/lib/zm/client/document/document.rb +11 -9
  54. data/lib/zm/client/domain/domain.rb +23 -7
  55. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  56. data/lib/zm/client/domain/domains_builder.rb +1 -19
  57. data/lib/zm/client/domain/domains_collection.rb +7 -10
  58. data/lib/zm/client/domain.rb +1 -0
  59. data/lib/zm/client/folder/folder.rb +50 -124
  60. data/lib/zm/client/folder/folder_grant.rb +44 -22
  61. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  62. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  63. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  64. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  65. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  66. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  67. data/lib/zm/client/folder/folders_builder.rb +2 -2
  68. data/lib/zm/client/folder/folders_collection.rb +46 -19
  69. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  70. data/lib/zm/client/folder.rb +6 -0
  71. data/lib/zm/client/identity/identities_builder.rb +4 -15
  72. data/lib/zm/client/identity/identities_collection.rb +7 -13
  73. data/lib/zm/client/identity/identity.rb +9 -7
  74. data/lib/zm/client/message/message.rb +111 -21
  75. data/lib/zm/client/message/messages_builder.rb +1 -1
  76. data/lib/zm/client/message/messages_collection.rb +10 -92
  77. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  78. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  79. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  80. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  81. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  82. data/lib/zm/client/mountpoint.rb +2 -0
  83. data/lib/zm/client/resource/resource.rb +5 -5
  84. data/lib/zm/client/resource/resources_builder.rb +1 -16
  85. data/lib/zm/client/resource/resources_collection.rb +5 -13
  86. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  87. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  88. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  89. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  90. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  91. data/lib/zm/client/search_folder.rb +2 -0
  92. data/lib/zm/client/server/server.rb +7 -14
  93. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  94. data/lib/zm/client/server/servers_builder.rb +4 -16
  95. data/lib/zm/client/server/servers_collection.rb +5 -10
  96. data/lib/zm/client/server.rb +1 -0
  97. data/lib/zm/client/share/share.rb +2 -9
  98. data/lib/zm/client/share/shares_builder.rb +3 -12
  99. data/lib/zm/client/signature/signature.rb +17 -13
  100. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  101. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  102. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  103. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  104. data/lib/zm/client/signature.rb +1 -0
  105. data/lib/zm/client/tag/tag.rb +27 -20
  106. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  107. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  108. data/lib/zm/client/tag/tags_builder.rb +6 -9
  109. data/lib/zm/client/tag/tags_collection.rb +6 -12
  110. data/lib/zm/client/tag.rb +2 -0
  111. data/lib/zm/client/task/tasks_collection.rb +6 -90
  112. data/lib/zm/client/upload/upload.rb +1 -1
  113. data/lib/zm/client/version.rb +2 -2
  114. data/lib/zm/modules/common/dl_common.rb +6 -1
  115. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  116. data/lib/zm/modules/zm_logger.rb +24 -0
  117. data/lib/zm/modules/zm_model.rb +41 -0
  118. data/test/accounts.rb +15 -1
  119. data/test/ace.rb +50 -0
  120. data/test/cluster.rb +41 -0
  121. data/test/cluster_zimbra_attributes.rb +38 -0
  122. data/test/domains.rb +8 -0
  123. data/test/folder.rb +125 -0
  124. data/test/folder_grant.rb +51 -0
  125. data/test/mountpoint.rb +49 -0
  126. data/test/retention_policies.rb +40 -0
  127. data/test/search_folder.rb +67 -0
  128. data/test/signature.rb +53 -0
  129. data/test/tag.rb +65 -0
  130. data/test/zimbra_attributes.rb +35 -0
  131. data/zm-ruby-client.gemspec +1 -0
  132. metadata +60 -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,22 +59,31 @@ 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
77
+ end
78
+
79
+ def token_metadata
80
+ @token_metadata ||= TokenMetaData.new(@soap_admin_connector.token)
55
81
  end
56
82
 
57
83
  def license
58
84
  @license ||= LicensesCollection.new(self).find
59
85
  rescue Zm::Client::SoapError => e
60
- puts e.message
86
+ logger.error "Get License info #{e.message}"
61
87
  nil
62
88
  end
63
89
 
@@ -107,10 +133,24 @@ module Zm
107
133
  !num.zero?
108
134
  end
109
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
+
110
150
  private
111
151
 
112
152
  def find_domain_key(domain_name)
113
- domains.find_by({ name: domain_name }, 'zimbraPreAuthKey').zimbraPreAuthKey
153
+ domains.attrs('zimbraPreAuthKey').find_by(name: domain_name).zimbraPreAuthKey
114
154
  end
115
155
  end
116
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
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ class TokenMetaDataError < StandardError; end
6
+
7
+ class TokenMetaData
8
+ def initialize(token)
9
+ raise TokenMetaDataError, 'no such token' unless token.is_a?(String)
10
+
11
+ parts = token.split('_')
12
+ raise TokenMetaDataError, 'invalid token' unless parts.length == 3
13
+
14
+ @key_id = parts[0]
15
+ @hmac = parts[1]
16
+ @encoded = parts[2]
17
+ end
18
+
19
+ def decoded
20
+ @decoded ||= [@encoded].pack('H*')
21
+ end
22
+
23
+ def metadatas
24
+ @metadatas ||= Hash[decoded.split(';').map { |v| key, len, str = v.split(/[:=]/); [key, str] }].freeze
25
+ end
26
+
27
+ def zimbra_id
28
+ metadatas['id']
29
+ end
30
+
31
+ def is_admin?
32
+ @is_admin ||= metadatas['admin'] == '1'
33
+ end
34
+
35
+ def server_version
36
+ metadatas['version']
37
+ end
38
+
39
+ def expire_at
40
+ @expire_at ||= Time.at(metadatas['exp'].to_f / 1000).freeze
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zm/client/common/recipients'
4
- require 'zm/client/common/message'
4
+ require 'zm/client/common/message'
5
+ require 'zm/client/common/token_metadata'
@@ -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,6 +11,7 @@ module Zm
11
11
  module Client
12
12
  class SoapAccountConnector < SoapBaseConnector
13
13
 
14
+ # SOAP_PATH = '/service/soap/'
14
15
  MAILSPACE = 'urn:zimbraMail'
15
16
  ACCOUNTSPACE = 'urn:zimbraAccount'
16
17
  A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
@@ -18,8 +19,7 @@ module Zm
18
19
  A_NODE_PROC_ARROW_NAME = lambda { |n| { :@name => n.first, content!: n.last } }
19
20
 
20
21
  def initialize(scheme, host, port)
21
- @uri = URI::HTTP.new(scheme, nil, host, port, nil, '/service/soap/', nil, nil, nil)
22
- init_curl_client
22
+ super(scheme, host, port, '/service/soap/')
23
23
  end
24
24
 
25
25
  def auth_template(mail)
@@ -173,75 +173,41 @@ module Zm
173
173
  # -------------------------------
174
174
  # FOLDER
175
175
 
176
- def get_folder(token, id)
177
- soap_name = :GetFolderRequest
178
- body = init_hash_request(token, soap_name)
179
- req = { folder: { l: id } }
180
- body[:Body][soap_name].merge!(req)
181
- curl_request(body)
176
+ def get_folder(token, jsns)
177
+ jsns_request(:GetFolderRequest, token, jsns)
182
178
  end
183
179
 
184
- def get_all_folders(token, view = nil, tr = nil)
185
- soap_name = :GetFolderRequest
186
- body = init_hash_request(token, soap_name)
187
- req = { view: view, tr: tr }.reject { |_, v| v.nil? }
188
- body[:Body][soap_name].merge!(req)
189
- curl_request(body)
190
- 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
191
187
 
192
- def create_folder(token, folder_options)
193
- soap_name = :CreateFolderRequest
194
- # folder = { l: parent_id, name: name, view: view, color: color }.merge(options)
195
- req = { folder: folder_options }
196
- body = init_hash_request(token, soap_name)
197
- body[:Body][soap_name].merge!(req)
198
- curl_request(body)
188
+ def create_folder(token, jsns)
189
+ jsns_request(:CreateFolderRequest, token, jsns)
199
190
  end
200
191
 
201
- def folder_action(token, op, id, options = {})
202
- soap_name = :FolderActionRequest
203
- action = { op: op, id: id }.merge(options)
204
- req = { action: action }
205
- body = init_hash_request(token, soap_name)
206
- body[:Body][soap_name].merge!(req)
207
- curl_request(body)
192
+ def folder_action(token, jsns)
193
+ jsns_request(:FolderActionRequest, token, jsns)
208
194
  end
209
195
 
210
196
  def get_all_search_folders(token)
211
- body = init_hash_request(token, :GetSearchFolderRequest)
197
+ soap_name = :GetSearchFolderRequest
198
+ body = init_hash_request(token, soap_name)
212
199
  curl_request(body)
213
200
  end
214
201
 
215
202
  # -------------------------------
216
203
  # SEARCH FOLDER
217
204
 
218
- def create_search_folder(token, name, query, types = 'messages', l = 1, color = nil, sort_by = nil)
219
- search = {
220
- name: name,
221
- query: query,
222
- types: types,
223
- sortBy: sort_by,
224
- color: color,
225
- l: l
226
- }.reject { |_, v| v.nil? }
227
-
228
- req = { search: search }
229
- body = init_hash_request(token, :CreateSearchFolderRequest)
230
- body[:Body][:CreateSearchFolderRequest].merge!(req)
231
- curl_request(body)
205
+ def create_search_folder(token, jsns)
206
+ jsns_request(:CreateSearchFolderRequest, token, jsns)
232
207
  end
233
208
 
234
- def modify_search_folder(token, id, query, types = 'messages')
235
- search = {
236
- id: id,
237
- query: query,
238
- types: types
239
- }.reject { |_, v| v.nil? }
240
-
241
- req = { search: search }
242
- body = init_hash_request(token, :ModifySearchFolderRequest)
243
- body[:Body][:ModifySearchFolderRequest].merge!(req)
244
- curl_request(body)
209
+ def modify_search_folder(token, jsns)
210
+ jsns_request(:ModifySearchFolderRequest, token, jsns)
245
211
  end
246
212
 
247
213
  # -------------------------------
@@ -265,12 +231,8 @@ module Zm
265
231
  # -------------------------------
266
232
  # SHARE
267
233
 
268
- def create_mountpoint(token, link_option)
269
- soap_name = :CreateMountpointRequest
270
- req = { link: link_option }
271
- body = init_hash_request(token, soap_name)
272
- body[:Body][soap_name].merge!(req)
273
- curl_request(body)
234
+ def create_mountpoint(token, jsns)
235
+ jsns_request(:CreateMountpointRequest, token, jsns)
274
236
  end
275
237
 
276
238
  def get_share_info(token, options = {})
@@ -281,49 +243,16 @@ module Zm
281
243
  curl_request(body)
282
244
  end
283
245
 
284
- def get_rights(token, rights)
285
- soap_name = :GetRightsRequest
286
- ace = rights.map { |r| { right: r } }
287
- req = { ace: ace }
288
- body = init_hash_request(token, soap_name, ACCOUNTSPACE)
289
- body[:Body][soap_name].merge!(req)
290
- curl_request(body)
246
+ def get_rights(token, jsns)
247
+ jsns_request(:GetRightsRequest, token, jsns, ACCOUNTSPACE)
291
248
  end
292
249
 
293
- def grant_rights(token, zid = nil, gt = nil, right = nil, d = nil, key = nil, pw = nil, deny = nil, chkgt = nil)
294
- ace = {
295
- zid: zid,
296
- gt: gt,
297
- right: right,
298
- d: d,
299
- key: key,
300
- pw: pw,
301
- deny: deny,
302
- chkgt: chkgt
303
- }.reject { |_, v| v.nil? }
304
-
305
- req = { ace: ace }
306
- body = init_hash_request(token, :GrantRightsRequest, ACCOUNTSPACE)
307
- body[:Body][:GrantRightsRequest].merge!(req)
308
- curl_request(body)
250
+ def grant_rights(token, jsns)
251
+ jsns_request(:GrantRightsRequest, token, jsns, ACCOUNTSPACE)
309
252
  end
310
253
 
311
- def revoke_rights(token, zid = nil, gt = nil, right = nil, d = nil, key = nil, pw = nil, deny = nil, chkgt = nil)
312
- ace = {
313
- zid: zid,
314
- gt: gt,
315
- right: right,
316
- d: d,
317
- key: key,
318
- pw: pw,
319
- deny: deny,
320
- chkgt: chkgt
321
- }.reject { |_, v| v.nil? }
322
-
323
- req = { ace: ace }
324
- body = init_hash_request(token, :RevokeRightsRequest, ACCOUNTSPACE)
325
- body[:Body][:RevokeRightsRequest].merge!(req)
326
- curl_request(body)
254
+ def revoke_rights(token, jsns)
255
+ jsns_request(:RevokeRightsRequest, token, jsns, ACCOUNTSPACE)
327
256
  end
328
257
 
329
258
  # -------------------------------
@@ -331,7 +260,7 @@ module Zm
331
260
 
332
261
  def get_msg(token, id, options = {})
333
262
  req = { m: { id: id } }
334
- req[:m].merge(options) unless options.empty?
263
+ req[:m].merge!(options) unless options.empty?
335
264
  body = init_hash_request(token, :GetMsgRequest)
336
265
  body[:Body][:GetMsgRequest].merge!(req)
337
266
  curl_request(body)
@@ -349,7 +278,7 @@ module Zm
349
278
  req = { m: m }
350
279
  body = init_hash_request(token, :SendMsgRequest)
351
280
  body[:Body][:SendMsgRequest].merge!(req)
352
- curl_request(body)
281
+ # curl_request(body)
353
282
  end
354
283
 
355
284
  def add_msg(token, l, eml, d = nil, f = nil, tn = nil)
@@ -377,19 +306,12 @@ module Zm
377
306
  curl_request(body)
378
307
  end
379
308
 
380
- def create_tag(token, name, color, rgb)
381
- body = init_hash_request(token, :CreateTagRequest)
382
- req = { tag: { name: name, color: color, rgb: rgb }.reject { |_, v| v.nil? } }
383
- body[:Body][:CreateTagRequest].merge!(req)
384
- curl_request(body)
309
+ def create_tag(token, jsns)
310
+ jsns_request(:CreateTagRequest, token, jsns)
385
311
  end
386
312
 
387
- def tag_action(token, op, id, options = {})
388
- action = { op: op, id: id }.merge(options)
389
- req = { action: action }
390
- body = init_hash_request(token, :TagActionRequest)
391
- body[:Body][:TagActionRequest].merge!(req)
392
- curl_request(body)
313
+ def tag_action(token, jsns)
314
+ jsns_request(:TagActionRequest, token, jsns)
393
315
  end
394
316
 
395
317
  # -------------------------------
@@ -486,18 +408,17 @@ module Zm
486
408
  curl_request(body)
487
409
  end
488
410
 
489
- def delete_signature(token, id)
411
+ def delete_signature(token, jsns)
490
412
  soap_name = :DeleteSignatureRequest
491
- req = { signature: { id: id } }
492
413
  body = init_hash_request(token, soap_name, ACCOUNTSPACE)
493
- body[:Body][soap_name].merge!(req)
414
+ body[:Body][soap_name].merge!(jsns)
494
415
  curl_request(body)
495
416
  end
496
417
 
497
418
  # -------------------------------
498
419
  # GENERIC
499
420
 
500
- 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)
501
422
  req = { rights: rights, sections: sections }.reject { |_, v| v.nil? }
502
423
  body = init_hash_request(token, :GetInfoRequest, ACCOUNTSPACE)
503
424
  body[:Body][:GetInfoRequest].merge!(req) if req.any?
@@ -512,7 +433,8 @@ module Zm
512
433
  offset: offset,
513
434
  limit: limit,
514
435
  sortBy: sortBy,
515
- query: query
436
+ query: query,
437
+ header: [{ n: 'messageIdHeader' }]
516
438
  }.merge!(options)
517
439
  req.reject! { |_, v| v.nil? }
518
440
 
@@ -521,6 +443,28 @@ module Zm
521
443
  curl_request(body)
522
444
  end
523
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
+
524
468
  private
525
469
 
526
470
  def compute_preauth(mail, ts, domainkey)
@@ -530,15 +474,15 @@ module Zm
530
474
  hmac.to_s
531
475
  end
532
476
 
533
- def init_hash_request(token, soap_name, jsns = MAILSPACE)
477
+ def init_hash_request(token, soap_name, namespace = MAILSPACE)
534
478
  {
535
479
  Body: {
536
- soap_name => { _jsns: jsns }
480
+ soap_name => { _jsns: namespace }
537
481
  }
538
482
  }.merge(hash_header(token))
539
483
  end
540
484
 
541
- def init_hash_arrow_request(token, soap_name, jsns = MAILSPACE)
485
+ def init_hash_arrow_request(token, soap_name, namespace = MAILSPACE)
542
486
  { Envelope: {
543
487
  :@xmlns => 'http://schemas.xmlsoap.org/soap/envelope/',
544
488
  '@xmlns:urn' => 'urn:zimbra',
@@ -552,7 +496,7 @@ module Zm
552
496
  }
553
497
  },
554
498
  Body: {
555
- soap_name => { :@xmlns => jsns }
499
+ soap_name => { :@xmlns => namespace }
556
500
  }
557
501
  }
558
502
  }