Class: Zm::Client::Base::MailboxObject

Inherits:
Object
  • Object
show all
Includes:
HasSoapAdminConnector
Defined in:
lib/zm/client/base/mailbox_object.rb

Overview

Abstract Class for Account and Resource

Direct Known Subclasses

Account, Resource

Instance Attribute Summary collapse

Attributes inherited from Object

#id, #name, #parent

Instance Method Summary collapse

Methods included from HasSoapAdminConnector

#soap_admin_connector

Methods inherited from Object

#clone, #initialize, #inspect, #instance_variables_map, #logger, #recorded?, #save!, #to_h, #to_s, #update_attribute

Constructor Details

This class inherits a constructor from Zm::Client::Base::Object

Instance Attribute Details

#carLicenseObject

Returns the value of attribute carLicense.



29
30
31
# File 'lib/zm/client/base/mailbox_object.rb', line 29

def carLicense
  @carLicense
end

#domain_keyObject



131
132
133
134
135
# File 'lib/zm/client/base/mailbox_object.rb', line 131

def domain_key
  return @domain_key if defined?(@domain_key)

  @parent.domain_key(domain_name)
end

#home_urlObject

Returns the value of attribute home_url.



29
30
31
# File 'lib/zm/client/base/mailbox_object.rb', line 29

def home_url
  @home_url
end

#passwordObject

Returns the value of attribute password.



29
30
31
# File 'lib/zm/client/base/mailbox_object.rb', line 29

def password
  @password
end

#public_urlObject

Returns the value of attribute public_url.



29
30
31
# File 'lib/zm/client/base/mailbox_object.rb', line 29

def public_url
  @public_url
end

#usedObject



76
77
78
# File 'lib/zm/client/base/mailbox_object.rb', line 76

def used
  @used || used!
end

Instance Method Details

#account_content_byObject



173
174
175
# File 'lib/zm/client/base/mailbox_object.rb', line 173

def 
  @id ? [@id, :id] : [@name, :name]
end

#account_loginObject



145
146
147
148
149
150
151
152
153
# File 'lib/zm/client/base/mailbox_object.rb', line 145

def 
  .token = nil

  if password
    
  else
    
  end
end

#account_login_passwordObject

Raises:



164
165
166
167
168
169
170
171
# File 'lib/zm/client/base/mailbox_object.rb', line 164

def 
  logger.info 'Get Account session token by password access'
  raise ZmError, 'password is required to login !' if password.nil?

  content, by = 

  self.token = .auth_password(content, by, @password)
end

#account_login_preauth(expires = 0) ⇒ Object

Raises:



155
156
157
158
159
160
161
162
# File 'lib/zm/client/base/mailbox_object.rb', line 155

def (expires = 0)
  logger.info 'Get Account session token by preauth access'
  raise ZmError, 'domain key is required to login !' if domain_key.nil?

  content, by = 

  self.token = .auth_preauth(content, by, expires, domain_key)
end

#acesObject Also known as: rights



257
258
259
260
261
# File 'lib/zm/client/base/mailbox_object.rb', line 257

def aces
  return @aces if defined? @aces

  @aces = AcesCollection.new(self)
end

#admin_loginObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/zm/client/base/mailbox_object.rb', line 177

def 
  logger.info 'Get Account session token by Delegate access'

  soap_request = SoapElement.admin(SoapAdminConstants::DELEGATE_AUTH_REQUEST)
   = SoapElement.create(SoapConstants::)

  if recorded?
    .add_attribute(SoapConstants::BY, SoapConstants::ID).add_content(@id)
  else
    .add_attribute(SoapConstants::BY, SoapConstants::NAME).add_content(@name)
  end

  soap_request.add_node()
  self.token = sac.invoke(soap_request)[:DelegateAuthResponse][:authToken].first[:_content]
end

#alive?Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
125
# File 'lib/zm/client/base/mailbox_object.rb', line 118

def alive?
  soap_request = SoapElement.mail(SoapMailConstants::NO_OP_REQUEST)
  soap_connector.invoke(soap_request)
  true
rescue Zm::Client::SoapError => e
  logger.warn "Mailbox session token alive ? #{e.message}"
  false
end

#appointmentsObject



239
240
241
242
243
# File 'lib/zm/client/base/mailbox_object.rb', line 239

def appointments
  return @appointments if defined? @appointments

  @appointments = AppointmentsCollection.new(self)
end

#build_uploaderObject

#################################################################

Raises:



351
352
353
354
355
356
# File 'lib/zm/client/base/mailbox_object.rb', line 351

def build_uploader
  tmp_token = soap_connector&.token
  raise ZmError, 'token have to be set to instance Upload class' unless tmp_token

  Upload.new(rest_url, tmp_token, is_token_admin: soap_connector.is_a?(SoapAdminConnector), **rest_options)
end

#contactsObject



233
234
235
236
237
# File 'lib/zm/client/base/mailbox_object.rb', line 233

def contacts
  return @contacts if defined? @contacts

  @contacts = ContactsCollection.new(self)
