imap-backup 2.0.0 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rspec-all +2 -0
  4. data/.rubocop.yml +15 -2
  5. data/.rubocop_todo.yml +58 -0
  6. data/.travis.yml +15 -2
  7. data/README.md +14 -22
  8. data/Rakefile +6 -3
  9. data/bin/imap-backup +5 -11
  10. data/imap-backup.gemspec +10 -6
  11. data/lib/email/mboxrd/message.rb +16 -16
  12. data/lib/imap/backup/account/connection.rb +38 -22
  13. data/lib/imap/backup/account/folder.rb +23 -7
  14. data/lib/imap/backup/configuration/account.rb +25 -21
  15. data/lib/imap/backup/configuration/asker.rb +3 -2
  16. data/lib/imap/backup/configuration/connection_tester.rb +1 -1
  17. data/lib/imap/backup/configuration/folder_chooser.rb +32 -5
  18. data/lib/imap/backup/configuration/list.rb +2 -0
  19. data/lib/imap/backup/configuration/setup.rb +2 -1
  20. data/lib/imap/backup/configuration/store.rb +3 -6
  21. data/lib/imap/backup/downloader.rb +8 -7
  22. data/lib/imap/backup/serializer/mbox.rb +44 -25
  23. data/lib/imap/backup/serializer/mbox_enumerator.rb +31 -0
  24. data/lib/imap/backup/serializer/mbox_store.rb +35 -32
  25. data/lib/imap/backup/uploader.rb +11 -2
  26. data/lib/imap/backup/utils.rb +11 -9
  27. data/lib/imap/backup/version.rb +2 -2
  28. data/spec/features/backup_spec.rb +6 -5
  29. data/spec/features/helper.rb +1 -1
  30. data/spec/features/restore_spec.rb +75 -27
  31. data/spec/features/support/backup_directory.rb +7 -7
  32. data/spec/features/support/email_server.rb +15 -11
  33. data/spec/features/support/shared/connection_context.rb +2 -2
  34. data/spec/features/support/shared/message_fixtures.rb +8 -0
  35. data/spec/spec_helper.rb +1 -1
  36. data/spec/support/fixtures.rb +2 -2
  37. data/spec/support/higline_test_helpers.rb +1 -1
  38. data/spec/unit/email/mboxrd/message_spec.rb +73 -53
  39. data/spec/unit/email/provider_spec.rb +3 -5
  40. data/spec/unit/imap/backup/account/connection_spec.rb +82 -59
  41. data/spec/unit/imap/backup/account/folder_spec.rb +75 -37
  42. data/spec/unit/imap/backup/configuration/account_spec.rb +95 -61
  43. data/spec/unit/imap/backup/configuration/asker_spec.rb +43 -45
  44. data/spec/unit/imap/backup/configuration/connection_tester_spec.rb +21 -22
  45. data/spec/unit/imap/backup/configuration/folder_chooser_spec.rb +66 -33
  46. data/spec/unit/imap/backup/configuration/list_spec.rb +32 -11
  47. data/spec/unit/imap/backup/configuration/setup_spec.rb +97 -56
  48. data/spec/unit/imap/backup/configuration/store_spec.rb +30 -25
  49. data/spec/unit/imap/backup/downloader_spec.rb +28 -26
  50. data/spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb +45 -0
  51. data/spec/unit/imap/backup/serializer/mbox_spec.rb +109 -51
  52. data/spec/unit/imap/backup/serializer/mbox_store_spec.rb +232 -20
  53. data/spec/unit/imap/backup/uploader_spec.rb +23 -9
  54. data/spec/unit/imap/backup/utils_spec.rb +14 -15
  55. data/spec/unit/imap/backup_spec.rb +28 -0
  56. metadata +13 -7
@@ -1,10 +1,10 @@
1
- require "spec_helper"
2
-
3
1
  describe Imap::Backup::Uploader do
4
2
  subject { described_class.new(folder, serializer) }
5
3
 
6
4
  let(:folder) do
