imap-backup 14.4.1 → 14.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/bin/imap-backup +2 -2
  3. data/docs/api.md +20 -0
  4. data/docs/development.md +18 -7
  5. data/lib/imap/backup/account/backup.rb +6 -3
  6. data/lib/imap/backup/account/backup_folders.rb +6 -3
  7. data/lib/imap/backup/account/client_factory.rb +3 -2
  8. data/lib/imap/backup/account/folder.rb +10 -9
  9. data/lib/imap/backup/account/folder_backup.rb +5 -4
  10. data/lib/imap/backup/account/folder_ensurer.rb +5 -2
  11. data/lib/imap/backup/account/local_only_folder_deleter.rb +7 -3
  12. data/lib/imap/backup/account/restore.rb +5 -2
  13. data/lib/imap/backup/account/serialized_folders.rb +3 -2
  14. data/lib/imap/backup/account.rb +85 -0
  15. data/lib/imap/backup/cli/backup.rb +14 -12
  16. data/lib/imap/backup/cli/folder_enumerator.rb +5 -5
  17. data/lib/imap/backup/cli/local/check.rb +4 -2
  18. data/lib/imap/backup/cli/local.rb +50 -49
  19. data/lib/imap/backup/cli/remote.rb +46 -46
  20. data/lib/imap/backup/cli/restore.rb +5 -3
  21. data/lib/imap/backup/cli/setup.rb +4 -2
  22. data/lib/imap/backup/cli/single/backup.rb +3 -3
  23. data/lib/imap/backup/cli/stats.rb +54 -52
  24. data/lib/imap/backup/cli/transfer.rb +93 -93
  25. data/lib/imap/backup/cli/utils.rb +28 -28
  26. data/lib/imap/backup/cli.rb +12 -0
  27. data/lib/imap/backup/client/default.rb +5 -5
  28. data/lib/imap/backup/configuration.rb +5 -4
  29. data/lib/imap/backup/downloader.rb +6 -14
  30. data/lib/imap/backup/email/mboxrd/message.rb +2 -3
  31. data/lib/imap/backup/file_mode.rb +4 -2
  32. data/lib/imap/backup/flag_refresher.rb +3 -3
  33. data/lib/imap/backup/local_only_message_deleter.rb +5 -3
  34. data/lib/imap/backup/migrator.rb +6 -4
  35. data/lib/imap/backup/mirror/map.rb +3 -3
  36. data/lib/imap/backup/mirror.rb +5 -5
  37. data/lib/imap/backup/serializer/appender.rb +7 -4
  38. data/lib/imap/backup/serializer/delayed_metadata_serializer.rb +15 -2
  39. data/lib/imap/backup/serializer/directory.rb +12 -3
  40. data/lib/imap/backup/serializer/folder_maker.rb +12 -4
  41. data/lib/imap/backup/serializer/imap.rb +5 -1
  42. data/lib/imap/backup/serializer/integrity_checker.rb +10 -3
  43. data/lib/imap/backup/serializer/mbox.rb +2 -1
  44. data/lib/imap/backup/serializer/message.rb +10 -18
  45. data/lib/imap/backup/serializer/permission_checker.rb +5 -3
  46. data/lib/imap/backup/serializer/transaction.rb +4 -1
  47. data/lib/imap/backup/serializer/unused_name_finder.rb +4 -2
  48. data/lib/imap/backup/serializer/version2_migrator.rb +2 -2
  49. data/lib/imap/backup/serializer.rb +5 -0
  50. data/lib/imap/backup/setup/account/header.rb +3 -3
  51. data/lib/imap/backup/setup/account.rb +6 -6
  52. data/lib/imap/backup/setup/asker.rb +6 -4
  53. data/lib/imap/backup/setup/backup_path.rb +3 -4
  54. data/lib/imap/backup/setup/connection_tester.rb +4 -2
  55. data/lib/imap/backup/setup/{email.rb → email_changer.rb} +4 -4
  56. data/lib/imap/backup/setup/folder_chooser.rb +2 -2
  57. data/lib/imap/backup/setup/global_options/download_strategy_chooser.rb +2 -2
  58. data/lib/imap/backup/setup/global_options.rb +2 -2
  59. data/lib/imap/backup/setup.rb +2 -2
  60. data/lib/imap/backup/text/sanitizer.rb +2 -2
  61. data/lib/imap/backup/thunderbird/mailbox_exporter.rb +10 -8
  62. data/lib/imap/backup/uploader.rb +3 -3
  63. data/lib/imap/backup/version.rb +1 -1
  64. metadata +4 -4
  65. data/lib/imap/backup/cli_coverage.rb +0 -21
