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.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#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.
- #reconnect ⇒ Object
- #restore ⇒ Object
- #run_backup ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/imap/backup/account/connection.rb', line 12 def initialize() @username = [:username] @password = [:password] @local_path = [:local_path] @backup_folders = [:folders] @server = [:server] @connection_options = [:connection_options] || {} @folders = nil create_account_folder end |
Instance Attribute Details
#connection_options ⇒ Object (readonly)
Returns the value of attribute connection_options.
7 8 9 |
# File 'lib/imap/backup/account/connection.rb', line 7 def @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 |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/imap/backup/account/connection.rb', line 9 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/imap/backup/account/connection.rb', line 10 def username @username end |
Instance Method Details
#disconnect ⇒ Object
64 65 66 |
# File 'lib/imap/backup/account/connection.rb', line 64 def disconnect imap.disconnect end |
#folders ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/imap/backup/account/connection.rb', line 23 def folders @folders ||= begin root = provider_root @folders = imap.list(root, "*") if @folders.nil? Imap::Backup.logger.warn( "Unable to get folder list for account #{username}" ) end @folders end end |
#imap ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/imap/backup/account/connection.rb', line 73 def imap return @imap unless @imap.nil? = Imap::Backup.logger.debug( "Creating IMAP instance: #{server}, 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 |
#reconnect ⇒ Object
68 69 70 71 |
# File 'lib/imap/backup/account/connection.rb', line 68 def reconnect disconnect @imap = nil end |
#restore ⇒ Object
58 59 60 61 62 |
# File 'lib/imap/backup/account/connection.rb', line 58 def restore local_folders do |serializer, folder| restore_folder serializer, folder end end |
#run_backup ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/imap/backup/account/connection.rb', line 45 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| next if !folder.exist? Imap::Backup.logger.debug "[#{folder.name}] running backup" serializer.apply_uid_validity(folder.uid_validity) Downloader.new(folder, serializer).run end end |