Class: MailHandler::Receiving::IMAPChecker

Inherits:
Checker
  • Object
show all
Defined in:
lib/mailhandler/receiving/imap.rb

Overview

in charge of retrieving email by IMAP

Instance Attribute Summary collapse

Attributes inherited from Checker

#available_search_options, #found_emails, #search_options

Instance Method Summary collapse

Methods inherited from Checker

#reset_found_emails, #search_result

Constructor Details

#initializeIMAPChecker

Returns a new instance of IMAPChecker.



20
21
22
23
24
# File 'lib/mailhandler/receiving/imap.rb', line 20

def initialize
  super
  @manual_connection_manage = false
  @available_search_options = AVAILABLE_SEARCH_OPTIONS
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



9
10
11
# File 'lib/mailhandler/receiving/imap.rb', line 9

def address
  @address
end

#authenticationObject

Returns the value of attribute authentication.



9
10
11
# File 'lib/mailhandler/receiving/imap.rb', line 9

def authentication
  @authentication
end

#manual_connection_manageObject

Connection is closed by default after each search. By setting this flag, closing connection is ignored and you need to close it manually.



18
19
20
# File 'lib/mailhandler/receiving/imap.rb', line 18

def manual_connection_manage
  @manual_connection_manage
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/mailhandler/receiving/imap.rb', line 9

def password
  @password
end

#portObject

Returns the value of attribute port.



9
10
11
# File 'lib/mailhandler/receiving/imap.rb', line 9

def port
  @port
end

#use_sslObject

Returns the value of attribute use_ssl.



9
10
11
# File 'lib/mailhandler/receiving/imap.rb', line 9

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/mailhandler/receiving/imap.rb', line 9

def username
  @username
end

Instance Method Details

#connectObject



46
47
48
# File 'lib/mailhandler/receiving/imap.rb', line 46

def connect
  mailer.connect
end

#disconnectObject



50
51
52
53
54
# File 'lib/mailhandler/receiving/imap.rb', line 50

def disconnect
  return if mailer.imap_connection.disconnected?

  mailer.disconnect
end

#find(options) ⇒ Object



26
27
28
29
30
31
# File 'lib/mailhandler/receiving/imap.rb', line 26

def find(options)
  verify_and_set_search_options(options)
  @found_emails = find_emails(search_options)

  search_result
end

#init_retrieverObject

delegate retrieval details to Mail library set imap settings if they are not set



58
59
60
61
62
63
64
65
66
67
# File 'lib/mailhandler/receiving/imap.rb', line 58

def init_retriever
  return if retriever_set?

  imap_settings = retriever_settings

  Mail.defaults do
    retriever_method :imap,
                     imap_settings
  end
end

#startObject



33
34
35
36
37
38
# File 'lib/mailhandler/receiving/imap.rb', line 33

def start
  return if manual_connection_manage

  init_retriever
  connect
end

#stopObject



40
41
42
43
44
# File 'lib/mailhandler/receiving/imap.rb', line 40

def stop
  return if manual_connection_manage

  disconnect
end