Class: Imap::Backup::Account::Connection
- Inherits:
-
Object
- Object
- Imap::Backup::Account::Connection
show all
- Defined in:
- lib/imap/backup/account/connection.rb,
lib/imap/backup/account/connection/folder_names.rb,
lib/imap/backup/account/connection/backup_folders.rb
Defined Under Namespace
Classes: BackupFolders, ClientFactory, FolderNames
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(account) ⇒ Connection
Returns a new instance of Connection.
16
17
18
19
|
# File 'lib/imap/backup/account/connection.rb', line 16
def initialize(account)
@account = account
reset
end
|
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
14
15
16
|
# File 'lib/imap/backup/account/connection.rb', line 14
def account
@account
end
|
Instance Method Details
#backup_folders ⇒ Object
25
26
27
28
|
# File 'lib/imap/backup/account/connection.rb', line 25
def backup_folders
@backup_folders ||=
Account::Connection::BackupFolders.new(client: client, account: account).run
end
|
#disconnect ⇒ Object
97
98
99
100
|
# File 'lib/imap/backup/account/connection.rb', line 97
def disconnect
client.disconnect if @client
reset
end
|
#folder_names ⇒ Object
21
22
23
|
# File 'lib/imap/backup/account/connection.rb', line 21
def folder_names
@folder_names ||= Account::Connection::FolderNames.new(client: client, account: account).run
end
|
#local_folders ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/imap/backup/account/connection.rb', line 77
def local_folders
return enum_for(:local_folders) if !block_given?
ensure_account_folder
glob = File.join(account.local_path, "**", "*.imap")
base = Pathname.new(account.local_path)
Pathname.glob(glob) do |path|
name = path.relative_path_from(base).to_s[0..-6]
serializer = Serializer.new(account.local_path, name)
folder = Account::Folder.new(self, name)
yield serializer, folder
end
end
|
#namespaces ⇒ Object
30
31
32
|
# File 'lib/imap/backup/account/connection.rb', line 30
def namespaces
client.namespace
end
|
#reconnect ⇒ Object
102
103
104
|
# File 'lib/imap/backup/account/connection.rb', line 102
def reconnect
disconnect
end
|
#reset ⇒ Object
106
107
108
109
110
|
# File 'lib/imap/backup/account/connection.rb', line 106
def reset
@backup_folders = nil
@client = nil
@folder_names = nil
end
|
#restore ⇒ Object
91
92
93
94
95
|
# File 'lib/imap/backup/account/connection.rb', line 91
def restore
local_folders do |serializer, folder|
Uploader.new(folder, serializer).run
end
end
|
#run_backup(refresh: false) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/imap/backup/account/connection.rb', line 34
def run_backup(refresh: false)
Logger.logger.info "Running backup of account: #{account.username}"
client
ensure_account_folder
if account.mirror_mode
wanted = backup_folders.map(&:name)
local_folders do |serializer, _folder|
serializer.delete if !wanted.include?(serializer.folder)
end
end
each_folder do |folder, serializer|
begin
next if !folder.exist?
rescue Encoding::UndefinedConversionError
message = "Skipping backup for '#{folder.name}' " \
"as it is not UTF-7 encoded correctly"
Logger.logger.info message
next
end
Logger.logger.debug "[#{folder.name}] running backup"
serializer.apply_uid_validity(folder.uid_validity)
begin
Downloader.new(
folder,
serializer,
multi_fetch_size: account.multi_fetch_size,
reset_seen_flags_after_fetch: account.reset_seen_flags_after_fetch
).run
if account.mirror_mode
Logger.logger.info "Mirror mode - Deleting messages only present locally"
LocalOnlyMessageDeleter.new(folder, serializer).run
end
FlagRefresher.new(folder, serializer).run if account.mirror_mode || refresh
rescue Net::IMAP::ByeResponseError
reconnect
retry
end
end
end
|