Class: Imap::Backup::Account::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/account/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection



11
12
13
14
15
16
17
18
19
# File 'lib/imap/backup/account/connection.rb', line 11

def initialize(options)
  @username, @password = options[:username], options[:password]
  @local_path = options[:local_path]
  @backup_folders = options[:folders]
  @server = options[:server]
  @connection_options = options[:connection_options] || {}
  @folders = nil
  
end

Instance Attribute Details

#connection_options ⇒ Object (readonly)

Returns the value of attribute connection_options.



9
10
11
# File 'lib/imap/backup/account/connection.rb', line 9

def connection_options
  @connection_options
end

#local_path ⇒ Object (readonly)

Returns the value of attribute local_path.



8
9
10
# File 'lib/imap/backup/account/connection.rb', line 8

def local_path
  @local_path
end

#username ⇒ Object (readonly)

Returns the value of attribute username.



7
8
9
# File 'lib/imap/backup/account/connection.rb', line 7

def username
  @username
end

Instance Method Details

#disconnect ⇒ Object



48
49
50
# File 'lib/imap/backup/account/connection.rb', line 48

def disconnect
  imap.disconnect
end

#folders ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/imap/backup/account/connection.rb', line 21

def folders
  return @folders if @folders
  @folders = imap.list("", "*")
  if @folders.nil?
    Imap::Backup.logger.warn "Unable to get folder list for account #{username}"
  end
  @folders
end

#imap ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/imap/backup/account/connection.rb', line 52

def imap
  return @imap unless @imap.nil?
  options = provider_options
  Imap::Backup.logger.debug "Creating IMAP instance: #{server}, options: #{options.inspect}"
  @imap = Net::IMAP.new(server, options)
  Imap::Backup.logger.debug "Logging in: #{username}/#{masked_password}"
  @imap.(username, password)
  Imap::Backup.logger.debug "Login complete"
  @imap
end

#run_backup ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/imap/backup/account/connection.rb', line 38

def run_backup
  Imap::Backup.logger.debug "Running backup of account: #{username}"
  # start the connection so we get logging messages in the right order
  imap
  each_folder do |folder, serializer|
    Imap::Backup.logger.debug "[#{folder.name}] running backup"
    Downloader.new(folder, serializer).run
  end
end

#status ⇒ Object



30
31
32
33
34
35
36
# File 'lib/imap/backup/account/connection.rb', line 30

def status
  backup_folders.map do |folder|
    f = ::Folder.new(self, folder[:name])
    s = Serializer::Directory.new(local_path, folder[:name])
    {name: folder[:name], local: s.uids, remote: f.uids}
  end
end