imap-backup 4.0.4 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/bin/imap-backup +5 -2
  3. data/lib/email/provider/apple_mail.rb +2 -2
  4. data/lib/email/provider/base.rb +8 -0
  5. data/lib/email/provider/fastmail.rb +2 -2
  6. data/lib/email/provider/gmail.rb +2 -2
  7. data/lib/email/provider/{default.rb → unknown.rb} +2 -3
  8. data/lib/email/provider.rb +2 -2
  9. data/lib/imap/backup/account/connection.rb +70 -58
  10. data/lib/imap/backup/account/folder.rb +23 -3
  11. data/lib/imap/backup/account.rb +102 -0
  12. data/lib/imap/backup/cli/accounts.rb +43 -0
  13. data/lib/imap/backup/cli/folders.rb +3 -1
  14. data/lib/imap/backup/cli/helpers.rb +8 -9
  15. data/lib/imap/backup/cli/local.rb +4 -2
  16. data/lib/imap/backup/cli/setup.rb +1 -1
  17. data/lib/imap/backup/cli/utils.rb +3 -2
  18. data/lib/imap/backup/{configuration/store.rb → configuration.rb} +49 -14
  19. data/lib/imap/backup/downloader.rb +26 -12
  20. data/lib/imap/backup/logger.rb +42 -0
  21. data/lib/imap/backup/sanitizer.rb +42 -0
  22. data/lib/imap/backup/serializer/mbox_store.rb +2 -2
  23. data/lib/imap/backup/setup/account.rb +177 -0
  24. data/lib/imap/backup/{configuration → setup}/asker.rb +5 -5
  25. data/lib/imap/backup/setup/connection_tester.rb +26 -0
  26. data/lib/imap/backup/{configuration → setup}/folder_chooser.rb +25 -17
  27. data/lib/imap/backup/setup/helpers.rb +15 -0
  28. data/lib/imap/backup/{configuration/setup.rb → setup.rb} +33 -25
  29. data/lib/imap/backup/uploader.rb +2 -2
  30. data/lib/imap/backup/version.rb +2 -2
  31. data/lib/imap/backup.rb +7 -33
  32. data/lib/retry_on_error.rb +1 -1
  33. data/spec/features/backup_spec.rb +1 -0
  34. data/spec/features/support/email_server.rb +5 -2
  35. data/spec/features/support/shared/connection_context.rb +7 -5
  36. data/spec/support/higline_test_helpers.rb +1 -1
  37. data/spec/support/silence_logging.rb +1 -1
  38. data/spec/unit/email/provider/{default_spec.rb → base_spec.rb} +1 -7
  39. data/spec/unit/email/provider_spec.rb +2 -2
  40. data/spec/unit/imap/backup/account/connection_spec.rb +22 -26
  41. data/spec/unit/imap/backup/cli/accounts_spec.rb +47 -0
  42. data/spec/unit/imap/backup/cli/local_spec.rb +15 -4
  43. data/spec/unit/imap/backup/cli/utils_spec.rb +54 -42
  44. data/spec/unit/imap/backup/{configuration/store_spec.rb → configuration_spec.rb} +23 -24
  45. data/spec/unit/imap/backup/downloader_spec.rb +1 -1
  46. data/spec/unit/imap/backup/logger_spec.rb +48 -0
  47. data/spec/unit/imap/backup/{configuration → setup}/account_spec.rb +78 -70
  48. data/spec/unit/imap/backup/{configuration → setup}/asker_spec.rb +2 -2
  49. data/spec/unit/imap/backup/{configuration → setup}/connection_tester_spec.rb +10 -10
  50. data/spec/unit/imap/backup/{configuration → setup}/folder_chooser_spec.rb +25 -26
  51. data/spec/unit/imap/backup/{configuration/setup_spec.rb → setup_spec.rb} +81 -52
  52. metadata +54 -51
  53. data/lib/imap/backup/configuration/account.rb +0 -159
  54. data/lib/imap/backup/configuration/connection_tester.rb +0 -14
  55. data/lib/imap/backup/configuration/list.rb +0 -53
  56. data/spec/support/shared_examples/account_flagging.rb +0 -23
  57. data/spec/unit/imap/backup/configuration/list_spec.rb +0 -89
  58. data/spec/unit/imap/backup_spec.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69ed28d85dda7c3d30cd6c8d4a9888e9f477eedd6f8ff08741fcc7d27cf087f8
