zm-ruby-client 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +58 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +674 -0
  5. data/README.md +47 -0
  6. data/SECURITY.md +21 -0
  7. data/lib/zm/client/account/account.rb +335 -0
  8. data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
  9. data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
  10. data/lib/zm/client/account/accounts_builder.rb +19 -0
  11. data/lib/zm/client/account/accounts_collection.rb +48 -0
  12. data/lib/zm/client/account.rb +7 -0
  13. data/lib/zm/client/ace/ace.rb +32 -0
  14. data/lib/zm/client/ace/aces_builder.rb +25 -0
  15. data/lib/zm/client/ace/aces_collection.rb +36 -0
  16. data/lib/zm/client/ace.rb +5 -0
  17. data/lib/zm/client/appointment/appointment.rb +143 -0
  18. data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
  19. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
  20. data/lib/zm/client/appointment/appointments_builder.rb +33 -0
  21. data/lib/zm/client/appointment/appointments_collection.rb +106 -0
  22. data/lib/zm/client/appointment.rb +7 -0
  23. data/lib/zm/client/backup/backup.rb +59 -0
  24. data/lib/zm/client/backup/backups_builder.rb +26 -0
  25. data/lib/zm/client/backup/backups_collection.rb +22 -0
  26. data/lib/zm/client/backup.rb +5 -0
  27. data/lib/zm/client/base/account_object.rb +17 -0
  28. data/lib/zm/client/base/admin_object.rb +45 -0
  29. data/lib/zm/client/base/object.rb +80 -0
  30. data/lib/zm/client/base/objects_builder.rb +31 -0
  31. data/lib/zm/client/base/objects_collection.rb +135 -0
  32. data/lib/zm/client/base.rb +7 -0
  33. data/lib/zm/client/cluster/cluster.rb +117 -0
  34. data/lib/zm/client/cluster/cluster_config.rb +100 -0
  35. data/lib/zm/client/cluster.rb +4 -0
  36. data/lib/zm/client/common/message.rb +10 -0
  37. data/lib/zm/client/common/recipients.rb +67 -0
  38. data/lib/zm/client/common.rb +4 -0
  39. data/lib/zm/client/config.rb +12 -0
  40. data/lib/zm/client/connector/rest_account.rb +74 -0
  41. data/lib/zm/client/connector/soap_account.rb +562 -0
  42. data/lib/zm/client/connector/soap_admin.rb +512 -0
  43. data/lib/zm/client/connector/soap_base.rb +65 -0
  44. data/lib/zm/client/connector/soap_error.rb +26 -0
  45. data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
  46. data/lib/zm/client/constant.rb +217 -0
  47. data/lib/zm/client/contact/contact.rb +124 -0
  48. data/lib/zm/client/contact/contact_member.rb +73 -0
  49. data/lib/zm/client/contact/contacts_builder.rb +24 -0
  50. data/lib/zm/client/contact/contacts_collection.rb +26 -0
  51. data/lib/zm/client/contact/mod_group_contact.rb +74 -0
  52. data/lib/zm/client/contact.rb +7 -0
  53. data/lib/zm/client/cos/cos.rb +59 -0
  54. data/lib/zm/client/cos/coses_builder.rb +29 -0
  55. data/lib/zm/client/cos/coses_collection.rb +33 -0
  56. data/lib/zm/client/cos.rb +5 -0
  57. data/lib/zm/client/data_source.rb +5 -0
  58. data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
  59. data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
  60. data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
  61. data/lib/zm/client/distributionlist.rb +5 -0
  62. data/lib/zm/client/document/document.rb +47 -0
  63. data/lib/zm/client/document/documents_builder.rb +31 -0
  64. data/lib/zm/client/document/documents_collection.rb +93 -0
  65. data/lib/zm/client/document.rb +5 -0
  66. data/lib/zm/client/domain/domain.rb +74 -0
  67. data/lib/zm/client/domain/domains_builder.rb +32 -0
  68. data/lib/zm/client/domain/domains_collection.rb +36 -0
  69. data/lib/zm/client/domain.rb +5 -0
  70. data/lib/zm/client/folder/folder.rb +215 -0
  71. data/lib/zm/client/folder/folder_grant.rb +58 -0
  72. data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
  73. data/lib/zm/client/folder/folders_builder.rb +58 -0
  74. data/lib/zm/client/folder/folders_collection.rb +70 -0
  75. data/lib/zm/client/folder/mod_document_folder.rb +17 -0
  76. data/lib/zm/client/folder.rb +8 -0
  77. data/lib/zm/client/identity/identities_builder.rb +25 -0
  78. data/lib/zm/client/identity/identities_collection.rb +26 -0
  79. data/lib/zm/client/identity/identity.rb +75 -0
  80. data/lib/zm/client/identity.rb +5 -0
  81. data/lib/zm/client/license/license.rb +29 -0
  82. data/lib/zm/client/license/licenses_collection.rb +28 -0
  83. data/lib/zm/client/license.rb +4 -0
  84. data/lib/zm/client/message/message.rb +225 -0
  85. data/lib/zm/client/message/messages_builder.rb +31 -0
  86. data/lib/zm/client/message/messages_collection.rb +111 -0
  87. data/lib/zm/client/message.rb +5 -0
  88. data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
  89. data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
  90. data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
  91. data/lib/zm/client/mountpoint.rb +5 -0
  92. data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
  93. data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
  94. data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
  95. data/lib/zm/client/mta_queue.rb +5 -0
  96. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
  97. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
  98. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
  99. data/lib/zm/client/mta_queue_item.rb +5 -0
  100. data/lib/zm/client/resource/resource.rb +149 -0
  101. data/lib/zm/client/resource/resources_builder.rb +29 -0
  102. data/lib/zm/client/resource/resources_collection.rb +41 -0
  103. data/lib/zm/client/resource.rb +5 -0
  104. data/lib/zm/client/search_folder/search_folder.rb +63 -0
  105. data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
  106. data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
  107. data/lib/zm/client/search_folder.rb +5 -0
  108. data/lib/zm/client/server/server.rb +516 -0
  109. data/lib/zm/client/server/servers_builder.rb +26 -0
  110. data/lib/zm/client/server/servers_collection.rb +37 -0
  111. data/lib/zm/client/server.rb +5 -0
  112. data/lib/zm/client/share/share.rb +60 -0
  113. data/lib/zm/client/share/shares_builder.rb +23 -0
  114. data/lib/zm/client/share/shares_collection.rb +48 -0
  115. data/lib/zm/client/share.rb +5 -0
  116. data/lib/zm/client/signature/signature.rb +62 -0
  117. data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
  118. data/lib/zm/client/signature/signatures_builder.rb +26 -0
  119. data/lib/zm/client/signature/signatures_collection.rb +28 -0
  120. data/lib/zm/client/signature.rb +6 -0
  121. data/lib/zm/client/tag/tag.rb +45 -0
  122. data/lib/zm/client/tag/tags_builder.rb +25 -0
  123. data/lib/zm/client/tag/tags_collection.rb +26 -0
  124. data/lib/zm/client/tag.rb +5 -0
  125. data/lib/zm/client/task/task.rb +74 -0
  126. data/lib/zm/client/task/tasks_builder.rb +31 -0
  127. data/lib/zm/client/task/tasks_collection.rb +100 -0
  128. data/lib/zm/client/task.rb +5 -0
  129. data/lib/zm/client/upload/upload.rb +154 -0
  130. data/lib/zm/client/upload.rb +3 -0
  131. data/lib/zm/client/version.rb +18 -0
  132. data/lib/zm/client.rb +5 -0
  133. data/lib/zm/modules/common/account_common.rb +71 -0
  134. data/lib/zm/modules/common/cos_common.rb +463 -0
  135. data/lib/zm/modules/common/dl_common.rb +33 -0
  136. data/lib/zm/modules/common/identity_common.rb +19 -0
  137. data/lib/zm/modules/common/resource_common.rb +59 -0
  138. data/lib/zm/modules/common/signature_common.rb +16 -0
  139. data/lib/zm/modules/common/zimbra-attrs.json +1 -0
  140. data/lib/zm/utils/thread_pool.rb +72 -0
  141. data/lib/zm-ruby-client.rb +1 -0
  142. data/test/accounts.rb +62 -0
  143. data/test/cluster_config.rb +30 -0
  144. data/test/coses.rb +26 -0
  145. data/test/domains.rb +62 -0
  146. data/zm-ruby-client.gemspec +24 -0
  147. metadata +243 -0
