Class: Imap::Backup::Client::Default

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/imap/backup/client/default.rb

Overview

Wraps a Net::IMAP instance Tracks the latest folder selection in order to avoid repeated calls

Instance Method Summary collapse

Constructor Details

#initialize(account) ⇒ Default

Returns a new instance of Default.



22
23
24
25
# File 'lib/imap/backup/client/default.rb', line 22

def initialize()
  @account = 
  @state = nil
end

Instance Method Details

#disconnectvoid

This method returns an undefined value.

Disconects from the server



63
64
65
66
# File 'lib/imap/backup/client/default.rb', line 63

def disconnect
  imap.disconnect
  self.state = nil
end

#examine(mailbox) ⇒ void

This method returns an undefined value.

Prepares read-only access to a folder



70
71
72
73
74
75
# File 'lib/imap/backup/client/default.rb', line 70

def examine(mailbox)
  return if state == [:examine, mailbox]

  imap.examine(mailbox)
  self.state = [:examine, mailbox]
end

#listArray<String>

Returns the account folders.

Returns:

  • (Array<String>)

    the account folders



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/imap/backup/client/default.rb', line 28

def list
  root = provider_root
  Logger.logger.debug "Listing all account folders"
  mailbox_lists = imap.list(root, "*")

  return [] if mailbox_lists.nil?

  ignored_tags = provider.folder_ignore_tags
  mailbox_lists.
    select { |ml| ml.attr & ignored_tags == [] }.
    map { |ml| extract_name(ml) }
end

#loginvoid

This method returns an undefined value.

Logs in to the account on the IMAP server



43
44
45
46
47
# File 'lib/imap/backup/client/default.rb', line 43

def 
  Logger.logger.debug "Logging in: #{account.username}/#{masked_password}"
  imap.(.username, .password)
  Logger.logger.debug "Login complete"
end

#reconnectvoid

This method returns an undefined value.

Logs out and back in to the server



51
52
53
54
# File 'lib/imap/backup/client/default.rb', line 51

def reconnect
  disconnect
  
end

#select(mailbox) ⇒ void

This method returns an undefined value.

Prepares read-write access to a folder



79
80
81
82
83
84
# File 'lib/imap/backup/client/default.rb', line 79

def select(mailbox)
  return if state == [:select, mailbox]

  imap.select(mailbox)
  self.state = [:select, mailbox]
end

#usernameString

Returns the account username.

Returns:

  • (String)

    the account username



57
58
59
# File 'lib/imap/backup/client/default.rb', line 57

def username
  .username
end