4
- data.tar.gz: 1a99e7143052a1d0b1b2d58381c5f9da0db2b1e0e3882c24e56036cebead043f
3
+ metadata.gz: d6302ae17c5b96de2f99c6683c4a6403edbf80d2afc51cbe0f471918251cfaef
4
+ data.tar.gz: 349c0b68911a751e670176a91dfc98d4359a06a9cb8acae7c2cc5d5efa028f25
5
5
  SHA512:
6
- metadata.gz: deb80ed5d629c81253574d96a7da0dcc6382eb6d5216c1f317b8083ca0f4dac80a3188cbc0b7f46ffbc01229dad9ab913858649558ca7b3a29bf7b81395bcce3
7
- data.tar.gz: 2e6b2b8d2c67c6bc1e3ff5dcbb91c4eec92d0edb87ff33ad6e8a360b6635895c72cc7eb4cc68a7ff24bcfbad5a3533bda0a916e3c4d0c40ee67de70a010d4b2b
6
+ metadata.gz: 444432d3bf689fa12de1226cb84e9f8975a300f2c94cc2529254e1e3680fba6d7b0cfddfc3fff9001a866dd5d84d1afabc0e952e894ec5ae1a91557ea5538472
7
+ data.tar.gz: f4d156790a84308e08ee3d4348741e6d55b26f07fece75473a80f4fc0b7c0265c1bb62230cee178bf4c00941ff0de91a323ade1c0e0783a72a970c738c8823f0
data/bin/imap-backup CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  $LOAD_PATH.unshift(File.expand_path("../lib/", __dir__))
4
4
  require "imap/backup/cli"
5
+ require "imap/backup/logger"
5
6
 
6
- Imap::Backup::Configuration::List.new.setup_logging
7
+ Imap::Backup::Logger.setup_logging
7
8
 
8
- Imap::Backup::CLI.start(ARGV)
9
+ Imap::Backup::Logger.sanitize_stderr do
10
+ Imap::Backup::CLI.start(ARGV)
11
+ end
@@ -1,6 +1,6 @@
1
- require "email/provider/default"
1
+ require "email/provider/base"
2
2
 
3
- class Email::Provider::AppleMail < Email::Provider::Default
3
+ class Email::Provider::AppleMail < Email::Provider::Base
4
4
  def host
5
5
  "imap.mail.me.com"
6
6
  end
@@ -0,0 +1,8 @@
1
+ module Email; end
2
+ class Email::Provider; end
3
+
4
+ class Email::Provider::Base
5
+ def options
6
+ {port: 993, ssl: {ssl_version: :TLSv1_2}}
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
- require "email/provider/default"
1
+ require "email/provider/base"
2
2
 
3
- class Email::Provider::Fastmail < Email::Provider::Default
3
+ class Email::Provider::Fastmail < Email::Provider::Base
4
4
  def host
5
5
  "imap.fastmail.com"
6
6
  end
@@ -1,6 +1,6 @@
1
- require "email/provider/default"
1
+ require "email/provider/base"
2
2
 
3
- class Email::Provider::GMail < Email::Provider::Default
3
+ class Email::Provider::GMail < Email::Provider::Base
4
4
  def host
5
5
  "imap.gmail.com"
6
6
  end
@@ -1,7 +1,6 @@
1
- module Email; end
2
- class Email::Provider; end
1
+ require "email/provider/base"
3
2
 
4
- class Email::Provider::Default
3
+ class Email::Provider::Unknown < Email::Provider::Base
5
4
  # We don't know how to guess the IMAP server
6
5
  def host
7
6
  end
@@ -1,7 +1,7 @@
1
- require "email/provider/default"
2
1
  require "email/provider/apple_mail"
3
2
  require "email/provider/fastmail"
4
3
  require "email/provider/gmail"
4
+ require "email/provider/unknown"
5
5
 
6
6
  module Email; end
7
7
 
@@ -21,7 +21,7 @@ class Email::Provider
21
21
  when address.end_with?("@me.com")
22
22
  Email::Provider::AppleMail.new
23
23
  else
24
- Email::Provider::Default.new
24
+ Email::Provider::Unknown.new
25
25
  end
26
26
  end
27
27
  end
@@ -4,63 +4,74 @@ require "imap/backup/client/default"
4
4
  require "retry_on_error"
5
5
 
6
6
  module Imap::Backup
7
- module Account; end
7
+ class Account; end
8
8
 
9
9
  class Account::Connection
10
10
  include RetryOnError
11
11
 
12
12
  LOGIN_RETRY_CLASSES = [EOFError, Errno::ECONNRESET, SocketError].freeze
