imap-backup 4.0.7 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/bin/imap-backup +5 -2
  3. data/lib/imap/backup/account/connection.rb +53 -33
  4. data/lib/imap/backup/account/folder.rb +22 -2
  5. data/lib/imap/backup/account.rb +4 -0
  6. data/lib/imap/backup/cli/accounts.rb +43 -0
  7. data/lib/imap/backup/cli/folders.rb +3 -1
  8. data/lib/imap/backup/cli/helpers.rb +8 -9
  9. data/lib/imap/backup/cli/local.rb +4 -2
  10. data/lib/imap/backup/cli/setup.rb +1 -1
  11. data/lib/imap/backup/cli/utils.rb +3 -2
  12. data/lib/imap/backup/{configuration/store.rb → configuration.rb} +16 -3
  13. data/lib/imap/backup/downloader.rb +26 -12
  14. data/lib/imap/backup/logger.rb +42 -0
  15. data/lib/imap/backup/sanitizer.rb +42 -0
  16. data/lib/imap/backup/serializer/mbox_store.rb +2 -2
  17. data/lib/imap/backup/{configuration → setup}/account.rb +29 -19
  18. data/lib/imap/backup/{configuration → setup}/asker.rb +5 -5
  19. data/lib/imap/backup/setup/connection_tester.rb +26 -0
  20. data/lib/imap/backup/{configuration → setup}/folder_chooser.rb +18 -8
  21. data/lib/imap/backup/setup/helpers.rb +15 -0
  22. data/lib/imap/backup/{configuration/setup.rb → setup.rb} +23 -17
  23. data/lib/imap/backup/uploader.rb +2 -2
  24. data/lib/imap/backup/version.rb +2 -2
  25. data/lib/imap/backup.rb +7 -33
  26. data/lib/retry_on_error.rb +1 -1
  27. data/spec/features/backup_spec.rb +1 -0
  28. data/spec/features/support/email_server.rb +5 -2
  29. data/spec/support/higline_test_helpers.rb +1 -1
  30. data/spec/support/silence_logging.rb +1 -1
  31. data/spec/unit/imap/backup/account/connection_spec.rb +14 -9
  32. data/spec/unit/imap/backup/cli/accounts_spec.rb +47 -0
  33. data/spec/unit/imap/backup/cli/local_spec.rb +7 -3
  34. data/spec/unit/imap/backup/cli/utils_spec.rb +15 -5
  35. data/spec/unit/imap/backup/{configuration/store_spec.rb → configuration_spec.rb} +2 -2
  36. data/spec/unit/imap/backup/downloader_spec.rb +1 -1
  37. data/spec/unit/imap/backup/logger_spec.rb +48 -0
  38. data/spec/unit/imap/backup/{configuration → setup}/account_spec.rb +31 -24
  39. data/spec/unit/imap/backup/{configuration → setup}/asker_spec.rb +2 -2
  40. data/spec/unit/imap/backup/{configuration → setup}/connection_tester_spec.rb +10 -10
  41. data/spec/unit/imap/backup/{configuration → setup}/folder_chooser_spec.rb +8 -8
  42. data/spec/unit/imap/backup/{configuration/setup_spec.rb → setup_spec.rb} +48 -40
  43. metadata +49 -46
  44. data/lib/imap/backup/configuration/connection_tester.rb +0 -14
  45. data/lib/imap/backup/configuration/list.rb +0 -53
  46. data/spec/unit/imap/backup/configuration/list_spec.rb +0 -96
  47. data/spec/unit/imap/backup_spec.rb +0 -28
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.7
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -191,6 +191,7 @@ files:
191
191
  - lib/imap/backup/account/connection.rb
192
192
  - lib/imap/backup/account/folder.rb
193
193
  - lib/imap/backup/cli.rb
194
+ - lib/imap/backup/cli/accounts.rb
194
195
  - lib/imap/backup/cli/backup.rb
195
196
  - lib/imap/backup/cli/folders.rb
196
197
  - lib/imap/backup/cli/helpers.rb
@@ -201,18 +202,20 @@ files:
201
202
  - lib/imap/backup/cli/utils.rb
202
203
  - lib/imap/backup/client/apple_mail.rb
203
204
  - lib/imap/backup/client/default.rb
