imap-backup 5.2.0 → 6.0.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/README.md +9 -2
- data/docs/development.md +10 -4
- data/imap-backup.gemspec +5 -1
- data/lib/cli_coverage.rb +11 -11
- data/lib/email/provider/base.rb +2 -0
- data/lib/email/provider/unknown.rb +2 -0
- data/lib/email/provider.rb +2 -0
- data/lib/imap/backup/account/connection/backup_folders.rb +27 -0
- data/lib/imap/backup/account/connection/client_factory.rb +54 -0
- data/lib/imap/backup/account/connection/folder_names.rb +26 -0
- data/lib/imap/backup/account/connection.rb +17 -105
- data/lib/imap/backup/account/folder.rb +9 -6
- data/lib/imap/backup/account.rb +36 -16
- data/lib/imap/backup/cli/backup.rb +1 -3
- data/lib/imap/backup/cli/folders.rb +3 -3
- data/lib/imap/backup/cli/helpers.rb +24 -22
- data/lib/imap/backup/cli/local.rb +20 -13
- data/lib/imap/backup/cli/migrate.rb +5 -11
- data/lib/imap/backup/cli/restore.rb +8 -7
- data/lib/imap/backup/cli/setup.rb +10 -8
- data/lib/imap/backup/cli/stats.rb +78 -0
- data/lib/imap/backup/cli/status.rb +2 -2
- data/lib/imap/backup/cli/utils.rb +6 -8
- data/lib/imap/backup/cli.rb +24 -3
- data/lib/imap/backup/configuration.rb +9 -21
- data/lib/imap/backup/downloader.rb +56 -34
- data/lib/imap/backup/migrator.rb +5 -5
- data/lib/imap/backup/sanitizer.rb +3 -2
- data/lib/imap/backup/serializer/appender.rb +49 -0
- data/lib/imap/backup/serializer/directory.rb +37 -0
- data/lib/imap/backup/serializer/imap.rb +144 -0
- data/lib/imap/backup/serializer/mbox.rb +33 -88
- data/lib/imap/backup/serializer/mbox_enumerator.rb +2 -0
- data/lib/imap/backup/serializer/message_enumerator.rb +29 -0
- data/lib/imap/backup/serializer/unused_name_finder.rb +25 -0
- data/lib/imap/backup/serializer.rb +160 -3
- data/lib/imap/backup/setup/account/header.rb +75 -0
- data/lib/imap/backup/setup/account.rb +41 -95
- data/lib/imap/backup/setup/asker.rb +4 -15
- data/lib/imap/backup/setup/backup_path.rb +41 -0
- data/lib/imap/backup/setup/email.rb +45 -0
- data/lib/imap/backup/setup/folder_chooser.rb +3 -3
- data/lib/imap/backup/setup/helpers.rb +2 -2
- data/lib/imap/backup/setup.rb +5 -4
- data/lib/imap/backup/thunderbird/mailbox_exporter.rb +41 -22
- data/lib/imap/backup/uploader.rb +46 -8
- data/lib/imap/backup/utils.rb +1 -1
- data/lib/imap/backup/version.rb +3 -3
- data/lib/imap/backup.rb +0 -2
- metadata +31 -105
- data/lib/imap/backup/serializer/mbox_store.rb +0 -217
- data/spec/features/backup_spec.rb +0 -108
- data/spec/features/configuration/minimal_configuration.rb +0 -15
- data/spec/features/configuration/missing_configuration.rb +0 -14
- data/spec/features/folders_spec.rb +0 -36
- data/spec/features/helper.rb +0 -2
- data/spec/features/local/list_accounts_spec.rb +0 -12
- data/spec/features/local/list_emails_spec.rb +0 -21
- data/spec/features/local/list_folders_spec.rb +0 -21
- data/spec/features/local/show_an_email_spec.rb +0 -34
- data/spec/features/migrate_spec.rb +0 -35
- data/spec/features/remote/list_account_folders_spec.rb +0 -16
- data/spec/features/restore_spec.rb +0 -162
- data/spec/features/status_spec.rb +0 -43
- data/spec/features/support/aruba.rb +0 -77
- data/spec/features/support/backup_directory.rb +0 -43
- data/spec/features/support/email_server.rb +0 -110
- data/spec/features/support/shared/connection_context.rb +0 -14
- data/spec/features/support/shared/message_fixtures.rb +0 -16
- data/spec/fixtures/connection.yml +0 -7
- data/spec/spec_helper.rb +0 -15
- data/spec/support/fixtures.rb +0 -11
- data/spec/support/higline_test_helpers.rb +0 -8
- data/spec/support/silence_logging.rb +0 -7
- data/spec/unit/email/mboxrd/message_spec.rb +0 -177
- data/spec/unit/email/provider/apple_mail_spec.rb +0 -7
- data/spec/unit/email/provider/base_spec.rb +0 -11
- data/spec/unit/email/provider/fastmail_spec.rb +0 -7
- data/spec/unit/email/provider/gmail_spec.rb +0 -7
- data/spec/unit/email/provider_spec.rb +0 -27
- data/spec/unit/imap/backup/account/connection_spec.rb +0 -405
- data/spec/unit/imap/backup/account/folder_spec.rb +0 -251
- data/spec/unit/imap/backup/cli/accounts_spec.rb +0 -47
- data/spec/unit/imap/backup/cli/helpers_spec.rb +0 -87
- data/spec/unit/imap/backup/cli/local_spec.rb +0 -81
- data/spec/unit/imap/backup/cli/utils_spec.rb +0 -62
- data/spec/unit/imap/backup/client/default_spec.rb +0 -22
- data/spec/unit/imap/backup/configuration_spec.rb +0 -238
- data/spec/unit/imap/backup/downloader_spec.rb +0 -44
- data/spec/unit/imap/backup/logger_spec.rb +0 -48
- data/spec/unit/imap/backup/migrator_spec.rb +0 -58
- data/spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb +0 -45
- data/spec/unit/imap/backup/serializer/mbox_spec.rb +0 -222
- data/spec/unit/imap/backup/serializer/mbox_store_spec.rb +0 -329
- data/spec/unit/imap/backup/setup/account_spec.rb +0 -366
- data/spec/unit/imap/backup/setup/asker_spec.rb +0 -137
- data/spec/unit/imap/backup/setup/connection_tester_spec.rb +0 -51
- data/spec/unit/imap/backup/setup/folder_chooser_spec.rb +0 -146
- data/spec/unit/imap/backup/setup_spec.rb +0 -301
- data/spec/unit/imap/backup/uploader_spec.rb +0 -54
- data/spec/unit/imap/backup/utils_spec.rb +0 -92
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
|
+
version: 6.0.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: 2022-
|
|
11
|
+
date: 2022-07-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: highline
|
|
@@ -164,6 +164,20 @@ dependencies:
|
|
|
164
164
|
- - ">="
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
166
|
version: '0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: yard
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
167
181
|
description: Backup GMail, or any other IMAP email service, to disk.
|
|
168
182
|
email:
|
|
169
183
|
- joe.g.yates@gmail.com
|
|
@@ -190,6 +204,9 @@ files:
|
|
|
190
204
|
- lib/imap/backup.rb
|
|
191
205
|
- lib/imap/backup/account.rb
|
|
192
206
|
- lib/imap/backup/account/connection.rb
|
|
207
|
+
- lib/imap/backup/account/connection/backup_folders.rb
|
|
208
|
+
- lib/imap/backup/account/connection/client_factory.rb
|
|
209
|
+
- lib/imap/backup/account/connection/folder_names.rb
|
|
193
210
|
- lib/imap/backup/account/folder.rb
|
|
194
211
|
- lib/imap/backup/cli.rb
|
|
195
212
|
- lib/imap/backup/cli/accounts.rb
|
|
@@ -201,6 +218,7 @@ files:
|
|
|
201
218
|
- lib/imap/backup/cli/remote.rb
|
|
202
219
|
- lib/imap/backup/cli/restore.rb
|
|
203
220
|
- lib/imap/backup/cli/setup.rb
|
|
221
|
+
- lib/imap/backup/cli/stats.rb
|
|
204
222
|
- lib/imap/backup/cli/status.rb
|
|
205
223
|
- lib/imap/backup/cli/utils.rb
|
|
206
224
|
- lib/imap/backup/client/apple_mail.rb
|
|
@@ -211,13 +229,20 @@ files:
|
|
|
211
229
|
- lib/imap/backup/migrator.rb
|
|
212
230
|
- lib/imap/backup/sanitizer.rb
|
|
213
231
|
- lib/imap/backup/serializer.rb
|
|
232
|
+
- lib/imap/backup/serializer/appender.rb
|
|
233
|
+
- lib/imap/backup/serializer/directory.rb
|
|
234
|
+
- lib/imap/backup/serializer/imap.rb
|
|
214
235
|
- lib/imap/backup/serializer/mbox.rb
|
|
215
236
|
- lib/imap/backup/serializer/mbox_enumerator.rb
|
|
216
|
-
- lib/imap/backup/serializer/
|
|
237
|
+
- lib/imap/backup/serializer/message_enumerator.rb
|
|
238
|
+
- lib/imap/backup/serializer/unused_name_finder.rb
|
|
217
239
|
- lib/imap/backup/setup.rb
|
|
218
240
|
- lib/imap/backup/setup/account.rb
|
|
241
|
+
- lib/imap/backup/setup/account/header.rb
|
|
219
242
|
- lib/imap/backup/setup/asker.rb
|
|
243
|
+
- lib/imap/backup/setup/backup_path.rb
|
|
220
244
|
- lib/imap/backup/setup/connection_tester.rb
|
|
245
|
+
- lib/imap/backup/setup/email.rb
|
|
221
246
|
- lib/imap/backup/setup/folder_chooser.rb
|
|
222
247
|
- lib/imap/backup/setup/helpers.rb
|
|
223
248
|
- lib/imap/backup/thunderbird/mailbox_exporter.rb
|
|
@@ -225,60 +250,11 @@ files:
|
|
|
225
250
|
- lib/imap/backup/utils.rb
|
|
226
251
|
- lib/imap/backup/version.rb
|
|
227
252
|
- lib/retry_on_error.rb
|
|
228
|
-
- spec/features/backup_spec.rb
|
|
229
|
-
- spec/features/configuration/minimal_configuration.rb
|
|
230
|
-
- spec/features/configuration/missing_configuration.rb
|
|
231
|
-
- spec/features/folders_spec.rb
|
|
232
|
-
- spec/features/helper.rb
|
|
233
|
-
- spec/features/local/list_accounts_spec.rb
|
|
234
|
-
- spec/features/local/list_emails_spec.rb
|
|
235
|
-
- spec/features/local/list_folders_spec.rb
|
|
236
|
-
- spec/features/local/show_an_email_spec.rb
|
|
237
|
-
- spec/features/migrate_spec.rb
|
|
238
|
-
- spec/features/remote/list_account_folders_spec.rb
|
|
239
|
-
- spec/features/restore_spec.rb
|
|
240
|
-
- spec/features/status_spec.rb
|
|
241
|
-
- spec/features/support/aruba.rb
|
|
242
|
-
- spec/features/support/backup_directory.rb
|
|
243
|
-
- spec/features/support/email_server.rb
|
|
244
|
-
- spec/features/support/shared/connection_context.rb
|
|
245
|
-
- spec/features/support/shared/message_fixtures.rb
|
|
246
|
-
- spec/fixtures/connection.yml
|
|
247
|
-
- spec/spec_helper.rb
|
|
248
|
-
- spec/support/fixtures.rb
|
|
249
|
-
- spec/support/higline_test_helpers.rb
|
|
250
|
-
- spec/support/silence_logging.rb
|
|
251
|
-
- spec/unit/email/mboxrd/message_spec.rb
|
|
252
|
-
- spec/unit/email/provider/apple_mail_spec.rb
|
|
253
|
-
- spec/unit/email/provider/base_spec.rb
|
|
254
|
-
- spec/unit/email/provider/fastmail_spec.rb
|
|
255
|
-
- spec/unit/email/provider/gmail_spec.rb
|
|
256
|
-
- spec/unit/email/provider_spec.rb
|
|
257
|
-
- spec/unit/imap/backup/account/connection_spec.rb
|
|
258
|
-
- spec/unit/imap/backup/account/folder_spec.rb
|
|
259
|
-
- spec/unit/imap/backup/cli/accounts_spec.rb
|
|
260
|
-
- spec/unit/imap/backup/cli/helpers_spec.rb
|
|
261
|
-
- spec/unit/imap/backup/cli/local_spec.rb
|
|
262
|
-
- spec/unit/imap/backup/cli/utils_spec.rb
|
|
263
|
-
- spec/unit/imap/backup/client/default_spec.rb
|
|
264
|
-
- spec/unit/imap/backup/configuration_spec.rb
|
|
265
|
-
- spec/unit/imap/backup/downloader_spec.rb
|
|
266
|
-
- spec/unit/imap/backup/logger_spec.rb
|
|
267
|
-
- spec/unit/imap/backup/migrator_spec.rb
|
|
268
|
-
- spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
|
|
269
|
-
- spec/unit/imap/backup/serializer/mbox_spec.rb
|
|
270
|
-
- spec/unit/imap/backup/serializer/mbox_store_spec.rb
|
|
271
|
-
- spec/unit/imap/backup/setup/account_spec.rb
|
|
272
|
-
- spec/unit/imap/backup/setup/asker_spec.rb
|
|
273
|
-
- spec/unit/imap/backup/setup/connection_tester_spec.rb
|
|
274
|
-
- spec/unit/imap/backup/setup/folder_chooser_spec.rb
|
|
275
|
-
- spec/unit/imap/backup/setup_spec.rb
|
|
276
|
-
- spec/unit/imap/backup/uploader_spec.rb
|
|
277
|
-
- spec/unit/imap/backup/utils_spec.rb
|
|
278
253
|
homepage: https://github.com/joeyates/imap-backup
|
|
279
254
|
licenses:
|
|
280
255
|
- MIT
|
|
281
|
-
metadata:
|
|
256
|
+
metadata:
|
|
257
|
+
rubygems_mfa_required: 'true'
|
|
282
258
|
post_install_message:
|
|
283
259
|
rdoc_options: []
|
|
284
260
|
require_paths:
|
|
@@ -298,54 +274,4 @@ rubygems_version: 3.1.6
|
|
|
298
274
|
signing_key:
|
|
299
275
|
specification_version: 4
|
|
300
276
|
summary: Backup GMail (or other IMAP) accounts to disk
|
|
301
|
-
test_files:
|
|
302
|
-
- spec/spec_helper.rb
|
|
303
|
-
- spec/unit/imap/backup/serializer/mbox_spec.rb
|
|
304
|
-
- spec/unit/imap/backup/serializer/mbox_store_spec.rb
|
|
305
|
-
- spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
|
|
306
|
-
- spec/unit/imap/backup/setup_spec.rb
|
|
307
|
-
- spec/unit/imap/backup/logger_spec.rb
|
|
308
|
-
- spec/unit/imap/backup/configuration_spec.rb
|
|
309
|
-
- spec/unit/imap/backup/setup/account_spec.rb
|
|
310
|
-
- spec/unit/imap/backup/setup/connection_tester_spec.rb
|
|
311
|
-
- spec/unit/imap/backup/setup/asker_spec.rb
|
|
312
|
-
- spec/unit/imap/backup/setup/folder_chooser_spec.rb
|
|
313
|
-
- spec/unit/imap/backup/cli/helpers_spec.rb
|
|
314
|
-
- spec/unit/imap/backup/cli/accounts_spec.rb
|
|
315
|
-
- spec/unit/imap/backup/cli/utils_spec.rb
|
|
316
|
-
- spec/unit/imap/backup/cli/local_spec.rb
|
|
317
|
-
- spec/unit/imap/backup/downloader_spec.rb
|
|
318
|
-
- spec/unit/imap/backup/migrator_spec.rb
|
|
319
|
-
- spec/unit/imap/backup/uploader_spec.rb
|
|
320
|
-
- spec/unit/imap/backup/account/folder_spec.rb
|
|
321
|
-
- spec/unit/imap/backup/account/connection_spec.rb
|
|
322
|
-
- spec/unit/imap/backup/utils_spec.rb
|
|
323
|
-
- spec/unit/imap/backup/client/default_spec.rb
|
|
324
|
-
- spec/unit/email/mboxrd/message_spec.rb
|
|
325
|
-
- spec/unit/email/provider/gmail_spec.rb
|
|
326
|
-
- spec/unit/email/provider/apple_mail_spec.rb
|
|
327
|
-
- spec/unit/email/provider/fastmail_spec.rb
|
|
328
|
-
- spec/unit/email/provider/base_spec.rb
|
|
329
|
-
- spec/unit/email/provider_spec.rb
|
|
330
|
-
- spec/features/folders_spec.rb
|
|
331
|
-
- spec/features/configuration/missing_configuration.rb
|
|
332
|
-
- spec/features/configuration/minimal_configuration.rb
|
|
333
|
-
- spec/features/backup_spec.rb
|
|
334
|
-
- spec/features/helper.rb
|
|
335
|
-
- spec/features/restore_spec.rb
|
|
336
|
-
- spec/features/local/list_emails_spec.rb
|
|
337
|
-
- spec/features/local/list_accounts_spec.rb
|
|
338
|
-
- spec/features/local/show_an_email_spec.rb
|
|
339
|
-
- spec/features/local/list_folders_spec.rb
|
|
340
|
-
- spec/features/status_spec.rb
|
|
341
|
-
- spec/features/support/email_server.rb
|
|
342
|
-
- spec/features/support/backup_directory.rb
|
|
343
|
-
- spec/features/support/aruba.rb
|
|
344
|
-
- spec/features/support/shared/connection_context.rb
|
|
345
|
-
- spec/features/support/shared/message_fixtures.rb
|
|
346
|
-
- spec/features/migrate_spec.rb
|
|
347
|
-
- spec/features/remote/list_account_folders_spec.rb
|
|
348
|
-
- spec/support/fixtures.rb
|
|
349
|
-
- spec/support/silence_logging.rb
|
|
350
|
-
- spec/support/higline_test_helpers.rb
|
|
351
|
-
- spec/fixtures/connection.yml
|
|
277
|
+
test_files: []
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
require "json"
|
|
2
|
-
|
|
3
|
-
require "email/mboxrd/message"
|
|
4
|
-
require "imap/backup/serializer/mbox_enumerator"
|
|
5
|
-
|
|
6
|
-
module Imap::Backup
|
|
7
|
-
class Serializer::MboxStore
|
|
8
|
-
CURRENT_VERSION = 2
|
|
9
|
-
|
|
10
|
-
attr_reader :folder
|
|
11
|
-
attr_reader :path
|
|
12
|
-
attr_reader :loaded
|
|
13
|
-
|
|
14
|
-
def initialize(path, folder)
|
|
15
|
-
@path = path
|
|
16
|
-
@folder = folder
|
|
17
|
-
@loaded = false
|
|
18
|
-
@uids = nil
|
|
19
|
-
@uid_validity = nil
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def exist?
|
|
23
|
-
mbox_exist? && imap_exist?
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def uid_validity
|
|
27
|
-
do_load if !loaded
|
|
28
|
-
@uid_validity
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def uid_validity=(value)
|
|
32
|
-
do_load if !loaded
|
|
33
|
-
@uid_validity = value
|
|
34
|
-
@uids ||= []
|
|
35
|
-
write_imap_file
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def uids
|
|
39
|
-
do_load if !loaded
|
|
40
|
-
@uids || []
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def add(uid, body)
|
|
44
|
-
do_load if !loaded
|
|
45
|
-
raise "Can't add messages without uid_validity" if !uid_validity
|
|
46
|
-
|
|
47
|
-
uid = uid.to_i
|
|
48
|
-
if uids.include?(uid)
|
|
49
|
-
Imap::Backup::Logger.logger.debug(
|
|
50
|
-
"[#{folder}] message #{uid} already downloaded - skipping"
|
|
51
|
-
)
|
|
52
|
-
return
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
mboxrd_message = Email::Mboxrd::Message.new(body)
|
|
56
|
-
mbox = nil
|
|
57
|
-
begin
|
|
58
|
-
mbox = File.open(mbox_pathname, "ab")
|
|
59
|
-
mbox.write mboxrd_message.to_serialized
|
|
60
|
-
@uids << uid
|
|
61
|
-
write_imap_file
|
|
62
|
-
rescue StandardError => e
|
|
63
|
-
message = <<-ERROR.gsub(/^\s*/m, "")
|
|
64
|
-
[#{folder}] failed to save message #{uid}:
|
|
65
|
-
#{body}. #{e}:
|
|
66
|
-
#{e.backtrace.join("\n")}"
|
|
67
|
-
ERROR
|
|
68
|
-
Imap::Backup::Logger.logger.warn message
|
|
69
|
-
ensure
|
|
70
|
-
mbox&.close
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def load(uid_maybe_string)
|
|
75
|
-
do_load if !loaded
|
|
76
|
-
uid = uid_maybe_string.to_i
|
|
77
|
-
message_index = uids.find_index(uid)
|
|
78
|
-
return nil if message_index.nil?
|
|
79
|
-
|
|
80
|
-
load_nth(message_index)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def each_message(required_uids)
|
|
84
|
-
return enum_for(:each_message, required_uids) if !block_given?
|
|
85
|
-
|
|
86
|
-
indexes = required_uids.each.with_object({}) do |uid_maybe_string, acc|
|
|
87
|
-
uid = uid_maybe_string.to_i
|
|
88
|
-
index = uids.find_index(uid)
|
|
89
|
-
acc[index] = uid if index
|
|
90
|
-
end
|
|
91
|
-
enumerator = Serializer::MboxEnumerator.new(mbox_pathname)
|
|
92
|
-
enumerator.each.with_index do |raw, i|
|
|
93
|
-
uid = indexes[i]
|
|
94
|
-
next if !uid
|
|
95
|
-
|
|
96
|
-
yield uid, Email::Mboxrd::Message.from_serialized(raw)
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def update_uid(old, new)
|
|
101
|
-
index = uids.find_index(old.to_i)
|
|
102
|
-
return if index.nil?
|
|
103
|
-
|
|
104
|
-
uids[index] = new.to_i
|
|
105
|
-
write_imap_file
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def reset
|
|
109
|
-
@uids = nil
|
|
110
|
-
@uid_validity = nil
|
|
111
|
-
@loaded = false
|
|
112
|
-
delete_files
|
|
113
|
-
write_blank_mbox_file
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def rename(new_name)
|
|
117
|
-
new_mbox_pathname = absolute_path("#{new_name}.mbox")
|
|
118
|
-
new_imap_pathname = absolute_path("#{new_name}.imap")
|
|
119
|
-
File.rename(mbox_pathname, new_mbox_pathname)
|
|
120
|
-
File.rename(imap_pathname, new_imap_pathname)
|
|
121
|
-
@folder = new_name
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def mbox_pathname
|
|
125
|
-
absolute_path("#{folder}.mbox")
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def imap_pathname
|
|
129
|
-
absolute_path("#{folder}.imap")
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
private
|
|
133
|
-
|
|
134
|
-
def do_load
|
|
135
|
-
data = imap_data
|
|
136
|
-
if data
|
|
137
|
-
@uids = data[:uids].map(&:to_i)
|
|
138
|
-
@uid_validity = data[:uid_validity]
|
|
139
|
-
@loaded = true
|
|
140
|
-
else
|
|
141
|
-
reset
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def imap_data
|
|
146
|
-
return nil if !imap_ok?
|
|
147
|
-
|
|
148
|
-
imap_data = nil
|
|
149
|
-
|
|
150
|
-
begin
|
|
151
|
-
imap_data = JSON.parse(File.read(imap_pathname), symbolize_names: true)
|
|
152
|
-
rescue JSON::ParserError
|
|
153
|
-
return nil
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
return nil if !imap_data.key?(:uids)
|
|
157
|
-
return nil if !imap_data[:uids].is_a?(Array)
|
|
158
|
-
|
|
159
|
-
imap_data
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def imap_ok?
|
|
163
|
-
return false if !exist?
|
|
164
|
-
return false if !imap_looks_like_json?
|
|
165
|
-
|
|
166
|
-
true
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def load_nth(index)
|
|
170
|
-
enumerator = Serializer::MboxEnumerator.new(mbox_pathname)
|
|
171
|
-
enumerator.each.with_index do |raw, i|
|
|
172
|
-
next if i != index
|
|
173
|
-
|
|
174
|
-
return Email::Mboxrd::Message.from_serialized(raw)
|
|
175
|
-
end
|
|
176
|
-
nil
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def imap_looks_like_json?
|
|
180
|
-
return false if !imap_exist?
|
|
181
|
-
|
|
182
|
-
content = File.read(imap_pathname)
|
|
183
|
-
content.start_with?("{")
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def write_imap_file
|
|
187
|
-
imap_data = {
|
|
188
|
-
version: CURRENT_VERSION,
|
|
189
|
-
uid_validity: @uid_validity,
|
|
190
|
-
uids: @uids
|
|
191
|
-
}
|
|
192
|
-
content = imap_data.to_json
|
|
193
|
-
File.open(imap_pathname, "w") { |f| f.write content }
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def write_blank_mbox_file
|
|
197
|
-
File.open(mbox_pathname, "w") { |f| f.write "" }
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def delete_files
|
|
201
|
-
File.unlink(imap_pathname) if imap_exist?
|
|
202
|
-
File.unlink(mbox_pathname) if mbox_exist?
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
def mbox_exist?
|
|
206
|
-
File.exist?(mbox_pathname)
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
def imap_exist?
|
|
210
|
-
File.exist?(imap_pathname)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def absolute_path(relative_path)
|
|
214
|
-
File.join(path, relative_path)
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
end
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "backup", type: :aruba, docker: true do
|
|
4
|
-
include_context "imap-backup connection"
|
|
5
|
-
include_context "message-fixtures"
|
|
6
|
-
|
|
7
|
-
let(:local_backup_path) { File.expand_path("~/backup") }
|
|
8
|
-
let(:backup_folders) { [{name: folder}] }
|
|
9
|
-
let(:folder) { "my-stuff" }
|
|
10
|
-
let(:messages_as_mbox) do
|
|
11
|
-
message_as_mbox_entry(msg1) + message_as_mbox_entry(msg2)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
let!(:pre) {}
|
|
15
|
-
let!(:setup) do
|
|
16
|
-
server_create_folder folder
|
|
17
|
-
send_email folder, msg1
|
|
18
|
-
send_email folder, msg2
|
|
19
|
-
create_config(accounts: [account.to_h])
|
|
20
|
-
|
|
21
|
-
run_command_and_stop("imap-backup backup")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
after do
|
|
25
|
-
server_delete_folder folder
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "downloads messages" do
|
|
29
|
-
expect(mbox_content(folder)).to eq(messages_as_mbox)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "IMAP metadata" do
|
|
33
|
-
let(:imap_metadata) { imap_parsed(folder) }
|
|
34
|
-
let(:folder_uids) { server_uids(folder) }
|
|
35
|
-
|
|
36
|
-
it "saves IMAP metadata in a JSON file" do
|
|
37
|
-
expect { imap_metadata }.to_not raise_error
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "saves a file version" do
|
|
41
|
-
expect(imap_metadata[:version].to_s).to match(/^[0-9.]$/)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "records IMAP ids" do
|
|
45
|
-
expect(imap_metadata[:uids]).to eq(folder_uids)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "records uid_validity" do
|
|
49
|
-
expect(imap_metadata[:uid_validity]).to eq(server_uid_validity(folder))
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context "when uid_validity does not match" do
|
|
53
|
-
let(:new_name) { "NEWNAME" }
|
|
54
|
-
let(:original_folder_uid_validity) { server_uid_validity(folder) }
|
|
55
|
-
let!(:pre) do
|
|
56
|
-
server_create_folder folder
|
|
57
|
-
send_email folder, msg3
|
|
58
|
-
original_folder_uid_validity
|
|
59
|
-
connection.run_backup
|
|
60
|
-
connection.disconnect
|
|
61
|
-
server_rename_folder folder, new_name
|
|
62
|
-
end
|
|
63
|
-
let(:renamed_folder) { "#{folder}-#{original_folder_uid_validity}" }
|
|
64
|
-
|
|
65
|
-
after do
|
|
66
|
-
server_delete_folder new_name
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "renames the old backup" do
|
|
70
|
-
expect(mbox_content(renamed_folder)).to eq(message_as_mbox_entry(msg3))
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "downloads messages" do
|
|
74
|
-
expect(mbox_content(folder)).to eq(messages_as_mbox)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context "when a renamed local backup exists" do
|
|
78
|
-
let!(:pre) do
|
|
79
|
-
super()
|
|
80
|
-
create_directory local_backup_path
|
|
81
|
-
File.write(imap_path(renamed_folder), "existing imap")
|
|
82
|
-
File.write(mbox_path(renamed_folder), "existing mbox")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "moves the old backup to a uniquely named directory" do
|
|
86
|
-
renamed = "#{folder}-#{original_folder_uid_validity}-1"
|
|
87
|
-
expect(mbox_content(renamed)).to eq(message_as_mbox_entry(msg3))
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context "when an unversioned .imap file is found" do
|
|
93
|
-
let!(:pre) do
|
|
94
|
-
create_directory local_backup_path
|
|
95
|
-
File.open(imap_path(folder), "w") { |f| f.write "old format imap" }
|
|
96
|
-
File.open(mbox_path(folder), "w") { |f| f.write "old format emails" }
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "replaces the .imap file with a versioned JSON file" do
|
|
100
|
-
expect(imap_metadata[:uids]).to eq(folder_uids)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "does the download" do
|
|
104
|
-
expect(mbox_content(folder)).to eq(messages_as_mbox)
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Running commands", type: :aruba do
|
|
4
|
-
before do
|
|
5
|
-
create_config(accounts: [])
|
|
6
|
-
run_command("imap-backup local accounts")
|
|
7
|
-
last_command_started.stop
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when no accounts are configured" do
|
|
11
|
-
it "succeeds" do
|
|
12
|
-
expect(last_command_started).to have_exit_status(0)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Running commands", type: :aruba do
|
|
4
|
-
before do
|
|
5
|
-
run_command("imap-backup")
|
|
6
|
-
last_command_started.stop
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
context "when the configuration file is missing" do
|
|
10
|
-
it "fails" do
|
|
11
|
-
expect(last_command_started).not_to have_exit_status(0)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
require "imap/backup/cli/folders"
|
|
3
|
-
|
|
4
|
-
RSpec.describe "folders", type: :feature, docker: true do
|
|
5
|
-
include_context "imap-backup connection"
|
|
6
|
-
|
|
7
|
-
let(:options) do
|
|
8
|
-
{accounts: "address@example.org"}
|
|
9
|
-
end
|
|
10
|
-
let(:folder) { "my-stuff" }
|
|
11
|
-
let(:output) { StringIO.new }
|
|
12
|
-
|
|
13
|
-
before do
|
|
14
|
-
allow(Imap::Backup::CLI::Accounts).to receive(:new) { [account] }
|
|
15
|
-
server_create_folder folder
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
around do |example|
|
|
19
|
-
stdout = $stdout
|
|
20
|
-
$stdout = output
|
|
21
|
-
example.run
|
|
22
|
-
$stdout = stdout
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
after do
|
|
26
|
-
FileUtils.rm_rf local_backup_path
|
|
27
|
-
server_delete_folder folder
|
|
28
|
-
connection.disconnect
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "lists account folders" do
|
|
32
|
-
Imap::Backup::CLI::Folders.new(options).run
|
|
33
|
-
|
|
34
|
-
expect(output.string).to match(/^\tmy-stuff\n/)
|
|
35
|
-
end
|
|
36
|
-
end
|
data/spec/features/helper.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Listing accounts", type: :aruba do
|
|
4
|
-
before do
|
|
5
|
-
create_config(accounts: [{"username": "me@example.com"}])
|
|
6
|
-
run_command_and_stop("imap-backup local accounts")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "lists accounts" do
|
|
10
|
-
expect(last_command_started).to have_output("me@example.com")
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Listing emails", type: :aruba do
|
|
4
|
-
let(:email) { "me@example.com" }
|
|
5
|
-
let(:account) do
|
|
6
|
-
{
|
|
7
|
-
username: email,
|
|
8
|
-
local_path: File.join(config_path, email.gsub("@", "_"))
|
|
9
|
-
}
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
create_config(accounts: [account])
|
|
14
|
-
store_email(email: email, folder: "my_folder", subject: "Ciao")
|
|
15
|
-
run_command_and_stop("imap-backup local list #{email} my_folder")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "lists emails" do
|
|
19
|
-
expect(last_command_started).to have_output(/1: Ciao/)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Listing account folders", type: :aruba do
|
|
4
|
-
let(:email) { "me@example.com" }
|
|
5
|
-
let(:account) do
|
|
6
|
-
{
|
|
7
|
-
username: email,
|
|
8
|
-
local_path: File.join(config_path, email.gsub("@", "_"))
|
|
9
|
-
}
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
create_config(accounts: [account])
|
|
14
|
-
store_email(email: email, folder: "my_folder", body: "Hi")
|
|
15
|
-
run_command_and_stop("imap-backup local folders #{email}")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "lists folders that have been backed up" do
|
|
19
|
-
expect(last_command_started).to have_output(%q("my_folder"))
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require "features/helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Show an email", type: :aruba do
|
|
4
|
-
let(:email) { "me@example.com" }
|
|
5
|
-
let(:account) do
|
|
6
|
-
{
|
|
7
|
-
username: email,
|
|
8
|
-
local_path: File.join(config_path, email.gsub("@", "_"))
|
|
9
|
-
}
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
create_config(accounts: [account])
|
|
14
|
-
store_email(
|
|
15
|
-
email: email,
|
|
16
|
-
folder: "my_folder",
|
|
17
|
-
uid: 99,
|
|
18
|
-
from: "me@example.com",
|
|
19
|
-
subject: "Hello",
|
|
20
|
-
body: "How're things?"
|
|
21
|
-
)
|
|
22
|
-
run_command_and_stop("imap-backup local show #{email} my_folder 99")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "shows the email" do
|
|
26
|
-
expected = <<~BODY
|
|
27
|
-
From: me@example.com
|
|
28
|
-
Subject: Hello
|
|
29
|
-
|
|
30
|
-
How're things?
|
|
31
|
-
BODY
|
|
32
|
-
expect(last_command_started).to have_output(expected)
|
|
33
|
-
end
|
|
34
|
-
end
|