@@ -4,9 +4,6 @@ module Imap; end
4
4
 
5
5
  module Imap::Backup
6
6
  class Serializer::PermissionChecker
7
- attr_reader :filename
8
- attr_reader :limit
9
-
10
7
  def initialize(filename:, limit:)
11
8
  @filename = filename
12
9
  @limit = limit
@@ -26,5 +23,10 @@ module Imap::Backup
26
23
  )
27
24
  raise message
28
25
  end
26
+
27
+ private
28
+
29
+ attr_reader :filename
30
+ attr_reader :limit
29
31
  end
30
32
  end
@@ -2,7 +2,6 @@ module Imap; end
2
2
 
3
3
  module Imap::Backup
4
4
  class Serializer::Transaction
5
- attr_reader :owner
6
5
  attr_reader :data
7
6
 
8
7
  def initialize(owner:)
@@ -33,5 +32,9 @@ module Imap::Backup
33
32
  def fail_outside_transaction!(method)
34
33
  raise "#{owner.class}##{method} can only be called inside a transaction" if !in_transaction?
35
34
  end
35
+
36
+ private
37
+
38
+ attr_reader :owner
36
39
  end
37
40
  end
@@ -4,8 +4,6 @@ module Imap; end
4
4
 
5
5
  module Imap::Backup
6
6
  class Serializer::UnusedNameFinder
7
- attr_reader :serializer
8
-
9
7
  def initialize(serializer:)
10
8
  @serializer = serializer
11
9
  end
@@ -25,5 +23,9 @@ module Imap::Backup
25
23
 
26
24
  folder
27
25
  end
26
+
27
+ private
28
+
29
+ attr_reader :serializer
28
30
  end
29
31
  end
@@ -6,8 +6,6 @@ module Imap; end
6
6
 
7
7
  module Imap::Backup
8
8
  class Serializer::Version2Migrator
9
- attr_reader :folder_path
10
-
11
9
  def initialize(folder_path)
12
10
  @folder_path = folder_path
13
11
  end
@@ -39,6 +37,8 @@ module Imap::Backup
39
37
 
40
38
  private
41
39
 
40
+ attr_reader :folder_path
41
+
42
42
  def imap_pathname
43
43
  "#{folder_path}.imap"
44
44
  end
@@ -35,6 +35,11 @@ module Imap::Backup
35
35
  @validated = nil
36
36
  end
37
37
 
38
+ # Calls the supplied block.
39
+ # This method is present so that this class implements the same
40
+ # interface as {DelayedMetadataSerializer}
41
+ #
42
+ # @return [void]
38
43
  def transaction(&block)
39
44
  block.call
40
45
  end
@@ -9,9 +9,6 @@ module Imap::Backup
9
9
  class Setup::Account; end
10
10
 
11
11
  class Setup::Account::Header
12
- attr_reader :account
13
- attr_reader :menu
14
-
15
12
  def initialize(menu:, account:)
16
13
  @menu = menu
17
14
  @account = account
@@ -41,6 +38,9 @@ module Imap::Backup
41
38
 
42
39
  private
43
40
 
41
+ attr_reader :account
42
+ attr_reader :menu
43
+
44
44
  def modified_flag
