zm-ruby-client 0.10.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2179dff314053e41480d35e8dc012dc64509f4f51939682daf89fe96a3ed9bf3
4
- data.tar.gz: 9b27f7a2c40226ba8691cd19afa8647a86fb3596a5b6a724a693637ccbc760f9
3
+ metadata.gz: 495fd8546a12d2a1fe034da87a2db380ea307cbbad2caf5f676bc88b2f8711be
4
+ data.tar.gz: cf02068191fca2875bb65c3d63e462db89f2819984be18b05f29b76a8a2070f9
5
5
  SHA512:
6
- metadata.gz: 364b6e0e612a76caf9350129e0adf852a5ad7847c7d79d306bbaa53a289802462d3324a862ff827c5087150ade21236d0bd287d8ad92844da0c46a149ce13904
7
- data.tar.gz: c49afd819b6a5bd34fa1e9bc0f2a9fe6705c2d41389174c83a2f1e5bcdc97f0a48d2af5b02cb1e0f771ed363b8d9c2dca13475fbc45f8726f6a35fe6cad11dc6
6
+ metadata.gz: 90a577b5df0dd69cbf9a5ef8d39f30765a17a7bed17b7e624b3ac007f172fbfca76b6e1d175e17ff2ae1baa081755bff2ac58cd2e8b463d14921ec196fa0f2c8
7
+ data.tar.gz: 350398aeff49637ae3d6c203f2ed73ae7f5dfa3cb2cf296e75913f20037a18f6132c1083786e5dccb5d83fd519d98e01374819b1262e9baf1d3ffb5456a2213e
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'zm/modules/common/account_common'
4
4
  # require_relative '../../modules/common/account_galsync'
5
+ require 'zm/client/common'
5
6
  require 'zm/client/connector/rest_account'
6
7
  require 'zm/client/signature'
7
8
  require 'zm/client/folder'
@@ -93,6 +94,10 @@ module Zm
93
94
  @token = sac.delegate_auth(@name)
94
95
  end
95
96
 
97
+ def token_metadata
98
+ @token_metadata ||= TokenMetaData.new(@token)
99
+ end
100
+
96
101
  def domain_name
97
102
  @name.split('@').last
98
103
  end
@@ -213,6 +218,11 @@ module Zm
213
218
  sac.delete_account(@id)
214
219
  end
215
220
 
221
+ def password!(new_password)
222
+ sac.set_password(@id, new_password)
223
+ @password = new_password
224
+ end
225
+
216
226
  def update!(hash)
217
227
  sac.modify_account(@id, hash)
218
228
 
@@ -54,6 +54,10 @@ module Zm
54
54
  )
55
55
  end
56
56
 
57
+ def token_metadata
58
+ @token_metadata ||= TokenMetaData.new(@soap_admin_connector.token)
59
+ end
60
+
57
61
  def license
58
62
  @license ||= LicensesCollection.new(self).find
59
63
  rescue Zm::Client::SoapError => e
@@ -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'
@@ -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,7 +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
+ @uri = URI::HTTP.new(scheme, nil, host, port, nil, SOAP_PATH, nil, nil, nil)
22
23
  init_curl_client
23
24
  end
24
25
 
@@ -8,6 +8,7 @@ module Zm
8
8
  module Client
9
9
  class SoapAdminConnector < SoapBaseConnector
10
10
 
11
+ SOAP_PATH = '/service/admin/soap/'
11
12
  ADMINSPACE = 'urn:zimbraAdmin'
12
13
  A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
13
14
 
@@ -15,7 +16,7 @@ module Zm
15
16
 
16
17
  def initialize(scheme, host, port)
17
18
  @verbose = false
18
- @uri = URI::HTTP.new(scheme, nil, host, port, nil, '/service/admin/soap/', nil, nil, nil)
19
+ @uri = URI::HTTP.new(scheme, nil, host, port, nil, SOAP_PATH, nil, nil, nil)
19
20
  init_curl_client
20
21
  end
21
22
 
@@ -214,6 +215,14 @@ module Zm
214
215
  curl_request(body)
215
216
  end
216
217
 
218
+ def set_password(id, new_password)
219
+ soap_name = :SetPasswordRequest
220
+ req = { id: id, newPassword: new_password }
221
+ body = init_hash_request(soap_name)
222
+ body[:Body][soap_name].merge!(req)
223
+ curl_request(body)
224
+ end
225
+
217
226
  def add_account_alias(id, email)
218
227
  generic_alias(:AddAccountAliasRequest, id, email)
219
228
  end
@@ -279,6 +288,17 @@ module Zm
279
288
  curl_request(body)
280
289
  end
281
290
 
291
+ def create_domain(name, attrs = [])
292
+ soap_name = :CreateDomainRequest
293
+ req = {
294
+ name: name,
295
+ a: attrs.map(&A_NODE_PROC)
296
+ }
297
+ body = init_hash_request(soap_name)
298
+ body[:Body][soap_name].merge!(req)
299
+ curl_request(body)
300
+ end
301
+
282
302
  def modify_domain(id, attrs = [])
283
303
  generic_modify(:ModifyDomainRequest, id, attrs)
284
304
  end
@@ -31,6 +31,10 @@ module Zm
31
31
  @parent.sacc.item_action(@parent.token, :tag, @id, tn: tag_name)
32
32
  end
33
33
 
34
+ def delete!
35
+ @parent.sacc.item_action(@parent.token, :delete, @id)
36
+ end
37
+
34
38
  def download(dest_file_path)
35
39
  uploader = Upload.new(@parent, RestAccountConnector.new)