end

#data_sourcesObject



300
301
302
303
304
# File 'lib/zm/client/base/mailbox_object.rb', line 300

def data_sources
  return @data_sources if defined? @data_sources

  @data_sources = DataSourcesCollection.new(self)
end

#dls_ownerObject



282
283
284
285
286
# File 'lib/zm/client/base/mailbox_object.rb', line 282

def dls_owner
  return @dls_owner if defined? @dls_owner

  @dls_owner = AccountDlsOwnerCollection.new(self)
end

#documentsObject



270
271
272
273
274
# File 'lib/zm/client/base/mailbox_object.rb', line 270

def documents
  return @documents if defined? @documents

  @documents = DocumentsCollection.new(self)
end

#domain_nameObject



58
59
60
61
62
# File 'lib/zm/client/base/mailbox_object.rb', line 58

def domain_name
  return @domain_name if defined? @domain_name

  @domain_name = @name.split('@').last
end

#filter_rulesObject



288
289
290
291
292
# File 'lib/zm/client/base/mailbox_object.rb', line 288

def filter_rules
  return @filter_rules if defined? @filter_rules

  @filter_rules = FilterRulesCollection.new(self)
end

#foldersObject



203
204
205
206
207
# File 'lib/zm/client/base/mailbox_object.rb', line 203

def folders
  return @folders if defined? @folders

  @folders = FoldersCollection.new(self)
end

#identitiesObject



221
222
223
224
225
# File 'lib/zm/client/base/mailbox_object.rb', line 221

def identities
  return @identities if defined? @identities

  @identities = IdentitiesCollection.new(self)
end

#infosObject



64
65
66
67
68
# File 'lib/zm/client/base/mailbox_object.rb', line 64

def infos
  return @infos if defined? @infos

  @infos = MailboxInfosCollection.new(self)
end

#is_external_transport?Boolean

Returns:

  • (Boolean)


337
338
339
340
341
# File 'lib/zm/client/base/mailbox_object.rb', line 337

def is_external_transport?
  return false unless zimbraMailTransport

  zimbraMailTransport.start_with?(SoapConstants::SMTP)
end

#is_local_transport?Boolean

Returns:

  • (Boolean)


331
332
333
334
335
# File 'lib/zm/client/base/mailbox_object.rb', line 331

def is_local_transport?
  return false unless zimbraMailTransport

  zimbraMailTransport.start_with?(SoapConstants::LMTP)
end

#last_logonObject



343
344
345
346
347
# File 'lib/zm/client/base/mailbox_object.rb', line 343

def last_logon
  return @last_logon if defined? @last_logon

  @last_logon = Time.parse(zimbraLastLogonTimestamp) unless zimbraLastLogonTimestamp.nil?
end

#local_transportObject



321
322
323
324
325
# File 'lib/zm/client/base/mailbox_object.rb', line 321

def local_transport
  raise Zm::Client::ZmError, 'zimbraMailHost is null' if zimbraMailHost.nil?

  "lmtp:#{zimbraMailHost}:7025"
end

#local_transport!Object



327
328
329
# File 'lib/zm/client/base/mailbox_object.rb', line 327

def local_transport!
  update!(zimbraMailTransport: local_transport)
end

#logged?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/zm/client/base/mailbox_object.rb', line 114

def logged?
  !token.nil? && !token.expired?
end

#logged_and_alive?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/zm/client/base/mailbox_object.rb', line 127

def logged_and_alive?
  logged? && alive?
end

#loginObject



137
138
139
140
141
142
143
# File 'lib/zm/client/base/mailbox_object.rb', line 137

def 
  if parent_logged?
    
  else
    
  end
end

#mailbox_infosObject



92
93
94
95
96
97
# File 'lib/zm/client/base/mailbox_object.rb', line 92

def mailbox_infos
  soap_request = SoapElement.admin(SoapAdminConstants::GET_MAILBOX_REQUEST)
  node_mbox = SoapElement.create(SoapConstants::MBOX).add_attribute(SoapConstants::ID, @id)
  soap_request.add_node(node_mbox)
  sac.invoke(soap_request)[:GetMailboxResponse][:mbox].first
end

#mbxidObject



84
85
86
# File 'lib/zm/client/base/mailbox_object.rb', line 84

def mbxid
  @mbxid || mbxid!
end

#mbxid!Object



88
89
90
# File 'lib/zm/client/base/mailbox_object.rb', line 88

def mbxid!
  @mbxid = mailbox_infos[:mbxid]
end

#membershipsObject



276
277
278
279
280
# File 'lib/zm/client/base/mailbox_object.rb', line 276

def memberships
  return @memberships if defined? @memberships

  @memberships = AccountDlsMembershipCollection.new(self)
end

#messagesObject

################################################################# Associations #################################################################



197
198
199
200
201
# File 'lib/zm/client/base/mailbox_object.rb', line 197

def messages
  return @messages if defined? @messages

  @messages = MessagesCollection.new(self)
end

#mountpointsObject