45
45
  account.modified? ? "*" : ""
46
46
  end
@@ -2,7 +2,7 @@ require "imap/backup/setup/account/header"
2
2
  require "imap/backup/setup/asker"
3
3
  require "imap/backup/setup/backup_path"
4
4
  require "imap/backup/setup/connection_tester"
5
- require "imap/backup/setup/email"
5
+ require "imap/backup/setup/email_changer"
6
6
  require "imap/backup/setup/folder_chooser"
7
7
 
8
8
  module Imap; end
@@ -11,10 +11,6 @@ module Imap::Backup
11
11
  class Setup; end
12
12
 
13
13
  class Setup::Account
14
- attr_reader :account
15
- attr_reader :config
16
- attr_reader :highline
17
-
18
14
  def initialize(config, account, highline)
19
15
  @account = account
20
16
  @config = config
@@ -36,6 +32,10 @@ module Imap::Backup
36
32
 
37
33
  private
38
34
 
35
+ attr_reader :account
36
+ attr_reader :config
37
+ attr_reader :highline
38
+
39
39
  def create_menu
40
40
  highline.choose do |menu|
41
41
  header menu
@@ -62,7 +62,7 @@ module Imap::Backup
62
62
 
63
63
  def modify_email(menu)
64
64
  menu.choice("modify email") do
65
- Setup::Email.new(account: account, config: config).run
65
+ Setup::EmailChanger.new(account: account, config: config).run
66
66
  end
67
67
  end
68
68
 
@@ -4,10 +4,6 @@ module Imap::Backup
4
4
  class Setup; end
5
5
 
6
6
  class Setup::Asker
7
- EMAIL_MATCHER = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$/i.freeze
8
-
9
- attr_reader :highline
10
-
11
7
  def initialize(highline)
12
8
  @highline = highline
13
9
  end
@@ -40,5 +36,11 @@ module Imap::Backup
40
36
  def self.password
41
37
  new(Setup.highline).password
42
38
  end
39
+
40
+ private
41
+
42
+ EMAIL_MATCHER = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$/i.freeze
43
+
44
+ attr_reader :highline
43
45
  end
44
46
  end
@@ -4,9 +4,6 @@ module Imap::Backup
4
4
  class Setup; end
5
5
 
6
6
  class Setup::BackupPath
7
- attr_reader :account
8
- attr_reader :config
9
-
10
7
  def initialize(account:, config:)
11
8
  @account = account
12
9
  @config = config
@@ -15,7 +12,6 @@ module Imap::Backup
15
12
  def run
16
13
  account.local_path = highline.ask("backup directory: ") do |q|
17
14
  q.default = account.local_path
18
- q.readline = true
19
15
  q.validate = ->(path) { path_modification_validator(path) }
20
16
  q.responses[:not_valid] = "Choose a different directory "
21
17
  end
@@ -23,6 +19,9 @@ module Imap::Backup
23
19
 
24
20
  private
25
21
 
22
+ attr_reader :account
23
+ attr_reader :config
24
+
26
25
  def highline
27
26
  Setup.highline
28
27
  end
@@ -6,8 +6,6 @@ module Imap::Backup
6
6
  class Setup; end
7
7
 
8
8
  class Setup::ConnectionTester
9
- attr_reader :account
10
-
11
9
  def initialize(account)
12
10
  @account = account
13
11
  end
@@ -20,5 +18,9 @@ module Imap::Backup
20
18
  rescue StandardError => e
21
19
  "Unexpected error: #{e}"
22
20
  end
21
+
22
+ private
23
+
24
+ attr_reader :account
23
25
  end
24
26
  end
@@ -6,10 +6,7 @@ module Imap; end
6
6
  module Imap::Backup
7
7
  class Setup; end
8
8
 
9
- class Setup::Email
10
- attr_reader :account
11
- attr_reader :config
12
-
9
+ class Setup::EmailChanger
13
10
  def initialize(account:, config:)
