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.
- checksums.yaml +4 -4
- data/bin/imap-backup +5 -2
- data/lib/email/provider/apple_mail.rb +2 -2
- data/lib/email/provider/base.rb +8 -0
- data/lib/email/provider/fastmail.rb +2 -2
- data/lib/email/provider/gmail.rb +2 -2
- data/lib/email/provider/{default.rb → unknown.rb} +2 -3
- data/lib/email/provider.rb +2 -2
- data/lib/imap/backup/account/connection.rb +70 -58
- data/lib/imap/backup/account/folder.rb +23 -3
- data/lib/imap/backup/account.rb +102 -0
- data/lib/imap/backup/cli/accounts.rb +43 -0
- data/lib/imap/backup/cli/folders.rb +3 -1
- data/lib/imap/backup/cli/helpers.rb +8 -9
- data/lib/imap/backup/cli/local.rb +4 -2
- data/lib/imap/backup/cli/setup.rb +1 -1
- data/lib/imap/backup/cli/utils.rb +3 -2
- data/lib/imap/backup/{configuration/store.rb → configuration.rb} +49 -14
- data/lib/imap/backup/downloader.rb +26 -12
- data/lib/imap/backup/logger.rb +42 -0
- data/lib/imap/backup/sanitizer.rb +42 -0
- data/lib/imap/backup/serializer/mbox_store.rb +2 -2
- data/lib/imap/backup/setup/account.rb +177 -0
- data/lib/imap/backup/{configuration → setup}/asker.rb +5 -5
- data/lib/imap/backup/setup/connection_tester.rb +26 -0
- data/lib/imap/backup/{configuration → setup}/folder_chooser.rb +25 -17
- data/lib/imap/backup/setup/helpers.rb +15 -0
- data/lib/imap/backup/{configuration/setup.rb → setup.rb} +33 -25
- data/lib/imap/backup/uploader.rb +2 -2
- data/lib/imap/backup/version.rb +2 -2
- data/lib/imap/backup.rb +7 -33
- data/lib/retry_on_error.rb +1 -1
- data/spec/features/backup_spec.rb +1 -0
- data/spec/features/support/email_server.rb +5 -2
- data/spec/features/support/shared/connection_context.rb +7 -5
- data/spec/support/higline_test_helpers.rb +1 -1
- data/spec/support/silence_logging.rb +1 -1
- data/spec/unit/email/provider/{default_spec.rb → base_spec.rb} +1 -7
- data/spec/unit/email/provider_spec.rb +2 -2
- data/spec/unit/imap/backup/account/connection_spec.rb +22 -26
- data/spec/unit/imap/backup/cli/accounts_spec.rb +47 -0
- data/spec/unit/imap/backup/cli/local_spec.rb +15 -4
- data/spec/unit/imap/backup/cli/utils_spec.rb +54 -42
- data/spec/unit/imap/backup/{configuration/store_spec.rb → configuration_spec.rb} +23 -24
- data/spec/unit/imap/backup/downloader_spec.rb +1 -1
- data/spec/unit/imap/backup/logger_spec.rb +48 -0
- data/spec/unit/imap/backup/{configuration → setup}/account_spec.rb +78 -70
- data/spec/unit/imap/backup/{configuration → setup}/asker_spec.rb +2 -2
- data/spec/unit/imap/backup/{configuration → setup}/connection_tester_spec.rb +10 -10
- data/spec/unit/imap/backup/{configuration → setup}/folder_chooser_spec.rb +25 -26
- data/spec/unit/imap/backup/{configuration/setup_spec.rb → setup_spec.rb} +81 -52
- metadata +54 -51
- data/lib/imap/backup/configuration/account.rb +0 -159
- data/lib/imap/backup/configuration/connection_tester.rb +0 -14
- data/lib/imap/backup/configuration/list.rb +0 -53
- data/spec/support/shared_examples/account_flagging.rb +0 -23
- data/spec/unit/imap/backup/configuration/list_spec.rb +0 -89
- data/spec/unit/imap/backup_spec.rb +0 -28
@@ -1,23 +1,46 @@
|
|
1
|
-
describe Imap::Backup::
|
1
|
+
describe Imap::Backup::Setup do
|
2
2
|
include HighLineTestHelpers
|
3
3
|
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
let(:
|
7
|
-
|
6
|
+
let(:normal_account) do
|
7
|
+
instance_double(
|
8
|
+
Imap::Backup::Account,
|
9
|
+
username: "account@example.com",
|
10
|
+
marked_for_deletion?: false,
|
11
|
+
modified?: false
|
12
|
+
)
|
13
|
+
end
|
14
|
+
let(:modified_account) do
|
15
|
+
instance_double(
|
16
|
+
Imap::Backup::Account,
|
17
|
+
username: "modified@example.com",
|
18
|
+
marked_for_deletion?: false,
|
19
|
+
modified?: true
|
20
|
+
)
|
21
|
+
end
|
22
|
+
let(:deleted_account) do
|
23
|
+
instance_double(
|
24
|
+
Imap::Backup::Account,
|
25
|
+
username: "delete@example.com",
|
26
|
+
marked_for_deletion?: true,
|
27
|
+
modified?: false
|
28
|
+
)
|
29
|
+
end
|
30
|
+
let(:accounts) { [normal_account] }
|
8
31
|
let(:store) do
|
9
32
|
instance_double(
|
10
|
-
Imap::Backup::Configuration
|
33
|
+
Imap::Backup::Configuration,
|
11
34
|
"accounts": accounts,
|
12
35
|
"path": "/base/path",
|
13
36
|
"save": nil,
|
14
37
|
"debug?": debug,
|
15
38
|
"debug=": nil,
|
16
|
-
"modified?":
|
39
|
+
"modified?": config_modified
|
17
40
|
)
|
18
41
|
end
|
19
42
|
let(:debug) { false }
|
20
|
-
let(:
|
43
|
+
let(:config_modified) { false }
|
21
44
|
let!(:highline_streams) { prepare_highline }
|
22
45
|
let(:input) { highline_streams[0] }
|
23
46
|
let(:output) { highline_streams[1] }
|
@@ -33,39 +56,48 @@ describe Imap::Backup::Configuration::Setup do
|
|
33
56
|
|
34
57
|
describe "#run" do
|
35
58
|
before do
|
36
|
-
allow(Imap::Backup::Configuration
|
37
|
-
allow(Imap::Backup).to receive(:setup_logging)
|
59
|
+
allow(Imap::Backup::Configuration).to receive(:new) { store }
|
60
|
+
allow(Imap::Backup::Logger).to receive(:setup_logging)
|
38
61
|
allow(input).to receive(:eof?) { false }
|
39
|
-
allow(input).to receive(:gets) { "
|
62
|
+
allow(input).to receive(:gets) { "q\n" }
|
40
63
|
allow(Kernel).to receive(:system)
|
41
64
|
end
|
42
65
|
|
43
66
|
describe "main menu" do
|
44
|
-
|
67
|
+
context "when changes have not been made" do
|
68
|
+
before { subject.run }
|
45
69
|
|
46
|
-
|
47
|
-
|
48
|
-
|
70
|
+
["add account", "quit"].each do |choice|
|
71
|
+
it "includes #{choice}" do
|
72
|
+
expect(output.string).to include(choice)
|
73
|
+
end
|
49
74
|
end
|
50
75
|
end
|
51
|
-
end
|
52
76
|
|
53
|
-
|
54
|
-
|
77
|
+
context "when changes have been made" do
|
78
|
+
let(:config_modified) { true }
|
55
79
|
|
56
|
-
|
80
|
+
before do
|
81
|
+
allow(input).to receive(:gets) { "exit\n" }
|
82
|
+
subject.run
|
83
|
+
end
|
84
|
+
|
85
|
+
["save and exit", "exit without saving"].each do |choice|
|
86
|
+
it "includes '#{choice}'" do
|
87
|
+
expect(output.string).to include(choice)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
57
91
|
end
|
58
92
|
|
59
|
-
it "
|
60
|
-
expect(
|
93
|
+
it "clears the screen" do
|
94
|
+
expect(Kernel).to receive(:system).with("clear")
|
61
95
|
|
62
96
|
subject.run
|
63
97
|
end
|
64
98
|
|
65
99
|
describe "listing" do
|
66
|
-
let(:accounts) { [
|
67
|
-
let(:modified) { {username: "modified@example.com", modified: true} }
|
68
|
-
let(:deleted) { {username: "deleted@example.com", delete: true} }
|
100
|
+
let(:accounts) { [normal_account, modified_account, deleted_account] }
|
69
101
|
|
70
102
|
before { subject.run }
|
71
103
|
|
@@ -90,15 +122,16 @@ describe Imap::Backup::Configuration::Setup do
|
|
90
122
|
|
91
123
|
context "when editing accounts" do
|
92
124
|
let(:account) do
|
93
|
-
instance_double(Imap::Backup::
|
125
|
+
instance_double(Imap::Backup::Setup::Account, run: nil)
|
94
126
|
end
|
127
|
+
let(:config_modified) { true }
|
95
128
|
|
96
129
|
before do
|
97
130
|
allow(input).to receive(:gets).and_return("1\n", "exit\n")
|
98
|
-
allow(Imap::Backup::
|
131
|
+
allow(Imap::Backup::Setup::Asker).to receive(:email).
|
99
132
|
with(no_args) { "new@example.com" }
|
100
|
-
allow(Imap::Backup::
|
101
|
-
with(store,
|
133
|
+
allow(Imap::Backup::Setup::Account).to receive(:new).
|
134
|
+
with(store, normal_account, anything) { account }
|
102
135
|
end
|
103
136
|
|
104
137
|
it "edits the account" do
|
@@ -118,35 +151,36 @@ describe Imap::Backup::Configuration::Setup do
|
|
118
151
|
}
|
119
152
|
end
|
120
153
|
let(:account) do
|
121
|
-
instance_double(Imap::Backup::
|
154
|
+
instance_double(Imap::Backup::Setup::Account, run: nil)
|
122
155
|
end
|
156
|
+
let(:config_modified) { true }
|
123
157
|
let(:added_email) { "new@example.com" }
|
124
158
|
let(:local_path) { "/base/path/new_example.com" }
|
125
159
|
|
126
160
|
before do
|
127
161
|
allow(input).to receive(:gets).and_return("add\n", "exit\n")
|
128
|
-
allow(Imap::Backup::
|
162
|
+
allow(Imap::Backup::Setup::Asker).to receive(:email).
|
129
163
|
with(no_args) { added_email }
|
130
|
-
allow(Imap::Backup::
|
164
|
+
allow(Imap::Backup::Setup::Account).to receive(:new).
|
131
165
|
with(store, anything, anything) { account }
|
132
166
|
|
133
167
|
subject.run
|
134
168
|
end
|
135
169
|
|
136
170
|
it "sets username" do
|
137
|
-
expect(accounts[1]
|
171
|
+
expect(accounts[1].username).to eq(added_email)
|
138
172
|
end
|
139
173
|
|
140
174
|
it "sets blank password" do
|
141
|
-
expect(accounts[1]
|
175
|
+
expect(accounts[1].password).to eq("")
|
142
176
|
end
|
143
177
|
|
144
178
|
it "sets local_path" do
|
145
|
-
expect(accounts[1]
|
179
|
+
expect(accounts[1].local_path).to eq(local_path)
|
146
180
|
end
|
147
181
|
|
148
182
|
it "sets folders" do
|
149
|
-
expect(accounts[1]
|
183
|
+
expect(accounts[1].folders).to eq([])
|
150
184
|
end
|
151
185
|
|
152
186
|
context "when the account is a GMail account" do
|
@@ -154,17 +188,19 @@ describe Imap::Backup::Configuration::Setup do
|
|
154
188
|
let(:local_path) { "/base/path/new_gmail.com" }
|
155
189
|
|
156
190
|
it "sets the server" do
|
157
|
-
expect(accounts[1]
|
191
|
+
expect(accounts[1].server).to eq(gmail_imap_server)
|
158
192
|
end
|
159
193
|
end
|
160
194
|
|
161
195
|
it "doesn't flag the unedited account as modified" do
|
162
|
-
expect(accounts[1]
|
196
|
+
expect(accounts[1].modified?).to be_falsey
|
163
197
|
end
|
164
198
|
end
|
165
199
|
|
166
200
|
describe "logging" do
|
167
201
|
context "when debug logging is disabled" do
|
202
|
+
let(:config_modified) { true }
|
203
|
+
|
168
204
|
before do
|
169
205
|
allow(input).to receive(:gets).and_return("start\n", "exit\n")
|
170
206
|
end
|
@@ -183,7 +219,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
183
219
|
end
|
184
220
|
|
185
221
|
it "updates logging status" do
|
186
|
-
expect(Imap::Backup).to receive(:setup_logging)
|
222
|
+
expect(Imap::Backup::Logger).to receive(:setup_logging)
|
187
223
|
|
188
224
|
subject.run
|
189
225
|
end
|
@@ -192,6 +228,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
192
228
|
|
193
229
|
context "when debug logging is enabled" do
|
194
230
|
let(:debug) { true }
|
231
|
+
let(:config_modified) { true }
|
195
232
|
|
196
233
|
before do
|
197
234
|
allow(input).to receive(:gets).and_return("stop\n", "exit\n")
|
@@ -215,7 +252,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
215
252
|
end
|
216
253
|
|
217
254
|
it "updates logging status" do
|
218
|
-
expect(Imap::Backup).to receive(:setup_logging)
|
255
|
+
expect(Imap::Backup::Logger).to receive(:setup_logging)
|
219
256
|
|
220
257
|
subject.run
|
221
258
|
end
|
@@ -224,6 +261,8 @@ describe Imap::Backup::Configuration::Setup do
|
|
224
261
|
end
|
225
262
|
|
226
263
|
context "when 'save' is selected" do
|
264
|
+
let(:config_modified) { true }
|
265
|
+
|
227
266
|
before do
|
228
267
|
allow(input).to receive(:gets) { "save\n" }
|
229
268
|
end
|
@@ -241,6 +280,8 @@ describe Imap::Backup::Configuration::Setup do
|
|
241
280
|
end
|
242
281
|
|
243
282
|
context "when 'exit without saving' is selected" do
|
283
|
+
let(:config_modified) { true }
|
284
|
+
|
244
285
|
before do
|
245
286
|
allow(input).to receive(:gets) { "exit\n" }
|
246
287
|
end
|
@@ -250,22 +291,10 @@ describe Imap::Backup::Configuration::Setup do
|
|
250
291
|
subject.run
|
251
292
|
end
|
252
293
|
|
253
|
-
|
254
|
-
|
294
|
+
it "doesn't save the configuration" do
|
295
|
+
expect(store).to_not receive(:save)
|
255
296
|
|
256
|
-
|
257
|
-
expect(store).to_not receive(:save)
|
258
|
-
|
259
|
-
subject.run
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "when the configuration isn't modified" do
|
264
|
-
it "doesn't save the configuration" do
|
265
|
-
expect(store).to_not receive(:save)
|
266
|
-
|
267
|
-
subject.run
|
268
|
-
end
|
297
|
+
subject.run
|
269
298
|
end
|
270
299
|
end
|
271
300
|
end
|
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.
|
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:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -182,13 +182,16 @@ files:
|
|
182
182
|
- lib/email/mboxrd/message.rb
|
183
183
|
- lib/email/provider.rb
|
184
184
|
- lib/email/provider/apple_mail.rb
|
185
|
-
- lib/email/provider/
|
185
|
+
- lib/email/provider/base.rb
|
186
186
|
- lib/email/provider/fastmail.rb
|
187
187
|
- lib/email/provider/gmail.rb
|
188
|
+
- lib/email/provider/unknown.rb
|
188
189
|
- lib/imap/backup.rb
|
190
|
+
- lib/imap/backup/account.rb
|
189
191
|
- lib/imap/backup/account/connection.rb
|
190
192
|
- lib/imap/backup/account/folder.rb
|
191
193
|
- lib/imap/backup/cli.rb
|
194
|
+
- lib/imap/backup/cli/accounts.rb
|
192
195
|
- lib/imap/backup/cli/backup.rb
|
193
196
|
- lib/imap/backup/cli/folders.rb
|
194
197
|
- lib/imap/backup/cli/helpers.rb
|
@@ -199,18 +202,20 @@ files:
|
|
199
202
|
- lib/imap/backup/cli/utils.rb
|
200
203
|
- lib/imap/backup/client/apple_mail.rb
|
201
204
|
- lib/imap/backup/client/default.rb
|
202
|
-
- lib/imap/backup/configuration
|
203
|
-
- lib/imap/backup/configuration/asker.rb
|
204
|
-
- lib/imap/backup/configuration/connection_tester.rb
|
205
|
-
- lib/imap/backup/configuration/folder_chooser.rb
|
206
|
-
- lib/imap/backup/configuration/list.rb
|
207
|
-
- lib/imap/backup/configuration/setup.rb
|
208
|
-
- lib/imap/backup/configuration/store.rb
|
205
|
+
- lib/imap/backup/configuration.rb
|
209
206
|
- lib/imap/backup/downloader.rb
|
207
|
+
- lib/imap/backup/logger.rb
|
208
|
+
- lib/imap/backup/sanitizer.rb
|
210
209
|
- lib/imap/backup/serializer.rb
|
211
210
|
- lib/imap/backup/serializer/mbox.rb
|
212
211
|
- lib/imap/backup/serializer/mbox_enumerator.rb
|
213
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
|
214
219
|
- lib/imap/backup/thunderbird/mailbox_exporter.rb
|
215
220
|
- lib/imap/backup/uploader.rb
|
216
221
|
- lib/imap/backup/utils.rb
|
@@ -235,33 +240,32 @@ files:
|
|
235
240
|
- spec/spec_helper.rb
|
236
241
|
- spec/support/fixtures.rb
|
237
242
|
- spec/support/higline_test_helpers.rb
|
238
|
-
- spec/support/shared_examples/account_flagging.rb
|
239
243
|
- spec/support/silence_logging.rb
|
240
244
|
- spec/unit/email/mboxrd/message_spec.rb
|
241
245
|
- spec/unit/email/provider/apple_mail_spec.rb
|
242
|
-
- spec/unit/email/provider/
|
246
|
+
- spec/unit/email/provider/base_spec.rb
|
243
247
|
- spec/unit/email/provider/fastmail_spec.rb
|
244
248
|
- spec/unit/email/provider/gmail_spec.rb
|
245
249
|
- spec/unit/email/provider_spec.rb
|
246
250
|
- spec/unit/imap/backup/account/connection_spec.rb
|
247
251
|
- spec/unit/imap/backup/account/folder_spec.rb
|
252
|
+
- spec/unit/imap/backup/cli/accounts_spec.rb
|
248
253
|
- spec/unit/imap/backup/cli/local_spec.rb
|
249
254
|
- spec/unit/imap/backup/cli/utils_spec.rb
|
250
255
|
- spec/unit/imap/backup/client/default_spec.rb
|
251
|
-
- spec/unit/imap/backup/
|
252
|
-
- spec/unit/imap/backup/configuration/asker_spec.rb
|
253
|
-
- spec/unit/imap/backup/configuration/connection_tester_spec.rb
|
254
|
-
- spec/unit/imap/backup/configuration/folder_chooser_spec.rb
|
255
|
-
- spec/unit/imap/backup/configuration/list_spec.rb
|
256
|
-
- spec/unit/imap/backup/configuration/setup_spec.rb
|
257
|
-
- spec/unit/imap/backup/configuration/store_spec.rb
|
256
|
+
- spec/unit/imap/backup/configuration_spec.rb
|
258
257
|
- spec/unit/imap/backup/downloader_spec.rb
|
258
|
+
- spec/unit/imap/backup/logger_spec.rb
|
259
259
|
- spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
|
260
260
|
- spec/unit/imap/backup/serializer/mbox_spec.rb
|
261
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
|
262
267
|
- spec/unit/imap/backup/uploader_spec.rb
|
263
268
|
- spec/unit/imap/backup/utils_spec.rb
|
264
|
-
- spec/unit/imap/backup_spec.rb
|
265
269
|
homepage: https://github.com/joeyates/imap-backup
|
266
270
|
licenses:
|
267
271
|
- MIT
|
@@ -281,47 +285,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
285
|
- !ruby/object:Gem::Version
|
282
286
|
version: '0'
|
283
287
|
requirements: []
|
284
|
-
rubygems_version: 3.1.
|
288
|
+
rubygems_version: 3.1.6
|
285
289
|
signing_key:
|
286
290
|
specification_version: 4
|
287
291
|
summary: Backup GMail (or other IMAP) accounts to disk
|
288
292
|
test_files:
|
289
|
-
- spec/
|
290
|
-
- spec/
|
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
|
291
304
|
- spec/unit/email/provider/gmail_spec.rb
|
292
|
-
- spec/unit/email/provider/apple_mail_spec.rb
|
293
|
-
- spec/unit/email/provider/default_spec.rb
|
294
305
|
- spec/unit/email/provider/fastmail_spec.rb
|
295
|
-
- spec/unit/email/
|
306
|
+
- spec/unit/email/provider/base_spec.rb
|
307
|
+
- spec/unit/email/provider/apple_mail_spec.rb
|
296
308
|
- spec/unit/email/mboxrd/message_spec.rb
|
297
|
-
- spec/unit/
|
309
|
+
- spec/unit/email/provider_spec.rb
|
298
310
|
- spec/unit/imap/backup/cli/utils_spec.rb
|
311
|
+
- spec/unit/imap/backup/cli/accounts_spec.rb
|
299
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
|
300
318
|
- spec/unit/imap/backup/utils_spec.rb
|
301
|
-
- spec/unit/imap/backup/
|
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
|
302
325
|
- spec/unit/imap/backup/downloader_spec.rb
|
303
|
-
- spec/unit/imap/backup/configuration/store_spec.rb
|
304
|
-
- spec/unit/imap/backup/configuration/connection_tester_spec.rb
|
305
|
-
- spec/unit/imap/backup/configuration/asker_spec.rb
|
306
|
-
- spec/unit/imap/backup/configuration/setup_spec.rb
|
307
|
-
- spec/unit/imap/backup/configuration/folder_chooser_spec.rb
|
308
|
-
- spec/unit/imap/backup/configuration/account_spec.rb
|
309
|
-
- spec/unit/imap/backup/configuration/list_spec.rb
|
310
326
|
- spec/unit/imap/backup/account/folder_spec.rb
|
311
327
|
- spec/unit/imap/backup/account/connection_spec.rb
|
312
|
-
- spec/unit/imap/backup/
|
313
|
-
- spec/
|
314
|
-
- spec/
|
315
|
-
- spec/unit/imap/backup/uploader_spec.rb
|
316
|
-
- spec/support/fixtures.rb
|
317
|
-
- spec/support/shared_examples/account_flagging.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,159 +0,0 @@
|
|
1
|
-
module Imap::Backup
|
2
|
-
module Configuration; end
|
3
|
-
|
4
|
-
Configuration::Account = Struct.new(:store, :account, :highline) do
|
5
|
-
def initialize(store, account, highline)
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
9
|
-
def run
|
10
|
-
catch :done do
|
11
|
-
loop do
|
12
|
-
Kernel.system("clear")
|
13
|
-
create_menu
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def create_menu
|
21
|
-
highline.choose do |menu|
|
22
|
-
header menu
|
23
|
-
modify_email menu
|
24
|
-
modify_password menu
|
25
|
-
modify_server menu
|
26
|
-
modify_backup_path menu
|
27
|
-
choose_folders menu
|
28
|
-
test_connection menu
|
29
|
-
delete_account menu
|
30
|
-
menu.choice("return to main menu") { throw :done }
|
31
|
-
menu.hidden("quit") { throw :done }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def header(menu)
|
36
|
-
menu.header = <<-HEADER.gsub(/^\s{8}/m, "")
|
37
|
-
Account:
|
38
|
-
email: #{account[:username]}
|
39
|
-
server: #{account[:server]}
|
40
|
-
path: #{account[:local_path]}
|
41
|
-
folders: #{folders.map { |f| f[:name] }.join(', ')}
|
42
|
-
password: #{masked_password}
|
43
|
-
HEADER
|
44
|
-
end
|
45
|
-
|
46
|
-
def modify_email(menu)
|
47
|
-
menu.choice("modify email") do
|
48
|
-
username = Configuration::Asker.email(username)
|
49
|
-
Kernel.puts "username: #{username}"
|
50
|
-
other_accounts = store.accounts.reject { |a| a == account }
|
51
|
-
others = other_accounts.map { |a| a[:username] }
|
52
|
-
Kernel.puts "others: #{others.inspect}"
|
53
|
-
if others.include?(username)
|
54
|
-
Kernel.puts(
|
55
|
-
"There is already an account set up with that email address"
|
56
|
-
)
|
57
|
-
else
|
58
|
-
account[:username] = username
|
59
|
-
# rubocop:disable Style/IfUnlessModifier
|
60
|
-
if account[:server].nil? || (account[:server] == "")
|
61
|
-
account[:server] = default_server(username)
|
62
|
-
end
|
63
|
-
# rubocop:enable Style/IfUnlessModifier
|
64
|
-
account[:modified] = true
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def modify_password(menu)
|
70
|
-
menu.choice("modify password") do
|
71
|
-
password = Configuration::Asker.password
|
72
|
-
|
73
|
-
if !password.nil?
|
74
|
-
account[:password] = password
|
75
|
-
account[:modified] = true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def modify_server(menu)
|
81
|
-
menu.choice("modify server") do
|
82
|
-
server = highline.ask("server: ")
|
83
|
-
if !server.nil?
|
84
|
-
account[:server] = server
|
85
|
-
account[:modified] = true
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def path_modification_validator(path)
|
91
|
-
same = store.accounts.find do |a|
|
92
|
-
a[:username] != account[:username] && a[:local_path] == path
|
93
|
-
end
|
94
|
-
if same
|
95
|
-
Kernel.puts "The path '#{path}' is used to backup " \
|
96
|
-
"the account '#{same[:username]}'"
|
97
|
-
false
|
98
|
-
else
|
99
|
-
true
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def modify_backup_path(menu)
|
104
|
-
menu.choice("modify backup path") do
|
105
|
-
existing = account[:local_path].clone
|
106
|
-
account[:local_path] = Configuration::Asker.backup_path(
|
107
|
-
account[:local_path], ->(path) { path_modification_validator(path) }
|
108
|
-
)
|
109
|
-
account[:modified] = true if existing != account[:local_path]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def choose_folders(menu)
|
114
|
-
menu.choice("choose backup folders") do
|
115
|
-
Configuration::FolderChooser.new(account).run
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_connection(menu)
|
120
|
-
menu.choice("test connection") do
|
121
|
-
result = Configuration::ConnectionTester.test(account)
|
122
|
-
Kernel.puts result
|
123
|
-
highline.ask "Press a key "
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def delete_account(menu)
|
128
|
-
menu.choice("delete") do
|
129
|
-
if highline.agree("Are you sure? (y/n) ")
|
130
|
-
account[:delete] = true
|
131
|
-
throw :done
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def folders
|
137
|
-
account[:folders] || []
|
138
|
-
end
|
139
|
-
|
140
|
-
def masked_password
|
141
|
-
if (account[:password] == "") || account[:password].nil?
|
142
|
-
"(unset)"
|
143
|
-
else
|
144
|
-
account[:password].gsub(/./, "x")
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def default_server(username)
|
149
|
-
provider = Email::Provider.for_address(username)
|
150
|
-
|
151
|
-
if provider.is_a?(Email::Provider::Default)
|
152
|
-
Kernel.puts "Can't decide provider for email address '#{username}'"
|
153
|
-
return nil
|
154
|
-
end
|
155
|
-
|
156
|
-
provider.host
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
@@ -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
|