7
- instance_double(Imap::Backup::Account::Folder, uids: [2, 3], append: 99)
5
+ instance_double(
6
+ Imap::Backup::Account::Folder, uids: [2, 3], append: 99, name: "foo"
7
+ )
8
8
  end
9
9
  let(:serializer) do
10
10
  instance_double(
@@ -13,27 +13,41 @@ describe Imap::Backup::Uploader do
13
13
  update_uid: nil
14
14
  )
15
15
  end
16
+ let(:missing_message) do
17
+ instance_double(Email::Mboxrd::Message, supplied_body: "missing message")
18
+ end
19
+ let(:existing_message) do
20
+ instance_double(Email::Mboxrd::Message, supplied_body: "existing message")
21
+ end
22
+
23
+ def message_enumerator
24
+ yield [1, missing_message]
25
+ end
16
26
 
17
27
  describe "#run" do
18
28
  before do
19
- allow(serializer).to receive(:load).with(1) { "missing message" }
20
- allow(serializer).to receive(:load).with(2) { "existing message" }
21
- subject.run
29
+ allow(serializer).to receive(:each_message).and_return(enum_for(:message_enumerator))
22
30
  end
23
31
 
24
32
  context "with messages that are missing" do
25
33
  it "restores them" do
26
- expect(folder).to have_received(:append).with("missing message")
34
+ expect(folder).to receive(:append).with(missing_message)
35
+
36
+ subject.run
27
37
  end
28
38
 
29
39
  it "updates the local message id" do
30
- expect(serializer).to have_received(:update_uid).with(1, 99)
40
+ expect(serializer).to receive(:update_uid).with(1, 99)
41
+
42
+ subject.run
31
43
  end
32
44
  end
33
45
 
34
46
  context "with messages that are present on server" do
35
47
  it "does nothing" do
36
- expect(folder).to_not have_received(:append).with("existing message")
48
+ expect(folder).to_not receive(:append).with(existing_message)
49
+
50
+ subject.run
37
51
  end
38
52
  end
39
53
  end
@@ -1,19 +1,18 @@
1
- require "spec_helper"
2
-
3
1
  describe Imap::Backup::Utils do
4
2
  let(:filename) { "foobar" }
5
- let(:stat) { double("File::Stat", mode: mode) }
3
+ let(:stat) { instance_double(File::Stat, mode: mode) }
6
4
  let(:mode) { 0o777 }
7
5
  let(:exists) { true }
8
6
 
9
7
  before do
10
- allow(File).to receive(:stat).and_return(stat)
11
- allow(File).to receive(:exist?).with(filename).and_return(exists)
8
+ allow(File).to receive(:stat) { stat }
9
+ allow(File).to receive(:exist?).with(filename) { exists }
12
10
  end
13
11
 
14
- context ".check_permissions" do
12
+ describe ".check_permissions" do
15
13
  let(:requested) { 0o345 }
16
14
 
15
+ # rubocop:disable RSpec/EmptyExampleGroup
17
16
  context "with existing files" do