14
11
  @account = account
15
12
  @config = config
@@ -34,6 +31,9 @@ module Imap::Backup
34
31
 
35
32
  private
36
33
 
34
+ attr_reader :account
35
+ attr_reader :config
36
+
37
37
  def default_server(username)
38
38
  provider = Email::Provider.for_address(username)
39
39
 
@@ -6,8 +6,6 @@ module Imap::Backup
6
6
  class Setup; end
7
7
 
8
8
  class Setup::FolderChooser
9
- attr_reader :account
10
-
11
9
  def initialize(account)
12
10
  @account = account
13
11
  end
@@ -36,6 +34,8 @@ module Imap::Backup
36
34
 
37
35
  private
38
36
 
37
+ attr_reader :account
38
+
39
39
  def show_menu
40
40
  highline.choose do |menu|
41
41
  menu.header = <<~MENU.chomp
@@ -6,8 +6,6 @@ class Imap::Backup::Setup; end
6
6
 
7
7
  class Imap::Backup::Setup::GlobalOptions
8
8
  class DownloadStrategyChooser
9
- attr_reader :config
10
-
11
9
  def initialize(config:)
12
10
  @config = config
13
11
  end
@@ -23,6 +21,8 @@ class Imap::Backup::Setup::GlobalOptions
23
21
 
24
22
  private
25
23
 
24
+ attr_reader :config
25
+
26
26
  def create_menu
27
27
  strategies = Imap::Backup::Configuration::DOWNLOAD_STRATEGIES
28
28
  highline.choose do |menu|
@@ -7,8 +7,6 @@ module Imap::Backup
7
7
  class Setup; end
8
8
 
9
9
  class Setup::GlobalOptions
10
- attr_reader :config
11
-
12
10
  def initialize(config:)
13
11
  @config = config
14
12
  end
@@ -24,6 +22,8 @@ module Imap::Backup
24
22
 
25
23
  private
26
24
 
25
+ attr_reader :config
26
+
27
27
  def show_menu
28
28
  highline.choose do |menu|
29
29
  menu.header = <<~MENU.chomp
@@ -16,8 +16,6 @@ module Imap::Backup
16
16
  end
17
17
  self.highline = HighLine.new
18
18
 
19
- attr_accessor :config
20
-
21
19
  def initialize(config:)
22
20
  @config = config
23
21
  end
@@ -33,6 +31,8 @@ module Imap::Backup
33
31
 
34
32
  private
35
33
 
34
+ attr_accessor :config
35
+
36
36
  def show_menu
37
37
  self.class.highline.choose do |menu|
38
38
  menu.header = <<~MENU.chomp
@@ -8,8 +8,6 @@ module Imap::Backup
8
8
  class Text::Sanitizer
9
9
  extend Forwardable
10
10
 
11
- attr_reader :output
12
-
13
11
  delegate puts: :output
14
12
  delegate write: :output
15
13
 
@@ -39,6 +37,8 @@ module Imap::Backup
39
37
 
40
38
  private
41
39
 
40
+ attr_reader :output
41
+
42
42
  def sanitize(text)
43
43
  # Hide password in Net::IMAP debug output
