imap-backup 2.1.1 → 3.0.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -4
- data/.rubocop_todo.yml +29 -11
- data/.travis.yml +1 -1
- data/README.md +10 -13
- data/bin/imap-backup +5 -2
- data/docs/01-credentials-screen.png +0 -0
- data/docs/02-new-project.png +0 -0
- data/docs/03-initial-credentials-for-project.png +0 -0
- data/docs/04-credential-type-selection.png +0 -0
- data/docs/05-cant-create-without-consent-setup.png +0 -0
- data/docs/06-user-type-selection.png +0 -0
- data/docs/07-consent-screen-form.png +0 -0
- data/docs/08-app-scopes.png +0 -0
- data/docs/09-scope-selection.png +0 -0
- data/docs/10-updated-app-scopes.png +0 -0
- data/docs/11-test-users.png +0 -0
- data/docs/12-add-users.png +0 -0
- data/docs/13-create-oauth-client.png +0 -0
- data/docs/14-application-details.png +0 -0
- data/docs/16-initial-menu.png +0 -0
- data/docs/17-inputting-the-email-address.png +0 -0
- data/docs/18-choose-password.png +0 -0
- data/docs/19-supply-client-info.png +0 -0
- data/docs/20-choose-gmail-account.png +0 -0
- data/docs/21-accept-warnings.png +0 -0
- data/docs/22-grant-access.png +0 -0
- data/docs/24-confirm-choices.png +0 -0
- data/docs/25-success-code.png +0 -0
- data/docs/26-type-code-into-imap-backup.png +0 -0
- data/docs/27-success.png +0 -0
- data/docs/setting-up-gmail.md +166 -0
- data/imap-backup.gemspec +3 -9
- data/lib/email/mboxrd/message.rb +4 -3
- data/lib/email/provider.rb +3 -1
- data/lib/gmail/authenticator.rb +160 -0
- data/lib/google/auth/stores/in_memory_token_store.rb +9 -0
- data/lib/imap/backup.rb +2 -1
- data/lib/imap/backup/account/connection.rb +59 -34
- data/lib/imap/backup/account/folder.rb +10 -1
- data/lib/imap/backup/configuration/account.rb +9 -1
- data/lib/imap/backup/configuration/gmail_oauth2.rb +82 -0
- data/lib/imap/backup/configuration/setup.rb +4 -1
- data/lib/imap/backup/serializer/mbox.rb +4 -0
- data/lib/imap/backup/serializer/mbox_enumerator.rb +1 -1
- data/lib/imap/backup/serializer/mbox_store.rb +20 -4
- data/lib/imap/backup/uploader.rb +10 -2
- data/lib/imap/backup/version.rb +5 -4
- data/spec/features/backup_spec.rb +3 -3
- data/spec/features/helper.rb +1 -1
- data/spec/features/restore_spec.rb +75 -27
- data/spec/features/support/backup_directory.rb +2 -2
- data/spec/features/support/email_server.rb +1 -3
- data/spec/features/support/shared/message_fixtures.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/fixtures.rb +1 -1
- data/spec/unit/email/mboxrd/message_spec.rb +2 -8
- data/spec/unit/email/provider_spec.rb +2 -2
- data/spec/unit/gmail/authenticator_spec.rb +138 -0
- data/spec/unit/google/auth/stores/in_memory_token_store_spec.rb +15 -0
- data/spec/unit/imap/backup/account/connection_spec.rb +157 -79
- data/spec/unit/imap/backup/account/folder_spec.rb +30 -20
- data/spec/unit/imap/backup/configuration/account_spec.rb +65 -46
- data/spec/unit/imap/backup/configuration/asker_spec.rb +20 -17
- data/spec/unit/imap/backup/configuration/connection_tester_spec.rb +6 -10
- data/spec/unit/imap/backup/configuration/folder_chooser_spec.rb +16 -10
- data/spec/unit/imap/backup/configuration/gmail_oauth2_spec.rb +84 -0
- data/spec/unit/imap/backup/configuration/list_spec.rb +6 -3
- data/spec/unit/imap/backup/configuration/setup_spec.rb +89 -54
- data/spec/unit/imap/backup/configuration/store_spec.rb +18 -16
- data/spec/unit/imap/backup/downloader_spec.rb +14 -14
- data/spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb +6 -1
- data/spec/unit/imap/backup/serializer/mbox_spec.rb +62 -40
- data/spec/unit/imap/backup/serializer/mbox_store_spec.rb +94 -35
- data/spec/unit/imap/backup/uploader_spec.rb +23 -7
- data/spec/unit/imap/backup/utils_spec.rb +10 -9
- metadata +68 -9
@@ -7,37 +7,37 @@ describe Imap::Backup::Downloader do
|
|
7
7
|
instance_double(
|
8
8
|
Imap::Backup::Account::Folder,
|
9
9
|
fetch: message,
|
10
|
-
name: "folder"
|
10
|
+
name: "folder",
|
11
|
+
uids: folder_uids
|
11
12
|
)
|
12
13
|
end
|
13
14
|
let(:folder_uids) { %w(111 222 333) }
|
14
15
|
let(:serializer) do
|
15
|
-
instance_double(Imap::Backup::Serializer::Mbox, save: nil)
|
16
|
-
end
|
17
|
-
let(:serializer_uids) { ["222"] }
|
18
|
-
|
19
|
-
before do
|
20
|
-
allow(folder).to receive(:uids).and_return(folder_uids)
|
21
|
-
allow(serializer).to receive(:uids).and_return(serializer_uids)
|
22
|
-
allow(folder).to receive(:fetch).with("333").and_return(nil)
|
23
|
-
subject.run
|
16
|
+
instance_double(Imap::Backup::Serializer::Mbox, save: nil, uids: ["222"])
|
24
17
|
end
|
25
18
|
|
26
19
|
context "with fetched messages" do
|
27
|
-
|
28
|
-
expect(serializer).to
|
20
|
+
specify "are saved" do
|
21
|
+
expect(serializer).to receive(:save).with("111", message)
|
22
|
+
|
23
|
+
subject.run
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
32
27
|
context "with messages which are already present" do
|
33
28
|
specify "are skipped" do
|
34
|
-
expect(serializer).to_not
|
29
|
+
expect(serializer).to_not receive(:save).with("222", anything)
|
30
|
+
|
31
|
+
subject.run
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
context "with failed fetches" do
|
39
36
|
specify "are skipped" do
|
40
|
-
|
37
|
+
allow(folder).to receive(:fetch).with("333") { nil }
|
38
|
+
expect(serializer).to_not receive(:save).with("333", anything)
|
39
|
+
|
40
|
+
subject.run
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -21,11 +21,16 @@ describe Imap::Backup::Serializer::MboxEnumerator do
|
|
21
21
|
|
22
22
|
before do
|
23
23
|
allow(File).to receive(:open).and_call_original
|
24
|
-
allow(File).to receive(:open).with(mbox_pathname).and_yield(mbox_file)
|
24
|
+
allow(File).to receive(:open).with(mbox_pathname, "rb").and_yield(mbox_file)
|
25
25
|
allow(mbox_file).to receive(:gets).and_return(*lines)
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#each" do
|
29
|
+
it "reads files as binary" do
|
30
|
+
expect(File).to receive(:open).with(mbox_pathname, "rb")
|
31
|
+
subject.each {}
|
32
|
+
end
|
33
|
+
|
29
34
|
it "yields messages" do
|
30
35
|
expect { |b| subject.each(&b) }.
|
31
36
|
to yield_successive_args(message1.join, message2.join)
|
@@ -28,8 +28,6 @@ describe Imap::Backup::Serializer::Mbox do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "folder path" do
|
31
|
-
before { subject.uids }
|
32
|
-
|
33
31
|
context "when it has multiple elements" do
|
34
32
|
let(:imap_folder) { "folder/path" }
|
35
33
|
|
@@ -37,8 +35,10 @@ describe Imap::Backup::Serializer::Mbox do
|
|
37
35
|
let(:dir_exists) { false }
|
38
36
|
|
39
37
|
it "is created" do
|
40
|
-
expect(Imap::Backup::Utils).to
|
38
|
+
expect(Imap::Backup::Utils).to receive(:make_folder).
|
41
39
|
with(base_path, File.dirname(imap_folder), 0o700)
|
40
|
+
|
41
|
+
subject.uids
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -48,57 +48,66 @@ describe Imap::Backup::Serializer::Mbox do
|
|
48
48
|
|
49
49
|
it "corrects them" do
|
50
50
|
path = File.expand_path(File.join(base_path, File.dirname(imap_folder)))
|
51
|
-
expect(FileUtils).to
|
51
|
+
expect(FileUtils).to receive(:chmod).with(0o700, path)
|
52
|
+
|
53
|
+
subject.uids
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
57
|
context "when permissons are correct" do
|
56
58
|
it "does nothing" do
|
57
|
-
expect(FileUtils).to_not
|
59
|
+
expect(FileUtils).to_not receive(:chmod)
|
60
|
+
|
61
|
+
subject.uids
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
65
|
context "when it exists" do
|
62
66
|
it "is not created" do
|
63
|
-
expect(Imap::Backup::Utils).to_not
|
67
|
+
expect(Imap::Backup::Utils).to_not receive(:make_folder).
|
64
68
|
with(base_path, File.dirname(imap_folder), 0o700)
|
69
|
+
|
70
|
+
subject.uids
|
65
71
|
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
75
|
describe "#apply_uid_validity" do
|
70
|
-
let(:result) { subject.apply_uid_validity("aaa") }
|
71
|
-
|
72
76
|
context "when the existing uid validity is unset" do
|
73
|
-
let!(:result) { super() }
|
74
|
-
|
75
77
|
it "sets uid validity" do
|
76
|
-
expect(store).to
|
78
|
+
expect(store).to receive(:uid_validity=).with("aaa")
|
79
|
+
|
80
|
+
subject.apply_uid_validity("aaa")
|
77
81
|
end
|
78
82
|
|
79
83
|
it "does not rename the store" do
|
80
|
-
expect(store).to_not
|
84
|
+
expect(store).to_not receive(:rename)
|
85
|
+
|
86
|
+
subject.apply_uid_validity("aaa")
|
81
87
|
end
|
82
88
|
|
83
89
|
it "returns nil" do
|
84
|
-
expect(
|
90
|
+
expect(subject.apply_uid_validity("aaa")).to be_nil
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
88
94
|
context "when the uid validity is unchanged" do
|
89
|
-
let!(:result) { super() }
|
90
95
|
let(:existing_uid_validity) { "aaa" }
|
91
96
|
|
92
97
|
it "does not set uid validity" do
|
93
|
-
expect(store).to_not
|
98
|
+
expect(store).to_not receive(:uid_validity=)
|
99
|
+
|
100
|
+
subject.apply_uid_validity("aaa")
|
94
101
|
end
|
95
102
|
|
96
103
|
it "does not rename the store" do
|
97
|
-
expect(store).to_not
|
104
|
+
expect(store).to_not receive(:rename)
|
105
|
+
|
106
|
+
subject.apply_uid_validity("aaa")
|
98
107
|
end
|
99
108
|
|
100
109
|
it "returns nil" do
|
101
|
-
expect(
|
110
|
+
expect(subject.apply_uid_validity("aaa")).to be_nil
|
102
111
|
end
|
103
112
|
end
|
104
113
|
|
@@ -113,20 +122,23 @@ describe Imap::Backup::Serializer::Mbox do
|
|
113
122
|
allow(Imap::Backup::Serializer::MboxStore).
|
114
123
|
to receive(:new).with(anything, /bbb/) { existing_store }
|
115
124
|
allow(existing_store).to receive(:exist?).and_return(exists, false)
|
116
|
-
result
|
117
125
|
end
|
118
126
|
|
119
127
|
it "sets uid validity" do
|
120
|
-
expect(store).to
|
128
|
+
expect(store).to receive(:uid_validity=).with("aaa")
|
129
|
+
|
130
|
+
subject.apply_uid_validity("aaa")
|
121
131
|
end
|
122
132
|
|
123
133
|
context "when adding the uid validity does not cause a name clash" do
|
124
134
|
it "renames the store, adding the existing uid validity" do
|
125
|
-
expect(store).to
|
135
|
+
expect(store).to receive(:rename).with("folder.bbb")
|
136
|
+
|
137
|
+
subject.apply_uid_validity("aaa")
|
126
138
|
end
|
127
139
|
|
128
140
|
it "returns the new name" do
|
129
|
-
expect(
|
141
|
+
expect(subject.apply_uid_validity("aaa")).to eq("folder.bbb")
|
130
142
|
end
|
131
143
|
end
|
132
144
|
|
@@ -134,67 +146,77 @@ describe Imap::Backup::Serializer::Mbox do
|
|
134
146
|
let(:exists) { true }
|
135
147
|
|
136
148
|
it "renames the store, adding the existing uid validity and a digit" do
|
137
|
-
expect(store).to
|
149
|
+
expect(store).to receive(:rename).with("folder.bbb.1")
|
150
|
+
|
151
|
+
subject.apply_uid_validity("aaa")
|
138
152
|
end
|
139
153
|
|
140
154
|
it "returns the new name" do
|
141
|
-
expect(
|
155
|
+
expect(subject.apply_uid_validity("aaa")).to eq("folder.bbb.1")
|
142
156
|
end
|
143
157
|
end
|
144
158
|
end
|
145
159
|
end
|
146
160
|
|
147
161
|
describe "#force_uid_validity" do
|
148
|
-
before { subject.force_uid_validity("66") }
|
149
|
-
|
150
162
|
it "sets the uid_validity" do
|
151
|
-
expect(store).to
|
163
|
+
expect(store).to receive(:uid_validity=).with("66")
|
164
|
+
|
165
|
+
subject.force_uid_validity("66")
|
152
166
|
end
|
153
167
|
end
|
154
168
|
|
155
169
|
describe "#uids" do
|
156
170
|
it "calls the store" do
|
157
|
-
|
171
|
+
expect(store).to receive(:uids)
|
158
172
|
|
159
|
-
|
173
|
+
subject.uids
|
160
174
|
end
|
161
175
|
end
|
162
176
|
|
163
177
|
describe "#load" do
|
164
|
-
let(:result) { subject.load("66") }
|
165
|
-
|
166
178
|
before { allow(store).to receive(:load).with("66") { "xxx" } }
|
167
179
|
|
168
180
|
it "returns the value loaded by the store" do
|
169
|
-
expect(
|
181
|
+
expect(subject.load("66")).to eq("xxx")
|
170
182
|
end
|
171
183
|
end
|
172
184
|
|
173
|
-
describe "#
|
174
|
-
|
185
|
+
describe "#each_message" do
|
186
|
+
it "calls the store" do
|
187
|
+
expect(store).to receive(:each_message).with([1])
|
188
|
+
|
189
|
+
subject.each_message([1])
|
190
|
+
end
|
191
|
+
end
|
175
192
|
|
193
|
+
describe "#save" do
|
176
194
|
it "calls the store" do
|
177
|
-
expect(store).to
|
195
|
+
expect(store).to receive(:add).with("foo", "bar")
|
196
|
+
|
197
|
+
subject.save("foo", "bar")
|
178
198
|
end
|
179
199
|
end
|
180
200
|
|
181
201
|
describe "#rename" do
|
182
|
-
before { subject.rename("foo") }
|
183
|
-
|
184
202
|
it "calls the store" do
|
185
|
-
expect(store).to
|
203
|
+
expect(store).to receive(:rename).with("foo")
|
204
|
+
|
205
|
+
subject.rename("foo")
|
186
206
|
end
|
187
207
|
|
188
208
|
it "updates the folder name" do
|
209
|
+
subject.rename("foo")
|
210
|
+
|
189
211
|
expect(subject.folder).to eq("foo")
|
190
212
|
end
|
191
213
|
end
|
192
214
|
|
193
215
|
describe "#update_uid" do
|
194
|
-
before { subject.update_uid("foo", "bar") }
|
195
|
-
|
196
216
|
it "calls the store" do
|
197
|
-
expect(store).to
|
217
|
+
expect(store).to receive(:update_uid).with("foo", "bar")
|
218
|
+
|
219
|
+
subject.update_uid("foo", "bar")
|
198
220
|
end
|
199
221
|
end
|
200
222
|
end
|
@@ -4,10 +4,10 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
4
4
|
let(:base_path) { "/base/path" }
|
5
5
|
let(:folder) { "the/folder" }
|
6
6
|
let(:folder_path) { File.join(base_path, folder) }
|
7
|
-
let(:imap_pathname) { folder_path
|
7
|
+
let(:imap_pathname) { "#{folder_path}.imap" }
|
8
8
|
let(:imap_exists) { true }
|
9
9
|
let(:imap_file) { instance_double(File, write: nil, close: nil) }
|
10
|
-
let(:mbox_pathname) { folder_path
|
10
|
+
let(:mbox_pathname) { "#{folder_path}.mbox" }
|
11
11
|
let(:mbox_exists) { true }
|
12
12
|
let(:mbox_file) { instance_double(File, write: nil, close: nil) }
|
13
13
|
let(:uids) { [3, 2, 1] }
|
@@ -51,14 +51,16 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
51
51
|
}.to_json
|
52
52
|
end
|
53
53
|
|
54
|
-
before { subject.uid_validity = new_uid_validity }
|
55
|
-
|
56
54
|
it "sets uid_validity" do
|
55
|
+
subject.uid_validity = new_uid_validity
|
56
|
+
|
57
57
|
expect(subject.uid_validity).to eq(new_uid_validity)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "writes the imap file" do
|
61
|
-
expect(imap_file).to
|
61
|
+
expect(imap_file).to receive(:write).with(updated_imap_content)
|
62
|
+
|
63
|
+
subject.uid_validity = new_uid_validity
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -80,22 +82,26 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
80
82
|
allow(JSON).to receive(:parse).and_raise(JSON::ParserError)
|
81
83
|
end
|
82
84
|
|
83
|
-
let!(:result) { subject.uids }
|
84
|
-
|
85
85
|
it "returns an empty Array" do
|
86
|
-
expect(
|
86
|
+
expect(subject.uids).to eq([])
|
87
87
|
end
|
88
88
|
|
89
89
|
it "deletes the imap file" do
|
90
|
-
expect(File).to
|
90
|
+
expect(File).to receive(:unlink).with(imap_pathname)
|
91
|
+
|
92
|
+
subject.uids
|
91
93
|
end
|
92
94
|
|
93
95
|
it "deletes the mbox file" do
|
94
|
-
expect(File).to
|
96
|
+
expect(File).to receive(:unlink).with(mbox_pathname)
|
97
|
+
|
98
|
+
subject.uids
|
95
99
|
end
|
96
100
|
|
97
101
|
it "writes a blank mbox file" do
|
98
|
-
expect(mbox_file).to
|
102
|
+
expect(mbox_file).to receive(:write).with("")
|
103
|
+
|
104
|
+
subject.uids
|
99
105
|
end
|
100
106
|
end
|
101
107
|
|
@@ -126,28 +132,29 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
126
132
|
end
|
127
133
|
|
128
134
|
before do
|
129
|
-
allow(Email::Mboxrd::Message).to receive(:new)
|
135
|
+
allow(Email::Mboxrd::Message).to receive(:new) { message }
|
130
136
|
allow(File).to receive(:open).with(mbox_pathname, "ab") { mbox_file }
|
131
137
|
end
|
132
138
|
|
133
139
|
it "saves the message to the mbox" do
|
134
|
-
|
140
|
+
expect(mbox_file).to receive(:write).with(mbox_formatted_message)
|
135
141
|
|
136
|
-
|
142
|
+
subject.add(message_uid, "The\nemail\n")
|
137
143
|
end
|
138
144
|
|
139
145
|
it "saves the uid to the imap file" do
|
140
|
-
|
146
|
+
expect(imap_file).to receive(:write).with(updated_imap_content)
|
141
147
|
|
142
|
-
|
148
|
+
subject.add(message_uid, "The\nemail\n")
|
143
149
|
end
|
144
150
|
|
145
151
|
context "when the message is already downloaded" do
|
146
152
|
let(:uids) { [999] }
|
147
153
|
|
148
154
|
it "skips the message" do
|
155
|
+
expect(mbox_file).to_not receive(:write)
|
156
|
+
|
149
157
|
subject.add(message_uid, "The\nemail\n")
|
150
|
-
expect(mbox_file).to_not have_received(:write)
|
151
158
|
end
|
152
159
|
end
|
153
160
|
|
@@ -157,8 +164,9 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
157
164
|
end
|
158
165
|
|
159
166
|
it "skips the message" do
|
167
|
+
expect(mbox_file).to_not receive(:write)
|
168
|
+
|
160
169
|
subject.add(message_uid, "The\nemail\n")
|
161
|
-
expect(mbox_file).to_not have_received(:write)
|
162
170
|
end
|
163
171
|
|
164
172
|
it "does not fail" do
|
@@ -171,7 +179,6 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
171
179
|
|
172
180
|
describe "#load" do
|
173
181
|
let(:uid) { "1" }
|
174
|
-
let(:result) { subject.load(uid) }
|
175
182
|
let(:enumerator) do
|
176
183
|
instance_double(Imap::Backup::Serializer::MboxEnumerator)
|
177
184
|
end
|
@@ -189,14 +196,55 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
189
196
|
end
|
190
197
|
|
191
198
|
it "returns the message" do
|
192
|
-
expect(
|
199
|
+
expect(subject.load(uid).supplied_body).to eq("ciao")
|
193
200
|
end
|
194
201
|
|
195
202
|
context "when the UID is unknown" do
|
196
203
|
let(:uid) { "99" }
|
197
204
|
|
198
205
|
it "returns nil" do
|
199
|
-
expect(
|
206
|
+
expect(subject.load(uid)).to be_nil
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "#each_message" do
|
212
|
+
let(:enumerator) do
|
213
|
+
instance_double(Imap::Backup::Serializer::MboxEnumerator)
|
214
|
+
end
|
215
|
+
let(:enumeration) { instance_double(Enumerator) }
|
216
|
+
|
217
|
+
before do
|
218
|
+
allow(Imap::Backup::Serializer::MboxEnumerator).
|
219
|
+
to receive(:new) { enumerator }
|
220
|
+
allow(enumerator).to receive(:each) { enumeration }
|
221
|
+
allow(enumeration).
|
222
|
+
to receive(:with_index).
|
223
|
+
and_yield("", 0).
|
224
|
+
and_yield("", 1).
|
225
|
+
and_yield("ciao", 2)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "yields messages" do
|
229
|
+
expect { |b| subject.each_message([1], &b) }.
|
230
|
+
to yield_successive_args([1, instance_of(Email::Mboxrd::Message)])
|
231
|
+
end
|
232
|
+
|
233
|
+
it "yields the requested message uid" do
|
234
|
+
subject.each_message([1]) do |uid, _message|
|
235
|
+
expect(uid).to eq(1)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
it "yields the requested message" do
|
240
|
+
subject.each_message([1]) do |_uid, message|
|
241
|
+
expect(message.supplied_body).to eq("ciao")
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context "without a block" do
|
246
|
+
it "returns an Enumerator" do
|
247
|
+
expect(subject.each_message([1])).to be_a(Enumerator)
|
200
248
|
end
|
201
249
|
end
|
202
250
|
end
|
@@ -211,59 +259,70 @@ describe Imap::Backup::Serializer::MboxStore do
|
|
211
259
|
}.to_json
|
212
260
|
end
|
213
261
|
|
214
|
-
before { subject.update_uid(old_uid, "999") }
|
215
|
-
|
216
262
|
it "updates the stored UID" do
|
217
|
-
expect(imap_file).to
|
263
|
+
expect(imap_file).to receive(:write).with(updated_imap_content)
|
264
|
+
|
265
|
+
subject.update_uid(old_uid, "999")
|
218
266
|
end
|
219
267
|
|
220
268
|
context "when the UID is unknown" do
|
221
269
|
let(:old_uid) { "42" }
|
222
270
|
|
223
271
|
it "does nothing" do
|
224
|
-
expect(imap_file).to_not
|
272
|
+
expect(imap_file).to_not receive(:write)
|
273
|
+
|
274
|
+
subject.update_uid(old_uid, "999")
|
225
275
|
end
|
226
276
|
end
|
227
277
|
end
|
228
278
|
|
229
279
|
describe "#reset" do
|
230
|
-
before { subject.reset }
|
231
|
-
|
232
280
|
it "deletes the imap file" do
|
233
|
-
expect(File).to
|
281
|
+
expect(File).to receive(:unlink).with(imap_pathname)
|
282
|
+
|
283
|
+
subject.reset
|
234
284
|
end
|
235
285
|
|
236
286
|
it "deletes the mbox file" do
|
237
|
-
expect(File).to
|
287
|
+
expect(File).to receive(:unlink).with(mbox_pathname)
|
288
|
+
|
289
|
+
subject.reset
|
238
290
|
end
|
239
291
|
|
240
292
|
it "writes a blank mbox file" do
|
241
|
-
expect(mbox_file).to
|
293
|
+
expect(mbox_file).to receive(:write).with("")
|
294
|
+
|
295
|
+
subject.reset
|
242
296
|
end
|
243
297
|
end
|
244
298
|
|
245
299
|
describe "#rename" do
|
246
300
|
let(:new_name) { "new_name" }
|
247
301
|
let(:new_folder_path) { File.join(base_path, new_name) }
|
248
|
-
let(:new_imap_name) { new_folder_path
|
249
|
-
let(:new_mbox_name) { new_folder_path
|
302
|
+
let(:new_imap_name) { "#{new_folder_path}.imap" }
|
303
|
+
let(:new_mbox_name) { "#{new_folder_path}.mbox" }
|
250
304
|
|
251
305
|
before do
|
252
306
|
allow(File).to receive(:rename).and_call_original
|
253
307
|
allow(File).to receive(:rename).with(imap_pathname, new_imap_name)
|
254
308
|
allow(File).to receive(:rename).with(mbox_pathname, new_mbox_name)
|
255
|
-
subject.rename(new_name)
|
256
309
|
end
|
257
310
|
|
258
311
|
it "renames the imap file" do
|
259
|
-
expect(File).to
|
312
|
+
expect(File).to receive(:rename).with(imap_pathname, new_imap_name)
|
313
|
+
|
314
|
+
subject.rename(new_name)
|
260
315
|
end
|
261
316
|
|
262
317
|
it "renames the mbox file" do
|
263
|
-
expect(File).to
|
318
|
+
expect(File).to receive(:rename).with(mbox_pathname, new_mbox_name)
|
319
|
+
|
320
|
+
subject.rename(new_name)
|
264
321
|
end
|
265
322
|
|
266
323
|
it "updates the folder name" do
|
324
|
+
subject.rename(new_name)
|
325
|
+
|
267
326
|
expect(subject.folder).to eq(new_name)
|
268
327
|
end
|
269
328
|
end
|