Class: Imap::Backup::Account::Connection
- Inherits:
-
Object
- Object
- Imap::Backup::Account::Connection
- Defined in:
- lib/imap/backup/account/connection.rb
Instance Attribute Summary collapse
-
#connection_options ⇒ Object
readonly
Returns the value of attribute connection_options.
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #disconnect ⇒ Object
- #folders ⇒ Object
- #imap ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #run_backup ⇒ Object
- #status ⇒ Object
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() @username, @password = [:username], [:password] @local_path = [:local_path] @backup_folders = [:folders] @server = [:server] = [:connection_options] || {} @folders = nil create_account_folder 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 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? = Imap::Backup.logger.debug "Creating IMAP instance: #{server}, options: #{options.inspect}" @imap = Net::IMAP.new(server, ) Imap::Backup.logger.debug "Logging in: #{username}/#{masked_password}" @imap.login(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 = Account::Folder.new(self, folder[:name]) s = Serializer::Directory.new(local_path, folder[:name]) {name: folder[:name], local: s.uids, remote: f.uids} end end |