44
44
  text.gsub(
@@ -5,14 +5,9 @@ require "imap/backup/logger"
5
5
  module Imap; end
6
6
 
7
7
  module Imap::Backup
8
- class Thunderbird::MailboxExporter
9
- EXPORT_PREFIX = "imap-backup".freeze
10
-
11
- attr_reader :email
12
- attr_reader :serializer
13
- attr_reader :profile
14
- attr_reader :force
8
+ class Thunderbird; end
15
9
 
10
+ class Thunderbird::MailboxExporter
16
11
  def initialize(email, serializer, profile, force: false)
17
12
  @email = email
18
13
  @serializer = serializer
@@ -48,6 +43,13 @@ module Imap::Backup
48
43
 
49
44
  private
50
45
 
46
+ EXPORT_PREFIX = "imap-backup".freeze
47
+
48
+ attr_reader :email
49
+ attr_reader :serializer
50
+ attr_reader :profile
51
+ attr_reader :force
52
+
51
53
  def profile_set_up
52
54
  File.exist?(profile.local_folders_path)
53
55
  end
@@ -95,7 +97,7 @@ module Imap::Backup
95
97
  @local_folder ||= begin
96
98
  top_level_folders = [EXPORT_PREFIX, email]
97
99
  prefixed_folder_path = File.join(top_level_folders, serializer.folder)
98
- Thunderbird::LocalFolder.new(profile, prefixed_folder_path)
100
+ ::Thunderbird::LocalFolder.new(profile, prefixed_folder_path)
99
101
  end
100
102
  end
101
103
 
@@ -6,9 +6,6 @@ module Imap; end
6
6
 
7
7
  module Imap::Backup
8
8
  class Uploader
9
- attr_reader :folder
10
- attr_reader :serializer
11
-
12
9
  def initialize(folder, serializer)
13
10
  @folder = folder
14
11
  @serializer = serializer
@@ -32,6 +29,9 @@ module Imap::Backup
32
29
 
33
30
  private
34
31
 
32
+ attr_reader :folder
33
+ attr_reader :serializer
34
+
35
35
  def upload_message(message, index)
36
36
  return if message.nil?
37
37
 
@@ -3,7 +3,7 @@ module Imap; end
3
3
  module Imap::Backup
4
4
  MAJOR = 14
5
5
  MINOR = 4
6
- REVISION = 1
6
+ REVISION = 3
7
7
  PRE = nil
8
8
  VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
9
9
  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: 14.4.1
4
+ version: 14.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-15 00:00:00.000000000 Z
11
+ date: 2023-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -133,6 +133,7 @@ files:
133
133
  - LICENSE
134
134
  - README.md
135
135
  - bin/imap-backup
136
+ - docs/api.md
136
137
  - docs/delimiters-and-prefixes.md
137
138
  - docs/development.md
138
139
  - docs/migrate-server-keep-address.md
@@ -162,7 +163,6 @@ files:
162
163
  - lib/imap/backup/cli/stats.rb
163
164
  - lib/imap/backup/cli/transfer.rb
164
165
  - lib/imap/backup/cli/utils.rb
165
- - lib/imap/backup/cli_coverage.rb
166
166
  - lib/imap/backup/client/apple_mail.rb
167
167
  - lib/imap/backup/client/automatic_login_wrapper.rb
168
168
  - lib/imap/backup/client/default.rb
@@ -206,7 +206,7 @@ files:
206
206
  - lib/imap/backup/setup/asker.rb
207
207
  - lib/imap/backup/setup/backup_path.rb
208
208
  - lib/imap/backup/setup/connection_tester.rb
209
- - lib/imap/backup/setup/email.rb
209
+ - lib/imap/backup/setup/email_changer.rb
210
210
  - lib/imap/backup/setup/folder_chooser.rb
211
211
  - lib/imap/backup/setup/global_options.rb
212
212
  - lib/imap/backup/setup/global_options/download_strategy_chooser.rb
@@ -1,21 +0,0 @@
1
- module Imap; end
2
-
3
- module Imap::Backup
4
- class CliCoverage
5
- def self.conditionally_activate
6
- return if !ENV.key?("COVERAGE")
7
-
8
- # Collect coverage separately
9
- ENV["SIMPLECOV_COMMAND_NAME"] = "#{ENV.fetch('COVERAGE')} #{ARGV.join(' ')} coverage"
10
- require "simplecov"
11
-
12
- # Silence output
13
- SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
14
- SimpleCov.print_error_status = false
15
-
16
- # Ensure SimpleCov doesn't filter out all out code
17
- project_root = File.expand_path("..", __dir__)
18
- SimpleCov.root project_root
19
- end
20
- end
21
- end