13
13
 
14
- attr_reader :connection_options
15
- attr_reader :local_path
16
- attr_reader :password
17
- attr_reader :username
18
-
19
- def initialize(options)
20
- @username = options[:username]
21
- @password = options[:password]
22
- @local_path = options[:local_path]
23
- @config_folders = options[:folders]
24
- @server = options[:server]
25
- @connection_options = options[:connection_options] || {}
26
- @folders = nil
14
+ attr_reader :account
15
+
16
+ def initialize(account)
17
+ @account = account
18
+ reset
27
19
  create_account_folder
28
20
  end
29
21
 
30
- def folders
31
- @folders ||=
22
+ # TODO: Make this private once the 'folders' command
23
+ # has been removed.
24
+ def folder_names
25
+ @folder_names ||=
32
26
  begin
33
- folders = client.list
27
+ folder_names = client.list
34
28
 
35
- if folders.empty?
36
- message = "Unable to get folder list for account #{username}"
37
- Imap::Backup.logger.info message
29
+ if folder_names.empty?
30
+ message = "Unable to get folder list for account #{account.username}"
31
+ Imap::Backup::Logger.logger.info message
38
32
  raise message
39
33
  end
40
34
 
41
- folders
35
+ folder_names
36
+ end
37
+ end
38
+
39
+ def backup_folders
40
+ @backup_folders ||=
41
+ begin
42
+ names =
43
+ if account.folders&.any?
44
+ account.folders.map { |af| af[:name] }
45
+ else
46
+ folder_names
47
+ end
48
+
49
+ names.map do |name|
50
+ Account::Folder.new(self, name)
51
+ end
42
52
  end
43
53
  end
44
54
 
45
55
  def status
46
- backup_folders.map do |backup_folder|
47
- f = Account::Folder.new(self, backup_folder[:name])
48
- s = Serializer::Mbox.new(local_path, backup_folder[:name])
49
- {name: backup_folder[:name], local: s.uids, remote: f.uids}
56
+ backup_folders.map do |folder|
57
+ s = Serializer::Mbox.new(account.local_path, folder.name)
58
+ {name: folder.name, local: s.uids, remote: folder.uids}
50
59
  end
51
60
  end
52
61
 
53
62
  def run_backup
54
- Imap::Backup.logger.debug "Running backup of account: #{username}"
63
+ Imap::Backup::Logger.logger.debug "Running backup of account: #{account.username}"
55
64
  # start the connection so we get logging messages in the right order
56
65
  client
57
66
  each_folder do |folder, serializer|
58
67
  next if !folder.exist?
59
68
 
60
- Imap::Backup.logger.debug "[#{folder.name}] running backup"
69
+ Imap::Backup::Logger.logger.debug "[#{folder.name}] running backup"
61
70
  serializer.apply_uid_validity(folder.uid_validity)
62
71
  begin
63
- Downloader.new(folder, serializer).run
72
+ Downloader.new(
73
+ folder, serializer, block_size: config.download_block_size
74
+ ).run
64
75
  rescue Net::IMAP::ByeResponseError
65
76
  reconnect
66
77
  retry
@@ -71,11 +82,11 @@ module Imap::Backup
71
82
  def local_folders
72
83
  return enum_for(:local_folders) if !block_given?
73
84
 
74
- glob = File.join(local_path, "**", "*.imap")
75
- base = Pathname.new(local_path)
85
+ glob = File.join(account.local_path, "**", "*.imap")
86
+ base = Pathname.new(account.local_path)
76
87
  Pathname.glob(glob) do |path|
77
88
  name = path.relative_path_from(base).to_s[0..-6]
78
- serializer = Serializer::Mbox.new(local_path, name)
89
+ serializer = Serializer::Mbox.new(account.local_path, name)
79
90
  folder = Account::Folder.new(self, name)
80
91
  yield serializer, folder
81
92
  end
@@ -89,18 +100,27 @@ module Imap::Backup
89
100
 
90
101
  def disconnect
91
102
  client.disconnect if @client
103
+ reset
92
104
  end
93
105
 
94
106
  def reconnect
95
107
  disconnect
108
+ end
109
+
110
+ def reset
111
+ @backup_folders = nil
96
112
  @client = nil
113
+ @config = nil
114
+ @folder_names = nil
115
+ @provider = nil
116
+ @server = nil
97
117
  end
98
118
 
99
119
  def client
100
120
  @client ||=
101
121
  retry_on_error(errors: LOGIN_RETRY_CLASSES) do