204
- - lib/imap/backup/configuration/account.rb
205
- - lib/imap/backup/configuration/asker.rb
206
- - lib/imap/backup/configuration/connection_tester.rb
207
- - lib/imap/backup/configuration/folder_chooser.rb
208
- - lib/imap/backup/configuration/list.rb
209
- - lib/imap/backup/configuration/setup.rb
210
- - lib/imap/backup/configuration/store.rb
205
+ - lib/imap/backup/configuration.rb
211
206
  - lib/imap/backup/downloader.rb
207
+ - lib/imap/backup/logger.rb
208
+ - lib/imap/backup/sanitizer.rb
212
209
  - lib/imap/backup/serializer.rb
213
210
  - lib/imap/backup/serializer/mbox.rb
214
211
  - lib/imap/backup/serializer/mbox_enumerator.rb
215
212
  - lib/imap/backup/serializer/mbox_store.rb
213
+ - lib/imap/backup/setup.rb
214
+ - lib/imap/backup/setup/account.rb
215
+ - lib/imap/backup/setup/asker.rb
216
+ - lib/imap/backup/setup/connection_tester.rb
217
+ - lib/imap/backup/setup/folder_chooser.rb
218
+ - lib/imap/backup/setup/helpers.rb
216
219
  - lib/imap/backup/thunderbird/mailbox_exporter.rb
217
220
  - lib/imap/backup/uploader.rb
218
221
  - lib/imap/backup/utils.rb
@@ -246,23 +249,23 @@ files:
246
249
  - spec/unit/email/provider_spec.rb
247
250
  - spec/unit/imap/backup/account/connection_spec.rb
248
251
  - spec/unit/imap/backup/account/folder_spec.rb
252
+ - spec/unit/imap/backup/cli/accounts_spec.rb
249
253
  - spec/unit/imap/backup/cli/local_spec.rb
250
254
  - spec/unit/imap/backup/cli/utils_spec.rb
251
255
  - spec/unit/imap/backup/client/default_spec.rb
252
- - spec/unit/imap/backup/configuration/account_spec.rb
253
- - spec/unit/imap/backup/configuration/asker_spec.rb
254
- - spec/unit/imap/backup/configuration/connection_tester_spec.rb
255
- - spec/unit/imap/backup/configuration/folder_chooser_spec.rb
256
- - spec/unit/imap/backup/configuration/list_spec.rb
257
- - spec/unit/imap/backup/configuration/setup_spec.rb
258
- - spec/unit/imap/backup/configuration/store_spec.rb
256
+ - spec/unit/imap/backup/configuration_spec.rb
259
257
  - spec/unit/imap/backup/downloader_spec.rb
258
+ - spec/unit/imap/backup/logger_spec.rb
260
259
  - spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
261
260
  - spec/unit/imap/backup/serializer/mbox_spec.rb
262
261
  - spec/unit/imap/backup/serializer/mbox_store_spec.rb
262
+ - spec/unit/imap/backup/setup/account_spec.rb
263
+ - spec/unit/imap/backup/setup/asker_spec.rb
264
+ - spec/unit/imap/backup/setup/connection_tester_spec.rb
265
+ - spec/unit/imap/backup/setup/folder_chooser_spec.rb
266
+ - spec/unit/imap/backup/setup_spec.rb
263
267
  - spec/unit/imap/backup/uploader_spec.rb
264
268
  - spec/unit/imap/backup/utils_spec.rb
265
- - spec/unit/imap/backup_spec.rb
266
269
  homepage: https://github.com/joeyates/imap-backup
267
270
  licenses:
268
271
  - MIT
@@ -282,46 +285,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
285
  - !ruby/object:Gem::Version
283
286
  version: '0'
284
287
  requirements: []
285
- rubygems_version: 3.1.2
288
+ rubygems_version: 3.1.6
286
289
  signing_key:
287
290
  specification_version: 4
288
291
  summary: Backup GMail (or other IMAP) accounts to disk
289
292
  test_files:
290
- - spec/spec_helper.rb
291
- - spec/fixtures/connection.yml
293
+ - spec/features/helper.rb
294
+ - spec/features/support/backup_directory.rb
295
+ - spec/features/support/shared/message_fixtures.rb
296
+ - spec/features/support/shared/connection_context.rb
297
+ - spec/features/support/email_server.rb
298
+ - spec/features/restore_spec.rb
299
+ - spec/features/backup_spec.rb
300
+ - spec/support/higline_test_helpers.rb
301
+ - spec/support/fixtures.rb
302
+ - spec/support/silence_logging.rb
303
+ - spec/gather_rspec_coverage.rb
292
304
  - spec/unit/email/provider/gmail_spec.rb