18
17
  [
19
18
  [0o100, "less than the limit", true],
@@ -38,6 +37,7 @@ describe Imap::Backup::Utils do
38
37
  end
39
38
  end
40
39
  end
40
+ # rubocop:enable RSpec/EmptyExampleGroup
41
41
 
42
42
  context "with non-existent files" do
43
43
  let(:exists) { false }
@@ -49,7 +49,7 @@ describe Imap::Backup::Utils do
49
49
  end
50
50
  end
51
51
 
52
- context ".mode" do
52
+ describe ".mode" do
53
53
  context "with existing files" do
54
54
  let(:mode) { 0o2345 }
55
55
 
@@ -67,29 +67,28 @@ describe Imap::Backup::Utils do
67
67
  end
68
68
  end
69
69
 
70
- context ".make_folder" do
70
+ describe ".make_folder" do
71
71
  before do
72
72
  allow(FileUtils).to receive(:mkdir_p)
73
73
  allow(FileUtils).to receive(:chmod)
74
74
  end
75
75
 
76
76
  it "does nothing if an empty path is supplied" do
77
- described_class.make_folder("aaa", "", 0o222)
77
+ expect(FileUtils).to_not receive(:mkdir_p)
78
78
 
79
- expect(FileUtils).to_not have_received(:mkdir_p)
79
+ described_class.make_folder("aaa", "", 0o222)
80
80
  end
81
81
 
82
82
  it "creates the path" do
83
- described_class.make_folder("/base/path", "new/folder", 0o222)
83
+ expect(FileUtils).to receive(:mkdir_p).with("/base/path/new/folder")
84
84
 
85
- expect(FileUtils).to have_received(:mkdir_p).with("/base/path/new/folder")
85
+ described_class.make_folder("/base/path", "new/folder", 0o222)
86
86
  end
87
87
 
88
88
  it "sets permissions on the path" do
89
- described_class.make_folder("/base/path/new", "folder", 0o222)
89
+ expect(FileUtils).to receive(:chmod).with(0o222, "/base/path/new/folder")
90
90
 
91
- expect(FileUtils).
92
- to have_received(:chmod).with(0o222, "/base/path/new/folder")
91
+ described_class.make_folder("/base/path/new", "folder", 0o222)
93
92
  end
94
93
  end
95
94
  end
@@ -0,0 +1,28 @@
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
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-10 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: highline
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: highline
28
+ name: mail
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mail
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -134,6 +134,7 @@ files:
134
134
  - ".rspec"
135
135
  - ".rspec-all"
136
136
  - ".rubocop.yml"
137
+ - ".rubocop_todo.yml"
137
138
  - ".travis.yml"
138
139
  - Gemfile
139
140
  - LICENSE
@@ -158,6 +159,7 @@ files:
158
159
  - lib/imap/backup/downloader.rb
159
160
  - lib/imap/backup/serializer.rb
160
161
  - lib/imap/backup/serializer/mbox.rb
162
+ - lib/imap/backup/serializer/mbox_enumerator.rb
161
163
  - lib/imap/backup/serializer/mbox_store.rb
162
164
  - lib/imap/backup/uploader.rb
163
165
  - lib/imap/backup/utils.rb
@@ -188,10 +190,12 @@ files:
188
190
  - spec/unit/imap/backup/configuration/setup_spec.rb
189
191
  - spec/unit/imap/backup/configuration/store_spec.rb
190
192
  - spec/unit/imap/backup/downloader_spec.rb
193
+ - spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
191
194
  - spec/unit/imap/backup/serializer/mbox_spec.rb
192
195
  - spec/unit/imap/backup/serializer/mbox_store_spec.rb
193
196
  - spec/unit/imap/backup/uploader_spec.rb
194
197
  - spec/unit/imap/backup/utils_spec.rb
198
+ - spec/unit/imap/backup_spec.rb
195
199
  - tmp/.gitkeep
196
200
  homepage: https://github.com/joeyates/imap-backup
197
201
  licenses: []
@@ -208,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
212
  requirements:
209
213
  - - ">="
210
214
  - !ruby/object:Gem::Version
211
- version: 2.2.0
215
+ version: 2.4.0
212
216
  required_rubygems_version: !ruby/object:Gem::Requirement
213
217
  requirements:
214
218
  - - ">="
215
219
  - !ruby/object:Gem::Version
216
220
  version: '0'
217
221
  requirements: []
218
- rubygems_version: 3.0.3
222
+ rubygems_version: 3.1.2
219
223
  signing_key:
220
224
  specification_version: 4
221
225
  summary: Backup GMail (or other IMAP) accounts to disk
@@ -246,7 +250,9 @@ test_files:
246
250
  - spec/unit/imap/backup/configuration/setup_spec.rb
247
251
  - spec/unit/imap/backup/configuration/store_spec.rb
248
252
  - spec/unit/imap/backup/downloader_spec.rb
253
+ - spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
249
254
  - spec/unit/imap/backup/serializer/mbox_spec.rb
250
255
  - spec/unit/imap/backup/serializer/mbox_store_spec.rb
251
256
  - spec/unit/imap/backup/uploader_spec.rb
252
257
  - spec/unit/imap/backup/utils_spec.rb
258
+ - spec/unit/imap/backup_spec.rb