102
122
  options = provider_options
103
- Imap::Backup.logger.debug(
123
+ Imap::Backup::Logger.logger.debug(
104
124
  "Creating IMAP instance: #{server}, options: #{options.inspect}"
105
125
  )
106
126
  client =
@@ -109,23 +129,22 @@ module Imap::Backup
109
129
  else
110
130
  Client::Default.new(server, options)
111
131
  end
112
- Imap::Backup.logger.debug "Logging in: #{username}/#{masked_password}"
113
- client.login(username, password)
114
- Imap::Backup.logger.debug "Login complete"
132
+ Imap::Backup::Logger.logger.debug "Logging in: #{account.username}/#{masked_password}"
133
+ client.login(account.username, account.password)
134
+ Imap::Backup::Logger.logger.debug "Login complete"
115
135
  client
116
136
  end
117
137
  end
118
138
 
119
139
  def server
120
- @server ||= provider.host
140
+ @server ||= account.server || provider.host
121
141
  end
122
142
 
123
143
  private
124
144
 
125
145
  def each_folder
126
- backup_folders.each do |backup_folder|
127
- folder = Account::Folder.new(self, backup_folder[:name])
128
- serializer = Serializer::Mbox.new(local_path, backup_folder[:name])
146
+ backup_folders.each do |folder|
147
+ serializer = Serializer::Mbox.new(account.local_path, folder.name)
129
148
  yield folder, serializer
130
149
  end
131
150
  end
@@ -133,16 +152,16 @@ module Imap::Backup
133
152
  def restore_folder(serializer, folder)
134
153
  existing_uids = folder.uids
135
154
  if existing_uids.any?
136
- Imap::Backup.logger.debug(
155
+ Imap::Backup::Logger.logger.debug(
137
156
  "There's already a '#{folder.name}' folder with emails"
138
157
  )
139
158
  new_name = serializer.apply_uid_validity(folder.uid_validity)
140
159
  old_name = serializer.folder
141
160
  if new_name
142
- Imap::Backup.logger.debug(
161
+ Imap::Backup::Logger.logger.debug(
143
162
  "Backup '#{old_name}' renamed and restored to '#{new_name}'"
144
163
  )
145
- new_serializer = Serializer::Mbox.new(local_path, new_name)
164
+ new_serializer = Serializer::Mbox.new(account.local_path, new_name)
146
165
  new_folder = Account::Folder.new(self, new_name)
147
166
  new_folder.create
148
167
  new_serializer.force_uid_validity(new_folder.uid_validity)
@@ -159,33 +178,26 @@ module Imap::Backup
159
178
 
160
179
  def create_account_folder
161
180
  Utils.make_folder(
162
- File.dirname(local_path),
163
- File.basename(local_path),
181
+ File.dirname(account.local_path),
182
+ File.basename(account.local_path),
164
183
  Serializer::DIRECTORY_PERMISSIONS
165
184
  )
166
185
  end
167
186
 
168
187
  def masked_password
169
- password.gsub(/./, "x")
170
- end
171
-
172
- def backup_folders
173
- @backup_folders ||=
174
- begin
175
- if @config_folders&.any?
176
- @config_folders
177
- else
178
- folders.map { |name| {name: name} }
179
- end
180
- end
188
+ account.password.gsub(/./, "x")
181
189
  end
182
190
 
183
191
  def provider
184
- @provider ||= Email::Provider.for_address(username)
192
+ @provider ||= Email::Provider.for_address(account.username)
185
193
  end
186
194
 
187
195
  def provider_options
188
- provider.options.merge(connection_options)
196
+ provider.options.merge(account.connection_options || {})
197
+ end
198
+
199
+ def config
200
+ @config ||= Configuration.new
189
201
  end
190
202
  end
191
203
  end
@@ -3,7 +3,7 @@ require "forwardable"
3
3
  require "retry_on_error"
4
4
 
5
5
  module Imap::Backup
6
- module Account; end
6
+ class Account; end
7
7
 
8
8
  class FolderNotFound < StandardError; end
9
9
 
@@ -64,7 +64,7 @@ module Imap::Backup
64
64
  in `search_internal` in stdlib net/imap.rb.
65
65
  This is caused by `@responses["SEARCH"] being unset/undefined
66
66
  MESSAGE
67
- Imap::Backup.logger.warn message
67
+ Imap::Backup::Logger.logger.warn message
68
68
  []
69
69
  end
70
70
 
@@ -84,6 +84,26 @@ module Imap::Backup
84
84
  nil
85
85
  end
86
86
 
87
+ def fetch_multi(uids)
88
+ examine
89
+ fetch_data_items =
90
+ retry_on_error(errors: UID_FETCH_RETRY_CLASSES) do
91
+ client.uid_fetch(uids, [BODY_ATTRIBUTE])
92
+ end
93
+ return nil if fetch_data_items.nil?
94
+
95
+ fetch_data_items.map do |item|
96
+ attributes = item.attr
97
+
98
+ {
99
+ uid: attributes["UID"],
100
+ body: attributes[BODY_ATTRIBUTE]
101
+ }
102
+ end
103
+ rescue FolderNotFound
104
+ nil
105
+ end
106
+
87
107
  def append(message)
88
108
  body = message.imap_body
89
109
  date = message.date&.to_time
@@ -96,7 +116,7 @@ module Imap::Backup
96
116
  def examine
97
117
  client.examine(utf7_encoded_name)
98
118
  rescue Net::IMAP::NoResponseError
99
- Imap::Backup.logger.warn "Folder '#{name}' does not exist on server"
119
+ Imap::Backup::Logger.logger.warn "Folder '#{name}' does not exist on server"
100
120
  raise FolderNotFound, "Folder '#{name}' does not exist on server"
101
121
  end
102
122
 
@@ -0,0 +1,102 @@
1
+ module Imap::Backup
2
+ class Account
3
+ attr_reader :username
4
+ attr_reader :password
5
+ attr_reader :local_path
6
+ attr_reader :folders
7
+ attr_reader :server
8
+ attr_reader :connection_options
9
+ attr_reader :changes
10
+ attr_reader :marked_for_deletion
11
+
12
+ def initialize(options)
13
+ @username = options[:username]
14
+ @password = options[:password]
15
+ @local_path = options[:local_path]
16
+ @folders = options[:folders]
17
+ @server = options[:server]
18
+ @connection_options = options[:connection_options]
19
+ @changes = {}
20
+ @marked_for_deletion = false
21
+ end
22
+
23
+ def connection
24
+ Account::Connection.new(self)
25
+ end
26
+
27
+ def valid?
28
+ username && password
29
+ end
30
+
31
+ def modified?
32
+ changes.any?
33
+ end
34
+
35
+ def clear_changes!
36
+ @changes = {}
37
+ end
38
+
39
+ def mark_for_deletion!
40
+ @marked_for_deletion = true
41
+ end
42
+
43
+ def marked_for_deletion?
44
+ @marked_for_deletion
45
+ end
46
+
47
+ def to_h
48
+ h = {
49
+ username: @username,
50
+ password: @password,
51
+ }
52
+ h[:local_path] = @local_path if @local_path
53
+ h[:folders] = @folders if @folders
54
+ h[:server] = @server if @server
55
+ h[:connection_options] = @connection_options if @connection_options
56
+ h
57
+ end
58
+
59
+ def username=(value)
60
+ update(:username, value)
61
+ end
62
+
63
+ def password=(value)
64
+ update(:password, value)
65
+ end
66
+
67
+ def local_path=(value)
68
+ update(:local_path, value)
69
+ end
70
+
71
+ def folders=(value)
72
+ raise "folders must be an Array" if !value.is_a?(Array)
73
+ update(:folders, value)
74
+ end
75
+
76
+ def server=(value)
77
+ update(:server, value)
78
+ end
79
+
80
+ def connection_options=(value)
81
+ parsed = JSON.parse(value)
82
+ update(:connection_options, parsed)
83
+ end
84
+
85
+ private
86
+
87
+ def update(field, value)
88
+ if changes[field]
89
+ change = changes[field]
90
+ changes.delete(field) if change[:from] == value
91
+ end
92
+ set_field!(field, value)
93
+ end
94
+
95
+ def set_field!(field, value)
96
+ key = :"@#{field}"
97
+ current = instance_variable_get(key)
98
+ changes[field] = {from: current, to: value}
99
+ instance_variable_set(key, value)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,43 @@
1
+ module Imap::Backup
2
+ class CLI; end
3
+
4
+ class CLI::Accounts
5
+ include Enumerable
6
+
7
+ attr_reader :required_accounts
8
+
9
+ def initialize(required_accounts = [])
10
+ @required_accounts = required_accounts
11
+ end
12
+
13
+ def each(&block)
14
+ return enum_for(:each) if !block
15
+
16
+ accounts.each(&block)
17
+ end
18
+
19
+ private
20
+
21
+ def accounts
22
+ @accounts ||=
23
+ if required_accounts.empty?
24
+ config.accounts
25
+ else
26
+ config.accounts.select do |account|
27
+ required_accounts.include?(account.username)
28
+ end
29
+ end
30
+ end
31
+
32
+ def config
33
+ @config ||= begin
34
+ exists = Configuration.exist?
35
+ if !exists
36
+ path = Configuration.default_pathname
37
+ raise ConfigurationNotFound, "Configuration file '#{path}' not found"
38
+ end
39
+ Configuration.new
40
+ end
41
+ end
42
+ end
43
+ end
@@ -14,7 +14,9 @@ module Imap::Backup
14
14
  def run
15
15
  each_connection(account_names) do |connection|
16
16
  puts connection.username
17
- folders = connection.folders
17
+ # TODO: Make folder_names private once this command
18
+ # has been removed.
19
+ folders = connection.folder_names
18
20
  if folders.nil?
19
21
  warn "Unable to list account folders"
20
22
  return false
@@ -1,4 +1,5 @@
1
1
  require "imap/backup"
2
+ require "imap/backup/cli/accounts"
2
3
 
3
4
  module Imap::Backup::CLI::Helpers
4
5
  def symbolized(options)
@@ -6,8 +7,8 @@ module Imap::Backup::CLI::Helpers
6
7
  end
7
8
 
8
9
  def account(email)
9
- connections = Imap::Backup::Configuration::List.new
10
- account = connections.accounts.find { |a| a[:username] == email }
10
+ accounts = Imap::Backup::CLI::Accounts.new
11
+ account = accounts.find { |a| a.username == email }
11
12
  raise "#{email} is not a configured account" if !account
12
13
 
13
14
  account
@@ -20,14 +21,12 @@ module Imap::Backup::CLI::Helpers
20
21
  end
21
22
 
22
23
  def each_connection(names)
23
- begin
24
- connections = Imap::Backup::Configuration::List.new(names)
25
- rescue Imap::Backup::ConfigurationNotFound
26
- raise "imap-backup is not configured. Run `imap-backup setup`"
27
- end
24
+ accounts = Imap::Backup::CLI::Accounts.new(names)
28
25
 
29
- connections.each_connection do |connection|
30
- yield connection
26
+ accounts.each do |account|
27
+ yield account.connection
31
28
  end
29
+ rescue Imap::Backup::ConfigurationNotFound
30
+ raise "imap-backup is not configured. Run `imap-backup setup`"
32
31
  end
33
32
  end
@@ -1,3 +1,5 @@
1
+ require "imap/backup/cli/accounts"
2
+
1
3
  module Imap::Backup
2
4
  class CLI::Local < Thor
3
5
  include Thor::Actions
@@ -5,8 +7,8 @@ module Imap::Backup
5
7
 
6
8
  desc "accounts", "List locally backed-up accounts"
7
9
  def accounts
8
- connections = Imap::Backup::Configuration::List.new
9
- connections.accounts.each { |a| Kernel.puts a[:username] }
10
+ accounts = CLI::Accounts.new
11
+ accounts.each { |a| Kernel.puts a.username }
10
12
  end
11
13
 
12
14
  desc "folders EMAIL", "List account folders"
@@ -7,7 +7,7 @@ class Imap::Backup::CLI::Setup < Thor
7
7
 
8
8
  no_commands do
9
9
  def run
10
- Imap::Backup::Configuration::Setup.new.run
10
+ Imap::Backup::Setup.new.run
11
11
  end
12
12
  end
13
13
  end
@@ -11,9 +11,10 @@ module Imap::Backup
11
11
  def ignore_history(email)
12
12
  connection = connection(email)
13
13
 
14
- connection.local_folders.each do |serializer, folder|
14
+ connection.backup_folders.each do |folder|
15
15
  next if !folder.exist?
16
16
 
17
+ serializer = Serializer::Mbox.new(connection.account.local_path, folder.name)
17
18
  do_ignore_folder_history(folder, serializer)
18
19
  end
19
20
  end
@@ -63,7 +64,7 @@ module Imap::Backup
63
64
  no_commands do
64
65
  def do_ignore_folder_history(folder, serializer)
65
66
  uids = folder.uids - serializer.uids
66
- Imap::Backup.logger.info "Folder '#{folder.name}' - #{uids.length} messages"
67
+ Imap::Backup::Logger.logger.info "Folder '#{folder.name}' - #{uids.length} messages"
67
68
 
68
69
  serializer.apply_uid_validity(folder.uid_validity)
69
70