Class: Mailarchiva::SoapClient

Inherits:
Base
  • Object
show all
Defined in:
lib/mailarchiva/soap_client.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app_name, #client, #host, #pass, #port, #ssl, #user

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SoapClient

Returns a new instance of SoapClient.



13
14
15
# File 'lib/mailarchiva/soap_client.rb', line 13

def initialize(args)
  super(args)
end

Instance Attribute Details

#soap_clientObject

Returns the value of attribute soap_client.



11
12
13
# File 'lib/mailarchiva/soap_client.rb', line 11

def soap_client
  @soap_client
end

Instance Method Details

#get_mail_message(blob_id, volume_id) ⇒ Object



45
46
47
48
# File 'lib/mailarchiva/soap_client.rb', line 45

def get_mail_message(blob_id, volume_id)
  message = get_message(blob_id, volume_id)
  Mail.new(message)
end

#get_message(blob_id, volume_id) ⇒ Object



39
40
41
42
43
# File 'lib/mailarchiva/soap_client.rb', line 39

def get_message(blob_id, volume_id)
  blob_response = soap_client.call(:get_blob, message: { 'blobID' =>{ 'blobID' => blob_id, 'volumeID' => volume_id } })
  encoded_message = blob_response.body[:get_blob_response][:return][:blob]
  decoded_message = Base64.decode64(encoded_message)
end

#logged_in?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/mailarchiva/soap_client.rb', line 66

def logged_in?
  @session_id.nil? ? false : soap_client.call(:is_logged_in).body[:is_logged_in_response][:return]
end

#login(client) ⇒ Object



61
62
63
64
# File 'lib/mailarchiva/soap_client.rb', line 61

def (client)
  response = client.call(:login, message: { applicationname: @app_name, username: @user, password: @pass })
  response.http.cookies.first.name_and_value
end

#logoutObject



70
71
72
73
# File 'lib/mailarchiva/soap_client.rb', line 70

def logout
  soap_client.call(:logout, message: {})
  @soap_client = nil
end

#search(params) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/mailarchiva/soap_client.rb', line 17

def search(params)
  params = {blob_category: 'email', max_results: 1000}.merge(params)
  params[:sent_before] = params[:sent_before].strftime("%Y-%m-%dT%T") if params.has_key?(:sent_before) && params[:sent_before].is_a?(Time)
  params[:sent_after] = params[:sent_after].strftime("%Y-%m-%dT%T") if params.has_key?(:sent_after) && params[:sent_after].is_a?(Time)
  search_response = soap_client.call(:search, message: params)
  search_results = search_results_from_response(search_response)
  logout
  search_results
end

#search_result_sizeObject



34
35
36
37
# File 'lib/mailarchiva/soap_client.rb', line 34

def search_result_size
  search_result_size_response = soap_client.call(:get_search_result_size)
  search_result_size_response.body[:get_search_result_size_response][:return].to_i
end

#search_results_from_response(response) ⇒ Object



27
28
29
30
31
32
# File 'lib/mailarchiva/soap_client.rb', line 27

def search_results_from_response(response)
  return [] if search_result_size == 0
  search_results_response = soap_client.call(:get_search_results, message: { blob_category: 'email', start: 0, end: search_result_size })
  search_results = [ search_results_response.body[:get_search_results_response][:return] ].flatten.compact
  search_results.map{|field_values| Message.new(self, field_values)}
end

#wsdlObject



50
51
52
# File 'lib/mailarchiva/soap_client.rb', line 50

def wsdl
  "%s://%s:%s/services/search?wsdl" % [@ssl ? 'https' : 'http', @host, @port]
end