293
- - spec/unit/email/provider/apple_mail_spec.rb
294
305
  - spec/unit/email/provider/fastmail_spec.rb
295
306
  - spec/unit/email/provider/base_spec.rb
296
- - spec/unit/email/provider_spec.rb
307
+ - spec/unit/email/provider/apple_mail_spec.rb
297
308
  - spec/unit/email/mboxrd/message_spec.rb
298
- - spec/unit/imap/backup_spec.rb
309
+ - spec/unit/email/provider_spec.rb
299
310
  - spec/unit/imap/backup/cli/utils_spec.rb
311
+ - spec/unit/imap/backup/cli/accounts_spec.rb
300
312
  - spec/unit/imap/backup/cli/local_spec.rb
313
+ - spec/unit/imap/backup/setup/account_spec.rb
314
+ - spec/unit/imap/backup/setup/connection_tester_spec.rb
315
+ - spec/unit/imap/backup/setup/folder_chooser_spec.rb
316
+ - spec/unit/imap/backup/setup/asker_spec.rb
317
+ - spec/unit/imap/backup/uploader_spec.rb
301
318
  - spec/unit/imap/backup/utils_spec.rb
302
- - spec/unit/imap/backup/client/default_spec.rb
319
+ - spec/unit/imap/backup/configuration_spec.rb
320
+ - spec/unit/imap/backup/setup_spec.rb
321
+ - spec/unit/imap/backup/logger_spec.rb
322
+ - spec/unit/imap/backup/serializer/mbox_store_spec.rb
323
+ - spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
324
+ - spec/unit/imap/backup/serializer/mbox_spec.rb
303
325
  - spec/unit/imap/backup/downloader_spec.rb
304
- - spec/unit/imap/backup/configuration/store_spec.rb
305
- - spec/unit/imap/backup/configuration/connection_tester_spec.rb
306
- - spec/unit/imap/backup/configuration/asker_spec.rb
307
- - spec/unit/imap/backup/configuration/setup_spec.rb
308
- - spec/unit/imap/backup/configuration/folder_chooser_spec.rb
309
- - spec/unit/imap/backup/configuration/account_spec.rb
310
- - spec/unit/imap/backup/configuration/list_spec.rb
311
326
  - spec/unit/imap/backup/account/folder_spec.rb
312
327
  - spec/unit/imap/backup/account/connection_spec.rb