@@ -0,0 +1,562 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'soap_base'
4
+ require_relative 'soap_error'
5
+ require 'gyoku'
6
+
7
+ # include OpenSSL
8
+ # include Digest
9
+
10
+ module Zm
11
+ module Client
12
+ class SoapAccountConnector < SoapBaseConnector
13
+
14
+ MAILSPACE = 'urn:zimbraMail'
15
+ ACCOUNTSPACE = 'urn:zimbraAccount'
16
+ A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
17
+ A_NODE_PROC_NAME = lambda { |n| { name: n.first, _content: n.last } }
18
+ A_NODE_PROC_ARROW_NAME = lambda { |n| { :@name => n.first, content!: n.last } }
19
+
20
+ def initialize(scheme, host, port)
21
+ @uri = URI::HTTP.new(scheme, nil, host, port, nil, '/service/soap/', nil, nil, nil)
22
+ init_curl_client
23
+ end
24
+
25
+ def auth_template(mail)
26
+ {
27
+ Body: {
28
+ AuthRequest: {
29
+ _jsns: ACCOUNTSPACE,
30
+ account: {
31
+ _content: mail,
32
+ by: :name
33
+ }
34
+ }
35
+ }
36
+ }
37
+ end
38
+
39
+ def auth_preauth(mail, domainkey)
40
+ ts = (Time.now.to_i * 1000)
41
+ preauth = compute_preauth(mail, ts, domainkey)
42
+ body = auth_template(mail)
43
+ preauth_h = {
44
+ preauth: {
45
+ _content: preauth,
46
+ timestamp: ts
47
+ }
48
+ }
49
+ body[:Body][:AuthRequest].merge!(preauth_h)
50
+ do_auth(body)
51
+ end
52
+
53
+ def auth_password(mail, password)
54
+ body = auth_template(mail)
55
+ body[:Body][:AuthRequest].merge!({ password: password })
56
+ do_auth(body)
57
+ end
58
+
59
+ def do_auth(body)
60
+ res = curl_request(body, AuthError)
61
+ res[BODY][:AuthResponse][:authToken].first[:_content]
62
+ end
63
+
64
+ # -------------------------------
65
+ # APPOINTMENT
66
+
67
+ def get_appointment(token, id)
68
+ req = { id: id }
69
+ body = init_hash_request(token, :GetAppointmentRequest)
70
+ body[:Body][:GetAppointmentRequest].merge!(req)
71
+ curl_request(body)
72
+ end
73
+
74
+ def create_appointment(token, jsns)
75
+ soap_name = :CreateAppointmentRequest
76
+ body = init_hash_request(token, soap_name)
77
+ body[:Body][soap_name].merge!(jsns)
78
+ curl_request(body)
79
+ end
80
+
81
+ def modify_appointment(token, jsns)
82
+ soap_name = :ModifyAppointmentRequest
83
+ body = init_hash_request(token, soap_name)
84
+ body[:Body][soap_name].merge!(jsns)
85
+ curl_request(body)
86
+ end
87
+
88
+ def cancel_appointment(token, jsns)
89
+ soap_name = :CancelAppointmentRequest
90
+ body = init_hash_request(token, soap_name)
91
+ body[:Body][soap_name].merge!(jsns)
92
+ curl_request(body)
93
+ end
94
+
95
+ # -------------------------------
96
+ # CONTACT
97
+
98
+ def get_all_contacts(token, folder_id = nil)
99
+ body = init_hash_request(token, :GetContactsRequest)
100
+ unless folder_id.nil?
101
+ req = { l: folder_id }
102
+ body[:Body][:GetContactsRequest].merge!(req)
103
+ end
104
+ curl_request(body)
105
+ end
106
+
107
+ def create_contact(token, folder_id, attrs)
108
+ a = attrs.to_a.map(&A_NODE_PROC)
109
+ soap_name = :CreateContactRequest
110
+ req = { cn: { a: a, l: folder_id } }
111
+ body = init_hash_request(token, soap_name)
112
+ body[:Body][soap_name].merge!(req)
113
+ curl_request(body)
114
+ end
115
+
116
+ def modify_contact(token, id, attrs)
117
+ a = attrs.to_a.map(&A_NODE_PROC)
118
+ soap_name = :ModifyContactRequest
119
+ req = { cn: { a: a, id: id } }
120
+ body = init_hash_request(token, soap_name)
121
+ body[:Body][soap_name].merge!(req)
122
+ curl_request(body)
123
+ end
124
+
125
+ def create_group_contact(token, folder_id, attrs, members = [])
126
+ soap_name = :CreateContactRequest
127
+ a = attrs.to_a.map(&A_NODE_PROC)
128
+ req = { cn: { a: a, l: folder_id, m: members } }
129
+ body = init_hash_request(token, soap_name)
130
+ body[:Body][soap_name].merge!(req)
131
+ curl_request(body)
132
+ end
133
+
134
+ def modify_group_contact(token, id, attrs, members = [])
135
+ soap_name = :ModifyContactRequest
136
+ a = attrs.to_a.map(&A_NODE_PROC)
137
+ req = { cn: { a: a, id: id, m: members } }
138
+ body = init_hash_request(token, soap_name)
139
+ body[:Body][soap_name].merge!(req)
140
+ curl_request(body)
141
+ end
142
+
143
+ def contact_action(token, op, id, options = {})
144
+ soap_name = :ContactActionRequest
145
+ action = { op: op, id: id }.merge(options)
146
+ req = { action: action }
147
+ body = init_hash_request(token, soap_name)
148
+ body[:Body][soap_name].merge!(req)
149
+ curl_request(body)
150
+ end
151
+
152
+ # -------------------------------
153
+ # DOCUMENT
154
+
155
+ def save_document(token, l, options = {})
156
+ soap_name = :SaveDocumentRequest
157
+ body = init_hash_request(token, soap_name)
158
+ req = { doc: { l: l } }
159
+ req[:doc].merge!(options)
160
+ body[:Body][soap_name].merge!(req)
161
+ curl_request(body)
162
+ end
163
+
164
+ def item_action(token, op, id, options = {})
165
+ soap_name = :ItemActionRequest
166
+ action = { op: op, id: id }.merge(options)
167
+ req = { action: action }
168
+ body = init_hash_request(token, soap_name)
169
+ body[:Body][soap_name].merge!(req)
170
+ curl_request(body)
171
+ end
172
+
173
+ # -------------------------------
174
+ # FOLDER
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)
182
+ end
183
+
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
191
+
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)
199
+ end
200
+
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)
208
+ end
209
+
210
+ def get_all_search_folders(token)
211
+ body = init_hash_request(token, :GetSearchFolderRequest)
212
+ curl_request(body)
213
+ end
214
+
215
+ # -------------------------------
216
+ # SEARCH FOLDER
217
+
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)
232
+ end
233
+
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)
245
+ end
246
+
247
+ # -------------------------------
248
+ # TASK
249
+
250
+ def create_task(token, folder_id, name, description = nil, options = {})
251
+ comp = { name: name }
252
+ comp.merge!(options) if !options.nil? && !options.empty?
253
+
254
+ task = { su: name, l: folder_id, inv: { comp: [comp] } }
255
+
256
+ task[:mp] = { ct: 'text/plain', content: description } unless description.nil?
257
+
258
+ req = { m: task }
259
+
260
+ body = init_hash_request(token, :CreateTaskRequest)
261
+ body[:Body][:CreateTaskRequest].merge!(req)
262
+ curl_request(body)
263
+ end
264
+
265
+ # -------------------------------
266
+ # SHARE
267
+
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)
274
+ end
275
+
276
+ def get_share_info(token, options = {})
277
+ soap_name = :GetShareInfoRequest
278
+ req = { includeSelf: 0 }.merge!(options)
279
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
280
+ body[:Body][soap_name].merge!(req)
281
+ curl_request(body)
282
+ end
283
+
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)
291
+ end
292
+
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)
309
+ end
310
+
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)
327
+ end
328
+
329
+ # -------------------------------
330
+ # MESSAGE
331
+
332
+ def get_msg(token, id, options = {})
333
+ req = { m: { id: id } }
334
+ req[:m].merge(options) unless options.empty?
335
+ body = init_hash_request(token, :GetMsgRequest)
336
+ body[:Body][:GetMsgRequest].merge!(req)
337
+ curl_request(body)
338
+ end
339
+
340
+ def msg_action(token, op, id, options = {})
341
+ action = { op: op, id: id }.merge(options)
342
+ req = { action: action }
343
+ body = init_hash_request(token, :MsgActionRequest)
344
+ body[:Body][:MsgActionRequest].merge!(req)
345
+ curl_request(body)
346
+ end
347
+
348
+ def send_msg(token, m)
349
+ req = { m: m }
350
+ body = init_hash_request(token, :SendMsgRequest)
351
+ body[:Body][:SendMsgRequest].merge!(req)
352
+ curl_request(body)
353
+ end
354
+
355
+ def add_msg(token, l, eml, d = nil, f = nil, tn = nil)
356
+ key = :AddMsgRequest
357
+ m = {
358
+ l: l,
359
+ d: d,
360
+ f: f,
361
+ tn: tn,
362
+ content: { _content: eml }
363
+ }.reject { |_, v| v.nil? }
364
+
365
+ req = { m: m }
366
+ body = init_hash_request(token, key)
367
+ body[:Body][key].merge!(req)
368
+
369
+ curl_request(body)
370
+ end
371
+
372
+ # -------------------------------
373
+ # TAG
374
+
375
+ def get_tag(token)
376
+ body = init_hash_request(token, :GetTagRequest)
377
+ curl_request(body)
378
+ end
379
+
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)
385
+ end
386
+
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)
393
+ end
394
+
395
+ # -------------------------------
396
+ # IDENTITY
397
+
398
+ def get_all_identities(token)
399
+ body = init_hash_request(token, :GetIdentitiesRequest, ACCOUNTSPACE)
400
+ curl_request(body)
401
+ end
402
+
403
+ def create_identity(token, name, attrs = [])
404
+ soap_name = :CreateIdentityRequest
405
+ req = { identity: { :@name => name, a: attrs.to_a.map(&A_NODE_PROC_ARROW_NAME) } }
406
+ body = init_hash_arrow_request(token, soap_name, ACCOUNTSPACE)
407
+ body[:Envelope][:Body][soap_name].merge!(req)
408
+ body_xml = Gyoku.xml(body, { :key_converter => :none })
409
+ # puts body_xml
410
+ # todo ne fonctionne pas en JS !
411
+ curl_xml(body_xml)
412
+ end
413
+
414
+ def modify_identity(token, id, attrs = [])
415
+ soap_name = :ModifyIdentityRequest
416
+ req = { identity: { :@id => id, a: attrs.to_a.map(&A_NODE_PROC_ARROW_NAME) } }
417
+ body = init_hash_arrow_request(token, soap_name, ACCOUNTSPACE)
418
+ body[:Envelope][:Body][soap_name].merge!(req)
419
+ body_xml = Gyoku.xml(body, { :key_converter => :none })
420
+ # puts body_xml
421
+ # todo ne fonctionne pas en JS !
422
+ curl_xml(body_xml)
423
+ end
424
+
425
+ def delete_identity(token, id)
426
+ soap_name = :DeleteIdentityRequest
427
+ req = { identity: { id: id } }
428
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
429
+ body[:Body][soap_name].merge!(req)
430
+ curl_request(body)
431
+ end
432
+
433
+ # -------------------------------
434
+ # PREFERENCES
435
+
436
+ def get_prefs(token, *names)
437
+ req = { prefs: names.map { |name| { name: name } } }
438
+ body = init_hash_request(token, :GetPrefsRequest, ACCOUNTSPACE)
439
+ body[:Body][:GetPrefsRequest].merge!(req) if req.any?
440
+ curl_request(body)
441
+ end
442
+
443
+ def modify_prefs(token, prefs)
444
+ soap_name = :ModifyPrefsRequest
445
+ req = { pref: prefs.map { |pref, value| { name: pref, _content: value } } }
446
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
447
+ body[:Body][soap_name].merge!(req) if req.any?
448
+ #puts body
449
+ #curl_request(body)
450
+ #puts SoapXmlBuilder.new(body).to_xml
451
+ # todo ne fonctionne pas en JS !
452
+ curl_xml(SoapXmlBuilder.new(body).to_xml)
453
+ end
454
+
455
+ def get_filter_rules(token)
456
+ soap_name = :GetFilterRulesRequest
457
+ body = init_hash_request(token, soap_name)
458
+ curl_request(body)
459
+ end
460
+
461
+ def modify_filter_rules(token, rules)
462
+ soap_name = :ModifyFilterRulesRequest
463
+ req = { filterRules: [{ filterRule: rules }] }
464
+ body = init_hash_request(token, soap_name)
465
+ body[:Body][soap_name].merge!(req)
466
+ curl_request(body)
467
+ end
468
+
469
+ def get_signatures(token)
470
+ soap_name = :GetSignaturesRequest
471
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
472
+ curl_request(body)
473
+ end
474
+
475
+ def create_signature(token, jsns)
476
+ soap_name = :CreateSignatureRequest
477
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
478
+ body[:Body][soap_name].merge!(jsns)
479
+ curl_request(body)
480
+ end
481
+
482
+ def modify_signature(token, jsns)
483
+ soap_name = :ModifySignatureRequest
484
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
485
+ body[:Body][soap_name].merge!(jsns)
486
+ curl_request(body)
487
+ end
488
+
489
+ def delete_signature(token, id)
490
+ soap_name = :DeleteSignatureRequest
491
+ req = { signature: { id: id } }
492
+ body = init_hash_request(token, soap_name, ACCOUNTSPACE)
493
+ body[:Body][soap_name].merge!(req)
494
+ curl_request(body)
495
+ end
496
+
497
+ # -------------------------------
498
+ # GENERIC
499
+
500
+ def get_info(token, sections = 'mbox', rights = nil)
501
+ req = { rights: rights, sections: sections }.reject { |_, v| v.nil? }
502
+ body = init_hash_request(token, :GetInfoRequest, ACCOUNTSPACE)
503
+ body[:Body][:GetInfoRequest].merge!(req) if req.any?
504
+ curl_request(body)
505
+ end
506
+
507
+ def search(token, types = nil, offset = nil, limit = nil, sortBy = nil, query = nil, options = {})
508
+ soap_name = :SearchRequest
509
+ # types: conversation|message|contact|appointment|task|wiki|document
510
+ req = {
511
+ types: types,
512
+ offset: offset,
513
+ limit: limit,
514
+ sortBy: sortBy,
515
+ query: query
516
+ }.merge!(options)
517
+ req.reject! { |_, v| v.nil? }
518
+
519
+ body = init_hash_request(token, soap_name)
520
+ body[:Body][soap_name].merge!(req) if req.any?
521
+ curl_request(body)
522
+ end
523
+
524
+ private
525
+
526
+ def compute_preauth(mail, ts, domainkey)
527
+ data = "#{mail}|name|0|#{ts}"
528
+ digest = OpenSSL::Digest.new('sha1')
529
+ hmac = OpenSSL::HMAC.hexdigest(digest, domainkey, data)
530
+ hmac.to_s
531
+ end
532
+
533
+ def init_hash_request(token, soap_name, jsns = MAILSPACE)
534
+ {
535
+ Body: {
536
+ soap_name => { _jsns: jsns }
537
+ }
538
+ }.merge(hash_header(token))
539
+ end
540
+
541
+ def init_hash_arrow_request(token, soap_name, jsns = MAILSPACE)
542
+ { Envelope: {
543
+ :@xmlns => 'http://schemas.xmlsoap.org/soap/envelope/',
544
+ '@xmlns:urn' => 'urn:zimbra',
545
+ Header: {
546
+ context: {
547
+ authToken: token,
548
+ :@xmlns => BASESPACE,
549
+ format: {
550
+ :@type => 'js'
551
+ }
552
+ }
553
+ },
554
+ Body: {
555
+ soap_name => { :@xmlns => jsns }
556
+ }
557
+ }
558
+ }
559
+ end
560
+ end
561
+ end
562
+ end