36
40
  uploader.download_file(folder.absFolderPath, nil, nil, [id], dest_file_path)
@@ -6,7 +6,7 @@ module Zm
6
6
  class Domain < Base::AdminObject
7
7
  INSTANCE_VARIABLE_KEYS = %i[name description zimbraDomainName zimbraDomainStatus zimbraId zimbraDomainType
8
8
  zimbraDomainDefaultCOSId zimbraGalAccountId zimbraPreAuthKey zimbraGalLdapBindDn zimbraGalLdapBindPassword
9
- zimbraGalLdapFilter zimbraGalLdapSearchBase zimbraGalLdapURL zimbraGalMode]
9
+ zimbraGalLdapFilter zimbraGalLdapSearchBase zimbraGalLdapURL zimbraGalMode zimbraMailTransport]
10
10
 
11
11
  attr_accessor *INSTANCE_VARIABLE_KEYS
12
12
 
@@ -25,6 +25,17 @@ module Zm
25
25
  INSTANCE_VARIABLE_KEYS
26
26
  end
27
27
 
28
+ def create!
29
+ attrs_write = INSTANCE_VARIABLE_KEYS.dup
30
+ attrs_write.delete(:name)
31
+
32
+ rep = sac.create_domain(
33
+ @name,
34
+ instance_variables_array(attrs_write)
35
+ )
36
+ @id = rep[:Body][:CreateDomainResponse][:domain].first[:id]
37
+ end
38
+
28
39
  def update!(hash)
29
40
  sac.modify_domain(@id, hash)
30
41
 
@@ -46,6 +46,31 @@ module Zm
46
46
  reset_query_params
47
47
  end
48
48
 
49
+ def document
50
+ @view = FolderDefault::BRIEFCASE[:type]
51
+ self
52
+ end
53
+
54
+ def appointment
55
+ @view = FolderDefault::CALENDAR[:type]
56
+ self
57
+ end
58
+
59
+ def contact
60
+ @view = FolderDefault::CONTACTS[:type]
61
+ self
62
+ end
63
+
64
+ def message
65
+ @view = FolderDefault::INBOX[:type]
66
+ self
67
+ end
68
+
69
+ def task
70
+ @view = FolderDefault::TASKS[:type]
71
+ self
72
+ end
73
+
49
74
  private
50
75
 
51
76
  def build_response
@@ -8,12 +8,12 @@ module Zm
8
8
  INSTANCE_VARIABLE_KEYS = %i[id name zimbraPrefIdentityName zimbraPrefFromDisplay zimbraPrefFromAddress
9
9
  zimbraPrefFromAddressType zimbraPrefReplyToEnabled zimbraPrefReplyToDisplay zimbraPrefReplyToAddress
10
10
  zimbraPrefDefaultSignatureId zimbraPrefForwardReplySignatureId zimbraPrefWhenSentToEnabled
11
- zimbraPrefWhenInFoldersEnabled]
11
+ zimbraPrefWhenInFoldersEnabled zimbraPrefWhenSentToAddresses]
12
12
 
13
13
  ATTRS_WRITE = %i[zimbraPrefIdentityName zimbraPrefFromDisplay zimbraPrefFromAddress
14
14
  zimbraPrefFromAddressType zimbraPrefReplyToEnabled zimbraPrefReplyToDisplay zimbraPrefReplyToAddress
15
15
  zimbraPrefDefaultSignatureId zimbraPrefForwardReplySignatureId zimbraPrefWhenSentToEnabled
16
- zimbraPrefWhenInFoldersEnabled]
16
+ zimbraPrefWhenInFoldersEnabled zimbraPrefWhenSentToAddresses]
17
17
 
18
18
  attr_accessor *INSTANCE_VARIABLE_KEYS
19
19
 
@@ -9,8 +9,8 @@ module Zm
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 0
12
- MINOR = 10
13
- TINY = 4
12
+ MINOR = 14
13
+ TINY = 0
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
16
16
  end
@@ -7,6 +7,8 @@ module DistributionListCommon
7
7
  cn
8
8
  zimbraMailForwardingAddress
9
9
  description
10
+ zimbraDistributionListSendShareMessageToNewMembers
11
+ zimbraNotes
10
12
  ].freeze
11
13
 
12
14
  ATTRS_READ = %w[zimbraMailAlias]
@@ -18,6 +20,7 @@ module DistributionListCommon
18
20
  zimbraMailTransport
19
21
  zimbraMailForwardingAddress
20
22
  description
23
+ zimbraDistributionListSendShareMessageToNewMembers
21
24
  ].freeze
22
25
 
23
26
  ATTRS_READ.each { |attr| attr_reader attr }
data/test/domains.rb CHANGED
@@ -59,4 +59,12 @@ class TestDomain < Minitest::Test
59
59
  assert domain.name == name
60
60
  end
61
61
 
62
+ def test_create_domain
63
+ name = @fixture_domains['domains']['toto']['name']
64
+ domain = @admin.domains.new do |acc|
65
+ acc.name = name
66
+ end
67
+ domain.save!
68
+ assert !domain.id.nil?
69
+ end
62
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zm-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Désécot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-22 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -111,6 +111,7 @@ files:
111
111
  - lib/zm/client/common.rb
112
112
  - lib/zm/client/common/message.rb
113
113
  - lib/zm/client/common/recipients.rb
114
+ - lib/zm/client/common/token_metadata.rb
114
115
  - lib/zm/client/config.rb
115
116
  - lib/zm/client/connector/rest_account.rb
116
117
  - lib/zm/client/connector/soap_account.rb