313
- - spec/unit/imap/backup/serializer/mbox_spec.rb
314
- - spec/unit/imap/backup/serializer/mbox_store_spec.rb
315
- - spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
316
- - spec/unit/imap/backup/uploader_spec.rb
317
- - spec/support/fixtures.rb
318
- - spec/support/higline_test_helpers.rb
319
- - spec/support/silence_logging.rb
320
- - spec/gather_rspec_coverage.rb
321
- - spec/features/backup_spec.rb
322
- - spec/features/helper.rb
323
- - spec/features/support/backup_directory.rb
324
- - spec/features/support/shared/message_fixtures.rb
325
- - spec/features/support/shared/connection_context.rb
326
- - spec/features/support/email_server.rb
327
- - spec/features/restore_spec.rb
328
+ - spec/unit/imap/backup/client/default_spec.rb
329
+ - spec/spec_helper.rb
330
+ - spec/fixtures/connection.yml
@@ -1,14 +0,0 @@
1
- module Imap::Backup
2
- module Configuration; end
3
-
4
- module Configuration::ConnectionTester
5
- def self.test(account)
6
- Account::Connection.new(account).client
7
- "Connection successful"
8
- rescue Net::IMAP::NoResponseError
9
- "No response"
10
- rescue StandardError => e
11
- "Unexpected error: #{e}"
12
- end
13
- end
14
- end
@@ -1,53 +0,0 @@
1
- module Imap::Backup
2
- module Configuration; end
3
-
4
- class Configuration::List
5
- attr_reader :required_accounts
6
-
7
- def initialize(required_accounts = [])
8
- @required_accounts = required_accounts
9
- end
10
-
11
- def setup_logging
12
- return if !config_exists?
13
-
14
- Imap::Backup.setup_logging config
15
- Net::IMAP.debug = config.debug?
16
- end
17
-
18
- def each_connection
19
- accounts.each do |account|
20
- connection = Account::Connection.new(account)
21
- yield connection
22
- connection.disconnect
23
- end
24
- end
25
-
26
- def accounts
27
- @accounts ||=
28
- if required_accounts.empty?
29
- config.accounts
30
- else
31
- config.accounts.select do |account|
32
- required_accounts.include?(account.username)
33
- end
34
- end
35
- end
36
-
37
- private
38
-
39
- def config
40
- return @config if @config
41
-
42
- if !config_exists?
43
- path = Configuration::Store.default_pathname
44
- raise ConfigurationNotFound, "Configuration file '#{path}' not found"
45
- end
46
- @config = Configuration::Store.new
47
- end
48
-
49
- def config_exists?
50
- Configuration::Store.exist?
51
- end
52
- end
53
- end
@@ -1,96 +0,0 @@
1
- describe Imap::Backup::Configuration::List do
2
- subject { described_class.new }
3
-
4
- let(:accounts) { [account1, account2] }
5
- let(:account1) do
6
- instance_double(
7
- Imap::Backup::Account,
8
- username: "a1@example.com"
9
- )
10
- end
11
- let(:account2) do
12
- instance_double(
13
- Imap::Backup::Account,
14
- username: "a2@example.com"
15
- )
16
- end
17
- let(:store) do
18
- instance_double(Imap::Backup::Configuration::Store, accounts: accounts)
19
- end
20
- let(:exists) { true }
21
- let(:connection1) do
22
- instance_double(Imap::Backup::Account::Connection, disconnect: nil)
23
- end
24
- let(:connection2) do
25
- instance_double(Imap::Backup::Account::Connection, disconnect: nil)
26
- end
27
-
28
- before do
29
- allow(Imap::Backup::Configuration::Store).to receive(:new) { store }
30
- allow(Imap::Backup::Configuration::Store).
31
- to receive(:exist?) { exists }
32
- allow(Imap::Backup::Account::Connection).
33
- to receive(:new).with(accounts[0]) { connection1 }
34
- allow(Imap::Backup::Account::Connection).
35
- to receive(:new).with(accounts[1]) { connection2 }
36
- end
37
-
38
- describe "#setup_logging" do
39
- let(:config_exists) { true }
40
-
41
- before do
42
- allow(Imap::Backup::Configuration::Store).
43
- to receive(:exist?) { config_exists }
44
- allow(Imap::Backup).to receive(:setup_logging)
45
- allow(store).to receive(:debug?)
46
- end
47
-
48
- it "sets global logging level" do
49
- expect(Imap::Backup).to receive(:setup_logging).with(store)
50
-
51
- subject.setup_logging
52
- end
53
-
54
- context "without a config" do
55
- let(:config_exists) { false }
56
-
57
- it "does nothing" do
58
- expect(Imap::Backup).to_not receive(:setup_logging).with(store)
59
-
60
- subject.setup_logging
61
- end
62
- end
63
- end
64
-
65
- describe "#each_connection" do
66
- specify "calls the block with each account's connection" do
67
- connections = []
68
-
69
- subject.each_connection { |a| connections << a }
70
-
71
- expect(connections).to eq([connection1, connection2])
72
- end
73
-
74
- context "with account parameter" do
75
- subject { described_class.new(["a2@example.com"]) }
76
-
77
- it "only creates requested accounts" do
78
- connections = []
79
-
80
- subject.each_connection { |a| connections << a }
81
-
82
- expect(connections).to eq([connection2])
83
- end
84
- end
85
-
86
- context "when the configuration file is missing" do
87
- let(:exists) { false }
88
-
89
- it "fails" do
90
- expect do
91
- subject.each_connection {}
92
- end.to raise_error(Imap::Backup::ConfigurationNotFound, /not found/)
93
- end
94
- end
95
- end
96
- end
@@ -1,28 +0,0 @@
1
- require "ostruct"
2
- require "imap/backup"
3
-
4
- describe Imap::Backup do
5
- describe ".setup_logging" do
6
- let!(:previous) { described_class.logger.level }
7
-
8
- before { described_class.setup_logging(config) }
9
-
10
- after { described_class.logger.level = previous }
11
-
12
- context "when config.debug?" do
13
- let(:config) { OpenStruct.new(debug?: true) }
14
-
15
- it "sets logger level to debug" do
16
- expect(described_class.logger.level).to eq(::Logger::Severity::DEBUG)
17
- end
18
- end
19
-
20
- context "when not config.debug?" do
21
- let(:config) { OpenStruct.new(debug?: false) }
22
-
23
- it "sets logger level to debug" do
24
- expect(described_class.logger.level).to eq(::Logger::Severity::ERROR)
25
- end
26
- end
27
- end
28
- end