209
210
211
212
213
# File 'lib/zm/client/base/mailbox_object.rb', line 209

def mountpoints
  return @mountpoints if defined? @mountpoints

  @mountpoints = MountPointsCollection.new(self)
end

#outgoing_filter_rulesObject



294
295
296
297
298
# File 'lib/zm/client/base/mailbox_object.rb', line 294

def outgoing_filter_rules
  return @outgoing_filter_rules if defined? @outgoing_filter_rules

  @outgoing_filter_rules = OutgoingFilterRulesCollection.new(self)
end

#password!(new_password = nil) ⇒ Object

################################################################# SOAP Actions #################################################################



310
311
312
313
314
315
316
317
318
319
# File 'lib/zm/client/base/mailbox_object.rb', line 310

def password!(new_password = nil)
  new_password ||= @password
  return false if new_password.nil?

  soap_request = SoapElement.admin(SoapAdminConstants::SET_PASSWORD_REQUEST)
  soap_request.add_attributes({ id: @id, newPassword: new_password })
  sac.invoke(soap_request)

  @password = new_password
end

#prefsObject



70
71
72
73
74
# File 'lib/zm/client/base/mailbox_object.rb', line 70

def prefs
  return @prefs if defined? @prefs

  @prefs = MailboxPrefsCollection.new(self)
end

#rest_account_urlObject



387
388
389
390
391
392
393
394
395
# File 'lib/zm/client/base/mailbox_object.rb', line 387

def 
  if soap_config.zimbra_public_url
    File.join(soap_config.zimbra_public_url, 'home', @name)
  elsif home_url
    home_url
  else
    raise ZmError, 'impossible to set rest_account_url'
  end
end

#rest_admin_urlObject

Raises:



381
382
383
384
385
# File 'lib/zm/client/base/mailbox_object.rb', line 381

def rest_admin_url
  raise ZmError, 'impossible to set rest_admin_url' unless soap_config.zimbra_admin_url

  File.join(soap_config.zimbra_admin_url, 'home', @name)
end

#rest_optionsObject



358
359
360
361
362
363
364
365
366
367
# File 'lib/zm/client/base/mailbox_object.rb', line 358

def rest_options
  if soap_config
    {
      timeout: soap_config.timeout,
      verbose: soap_config.logger.debug?
    }
  else
    {}
  end
end

#rest_urlObject

Raises:



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/zm/client/base/mailbox_object.rb', line 369

def rest_url
  raise ZmError, 'name attribute is requuired for REST Url' unless @name

  if logged?
    
  elsif parent_logged?
    rest_admin_url
  else
    raise ZmError, 'impossible to set rest_url'
  end
end

#search_foldersObject



215
216
217
218
219
# File 'lib/zm/client/base/mailbox_object.rb', line 215

def search_folders
  return @search_folders if defined? @search_folders

  @search_folders = SearchFoldersCollection.new(self)
end

#sharesObject



227
228
229
230
231
# File 'lib/zm/client/base/mailbox_object.rb', line 227

def shares
  return @shares if defined? @shares

  @shares = SharesCollection.new(self)
end

#signaturesObject



264
265
266
267
268
# File 'lib/zm/client/base/mailbox_object.rb', line 264

def signatures
  return @signatures if defined? @signatures

  @signatures = SignaturesCollection.new(self)
end

#soap_account_connectorObject



32
33
34
35
36
# File 'lib/zm/client/base/mailbox_object.rb', line 32

def 
  return  if defined? 

   = SoapAccountConnector.create(soap_config)
end

#soap_connectorObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/zm/client/base/mailbox_object.rb', line 38

def soap_connector
  return @soap_connector if defined? @soap_connector

  if logged?
    @soap_connector = 
  elsif (@id || @name) && @parent&.logged?
    @soap_connector = @parent.soap_admin_connector.clone

    if @id
      @soap_connector.context.(:id, @id)
    else
      @soap_connector.context.(:name, @name)
    end
  else
    raise ZmError, 'SoapConnector not defined'
  end

  @soap_connector
end

#tagsObject



245
246
247
248
249
# File 'lib/zm/client/base/mailbox_object.rb', line 245

def tags
  return @tags if defined? @tags

  @tags = TagsCollection.new(self)
end

#tasksObject



251
252
253
254
255
# File 'lib/zm/client/base/mailbox_object.rb', line 251

def tasks
  return @tasks if defined? @tasks

  @tasks = TasksCollection.new(self)
end

#tokenObject

################################################################# Authentication #################################################################



103
104
105
106
107
# File 'lib/zm/client/base/mailbox_object.rb', line 103

def token
  return @token if defined? @token

  @token = (Token.new(.token) if .token)
end

#token=(value) ⇒ Object



109
110
111
112
# File 'lib/zm/client/base/mailbox_object.rb', line 109

def token=(value)
  @token = Token.new(.token = value)
  @soap_connector = 
end

#used!Object



80
81
82
# File 'lib/zm/client/base/mailbox_object.rb', line 80

def used!
  @used = mailbox_infos[:s]
end