imap-backup 14.5.2 → 14.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2b34662687d096c2dc7e4522910a009d12aeb4eb6f57c66c9f352ca3e1d8051
4
- data.tar.gz: 993b38940bf5c037cdf56a088b0dde8e380ec6bb081f1268eeddad72f6d9ea76
3
+ metadata.gz: 80b99aa3b4c713e6a88c9dbe504186fd64065a1d03d50d2d47a79de6ab14902f
4
+ data.tar.gz: c7a7d6f52b36819de9f660c488a8b4dfcf75794affa56547e197aab79c56cf7b
5
5
  SHA512:
6
- metadata.gz: 3cc751ae2e157ea6e1e6f59cff363c21536219fd732962f2a5d5b97e3c8373a9bf698868023cf212590d75b784f74b8a36a5c5c87d2e6005f71314aa1511be00
7
- data.tar.gz: 0ed900bd4e5ae9b01c3d10cefeb35da2d4185788fd6aded23b1f957dfdfae476c1a6dabb2804a61a889b91359f03e74a208eb6e3c411af255f61aec7a18435ad
6
+ metadata.gz: 75e98d37c675dab0d44fe98f2689f3dd36cf30eb2968f3c6260268e733122fccf212b0e91024b4031bc2b8243011e240a8370c03681dca4b21e8a155262292f5
7
+ data.tar.gz: 46ca660ed4f2f87a3285db448b6e77e052df7628e512c57d7600876abca390b5e872529c76ef1f01b4ae35035d08a4941e24dd298d3db5850f44968ccbda25c2
@@ -7,22 +7,22 @@ require "imap/backup/serializer"
7
7
  module Imap; end
8
8
 
9
9
  module Imap::Backup
10
- class CLI < Thor; end
10
+ class Account; end
11
11
 
12
12
  # Implements a folder enumerator for backed-up accounts
13
- class CLI::FolderEnumerator
13
+ class Account::FolderMapper
14
14
  def initialize(
15
+ account:,
15
16
  destination:,
16
- source:,
17
17
  destination_delimiter: "/",
18
18
  destination_prefix: "",
19
19
  source_delimiter: "/",
20
20
  source_prefix: ""
21
21
  )
22
+ @account = account
22
23
  @destination = destination
23
24
  @destination_delimiter = destination_delimiter
24
25
  @destination_prefix = destination_prefix
25
- @source = source
26
26
  @source_delimiter = source_delimiter
27
27
  @source_prefix = source_prefix
28
28
  end
@@ -48,7 +48,7 @@ module Imap::Backup
48
48
 
49
49
  attr_reader :destination
50
50
  attr_reader :destination_delimiter
51
- attr_reader :source
51
+ attr_reader :account
52
52
  attr_reader :source_delimiter
53
53
 
54
54
  def destination_prefix_clipped
@@ -94,7 +94,7 @@ module Imap::Backup
94
94
  end
95
95
 
96
96
  def source_local_path
97
- source.local_path
97
+ account.local_path
98
98
  end
99
99
 
100
100
  def source_folder_name(imap_pathname)
@@ -1,4 +1,4 @@
1
- require "imap/backup/account/serialized_folders"
1
+ require "imap/backup/account/folder_mapper"
2
2
  require "imap/backup/uploader"
3
3
 
4
4
  module Imap; end
@@ -8,15 +8,16 @@ module Imap::Backup
8
8
 
9
9
  # Restores all backed up folders to the server
10
10
  class Account::Restore
11
- def initialize(account:)
11
+ def initialize(account:, delimiter: "/", prefix: "")
12
12
  @account = account
13
+ @destination_delimiter = delimiter
14
+ @destination_prefix = prefix
13
15
  end
14
16
 
15
17
  # Runs the restore operation
16
18
  # @return [void]
17
19
  def run
18
- serialized_folders = Account::SerializedFolders.new(account: account)
19
- serialized_folders.each do |serializer, folder|
20
+ folders.each do |serializer, folder|
20
21
  Uploader.new(folder, serializer).run
21
22
  end
22
23
  end
@@ -24,5 +25,20 @@ module Imap::Backup
24
25
  private
25
26
 
26
27
  attr_reader :account
28
+ attr_reader :destination_delimiter
29
+ attr_reader :destination_prefix
30
+
31
+ def enumerator_options
32
+ {
33
+ account: account,
34
+ destination: account,
35
+ destination_delimiter: destination_delimiter,
36
+ destination_prefix: destination_prefix
37
+ }
38
+ end
39
+
40
+ def folders
41
+ Account::FolderMapper.new(**enumerator_options)
42
+ end
27
43
  end
28
44
  end
@@ -1,7 +1,6 @@
1
1
  require "json"
2
2
 
3
3
  require "imap/backup/account/client_factory"
4
- require "imap/backup/account/restore"
5
4
 
6
5
  module Imap; end
7
6
 
@@ -98,14 +97,6 @@ module Imap::Backup
98
97
  client.capability
99
98
  end
100
99
 
101
- # Restore the local backup to the server
102
- #
103
- # @return [void]
104
- def restore
105
- restore = Account::Restore.new(account: self)
106
- restore.run
107
- end
108
-
109
100
  # Indicates whether the account has been configured, and is ready
110
101
  # to be used
111
102
  #
@@ -15,7 +15,7 @@ module Imap::Backup
15
15
  include Thor::Actions
16
16
  include CLI::Helpers
17
17
 
18
- desc "accounts", "List locally backed-up accounts"
18
+ desc "accounts [OPTIONS]", "List locally backed-up accounts"
19
19
  config_option
20
20
  format_option
21
21
  quiet_option
@@ -34,7 +34,7 @@ module Imap::Backup
34
34
  end
35
35
 
36
36
  desc(
37
- "check",
37
+ "check [OPTIONS]",
38
38
  "Check the integrity of backups for all accounts (or the selected account(s))"
39
39
  )
40
40
  method_option(
@@ -54,7 +54,7 @@ module Imap::Backup
54
54
  Check.new(non_logging_options).run
55
55
  end
56
56
 
57
- desc "folders EMAIL", "List backed up folders"
57
+ desc "folders EMAIL [OPTIONS]", "List backed up folders"
58
58
  config_option
59
59
  format_option
60
60
  quiet_option
@@ -76,7 +76,7 @@ module Imap::Backup
76
76
  end
77
77
  end
78
78
 
79
- desc "list EMAIL FOLDER", "List emails in a folder"
79
+ desc "list EMAIL FOLDER [OPTIONS]", "List emails in a folder"
80
80
  config_option
81
81
  format_option
82
82
  quiet_option
@@ -101,7 +101,7 @@ module Imap::Backup
101
101
  end
102
102
  end
103
103
 
104
- desc "show EMAIL FOLDER UID[,UID]", "Show one or more emails"
104
+ desc "show EMAIL FOLDER UID[,UID] [OPTIONS]", "Show one or more emails"
105
105
  long_desc <<~DESC
106
106
  Prints out the requested emails.
107
107
  If more than one UID is given, they are separated by a header indicating
@@ -13,7 +13,7 @@ module Imap::Backup
13
13
  include Thor::Actions
14
14
  include CLI::Helpers
15
15
 
16
- desc "folders EMAIL", "List account folders"
16
+ desc "folders EMAIL [OPTIONS]", "List account folders"
17
17
  config_option
18
18
  format_option
19
19
  quiet_option
@@ -31,7 +31,7 @@ module Imap::Backup
31
31
  end
32
32
  end
33
33
 
34
- desc "capabilities EMAIL", "List server capabilities"
34
+ desc "capabilities EMAIL [OPTIONS]", "List server capabilities"
35
35
  long_desc <<~DESC
36
36
  Lists the IMAP capabilities supported by the IMAP server.
37
37
  DESC
@@ -49,7 +49,7 @@ module Imap::Backup
49
49
  Kernel.puts capabilities.join(", ")
50
50
  end
51
51
 
52
- desc "namespaces EMAIL", "List account namespaces"
52
+ desc "namespaces EMAIL [OPTIONS]", "List account namespaces"
53
53
  long_desc <<~DESC
54
54
  Lists namespaces defined for an email account.
55
55
 
@@ -1,5 +1,6 @@
1
1
  require "thor"
2
2
 
3
+ require "imap/backup/account/restore"
3
4
  require "imap/backup/cli/helpers"
4
5
  require "imap/backup/logger"
5
6
 
@@ -28,18 +29,18 @@ module Imap::Backup
28
29
  case
29
30
  when email && !options.key?(:accounts)
30
31
  account = account(config, email)
31
- account.restore
32
+ restore(account, **restore_options)
32
33
  when !email && !options.key?(:accounts)
33
34
  Logger.logger.info "Calling restore without an EMAIL parameter is deprecated"
34
- config.accounts.map(&:restore)
35
+ config.accounts.each { |a| restore(a) }
35
36
  when email && options.key?(:accounts)
36
37
  raise "Missing EMAIL parameter"
37
38
  when !email && options.key?(:accounts)
38
39
  Logger.logger.info(
39
- "Calling restore with the --account option is deprected, " \
40
+ "Calling restore with the --account option is deprecated, " \
40
41
  "please pass a single EMAIL parameter"
41
42
  )
42
- requested_accounts(config).each(&:restore)
43
+ requested_accounts(config).each { |a| restore(a) }
43
44
  end
44
45
  end
45
46
  end
@@ -48,5 +49,14 @@ module Imap::Backup
48
49
 
49
50
  attr_reader :email
50
51
  attr_reader :options
52
+
53
+ def restore(account, **options)
54
+ restore = Account::Restore.new(account: account, **options)
55
+ restore.run
56
+ end
57
+
58
+ def restore_options
59
+ options.slice(:delimiter, :prefix)
60
+ end
51
61
  end
52
62
  end
@@ -14,7 +14,7 @@ module Imap::Backup
14
14
  class CLI::Single < Thor
15
15
  include CLI::Helpers
16
16
 
17
- desc "backup", "Backup a single email account based on command-line parameters"
17
+ desc "backup [OPTIONS]", "Backup a single email account based on command-line parameters"
18
18
  long_desc <<~DESC
19
19
  This is a "stand-alone" backup command that doesn't require
20
20
  a configuration file.
@@ -1,6 +1,6 @@
1
+ require "imap/backup/account/folder_mapper"
1
2
  require "imap/backup/cli/backup"
2
3
  require "imap/backup/cli/helpers"
3
- require "imap/backup/cli/folder_enumerator"
4
4
  require "imap/backup/logger"
5
5
  require "imap/backup/migrator"
6
6
  require "imap/backup/mirror"
@@ -9,15 +9,13 @@ module Imap; end
9
9
 
10
10
  module Imap::Backup
11
11
  # Implements migration and mirroring
12
- class CLI::Transfer < Thor
13
- include Thor::Actions
12
+ class CLI::Transfer
14
13
  include CLI::Helpers
15
14
 
16
- # The possible vaues for the action parameter
15
+ # The possible values for the action parameter
17
16
  ACTIONS = %i(migrate mirror).freeze
18
17
 
19
18
  def initialize(action, source_email, destination_email, options)
20
- super([])
21
19
  @action = action
22
20
  @source_email = source_email
23
21
  @destination_email = destination_email
@@ -35,22 +33,20 @@ module Imap::Backup
35
33
  # @raise [RuntimeError] if the indicated action is unknown,
36
34
  # or the source and destination accounts are the same,
37
35
  # or either of the accounts is not configured,
38
- # or incompatible namespace/delimter parameters have been supplied
36
+ # or incompatible namespace/delimiter parameters have been supplied
39
37
  # @return [void]
40
- no_commands do
41
- def run
42
- raise "Unknown action '#{action}'" if !ACTIONS.include?(action)
43
-
44
- process_options!
45
- prepare_mirror if action == :mirror
46
-
47
- folders.each do |serializer, folder|
48
- case action
49
- when :migrate
50
- Migrator.new(serializer, folder, reset: reset).run
51
- when :mirror
52
- Mirror.new(serializer, folder).run
53
- end
38
+ def run
39
+ raise "Unknown action '#{action}'" if !ACTIONS.include?(action)
40
+
41
+ process_options!
42
+ prepare_mirror if action == :mirror
43
+
44
+ folders.each do |serializer, folder|
45
+ case action
46
+ when :migrate
47
+ Migrator.new(serializer, folder, reset: reset).run
48
+ when :mirror
49
+ Mirror.new(serializer, folder).run
54
50
  end
55
51
  end
56
52
  end
@@ -148,17 +144,17 @@ module Imap::Backup
148
144
 
149
145
  def enumerator_options
150
146
  {
147
+ account: source_account,
151
148
  destination: destination_account,
152
149
  destination_delimiter: destination_delimiter,
153
150
  destination_prefix: destination_prefix,
154
- source: source_account,
155
151
  source_delimiter: source_delimiter,
156
152
  source_prefix: source_prefix
157
153
  }
158
154
  end
159
155
 
160
156
  def folders
161
- CLI::FolderEnumerator.new(**enumerator_options)
157
+ Account::FolderMapper.new(**enumerator_options)
162
158
  end
163
159
 
164
160
  def destination_account
@@ -18,7 +18,10 @@ module Imap::Backup
18
18
  include Thor::Actions
19
19
  include CLI::Helpers
20
20
 
21
- desc "ignore-history EMAIL", "Skip downloading emails up to today for all configured folders"
21
+ desc(
22
+ "ignore-history EMAIL [OPTIONS]",
23
+ "Skip downloading emails up to today for all configured folders"
24
+ )
22
25
  config_option
23
26
  quiet_option
24
27
  verbose_option
@@ -30,7 +30,7 @@ module Imap::Backup
30
30
  In these cases there are two choices.
31
31
 
32
32
  You can use the `--automatic-namespaces` option.
33
- This wil query the source and detination servers for their
33
+ This will query the source and detination servers for their
34
34
  namespace configuration and will adapt paths accordingly.
35
35
  This option requires that both the source and destination
36
36
  servers are available and work with the provided parameters
@@ -220,7 +220,7 @@ module Imap::Backup
220
220
  desc "remote SUBCOMMAND [OPTIONS]", "View info about online accounts"
221
221
  subcommand "remote", Remote
222
222
 
223
- desc "restore EMAIL", "Restores a single account"
223
+ desc "restore EMAIL [OPTIONS]", "Restores a single account"
224
224
  long_desc <<~DESC
225
225
  Restores all backed-up emails for the supplied account to
226
226
  their original server.
@@ -229,14 +229,25 @@ module Imap::Backup
229
229
  config_option
230
230
  quiet_option
231
231
  verbose_option
232
- # Restores backed up meails to an account
232
+ method_option(
233
+ "delimiter",
234
+ type: :string,
235
+ desc: "the delimiter for folder names"
236
+ )
237
+ method_option(
238
+ "prefix",
239
+ type: :string,
240
+ desc: "a prefix (namespace) to add to folder names",
241
+ aliases: ["-d"]
242
+ )
243
+ # Restores backed up emails to an account
233
244
  # @return [void]
234
245
  def restore(email = nil)
235
246
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
236
247
  Restore.new(email, non_logging_options).run
237
248
  end
238
249
 
239
- desc "setup", "Configure imap-backup"
250
+ desc "setup [OPTIONS]", "Configure imap-backup"
240
251
  long_desc <<~DESC
241
252
  A menu-driven command-line application used to configure imap-backup.
242
253
  Configure email accounts to back up.
@@ -8,6 +8,8 @@ require "imap/backup/serializer/transaction"
8
8
  module Imap; end
9
9
 
10
10
  module Imap::Backup
11
+ class Serializer; end
12
+
11
13
  # Wraps the Serializer, delaying metadata appends
12
14
  class Serializer::DelayedMetadataSerializer
13
15
  extend Forwardable
@@ -7,6 +7,8 @@ require "imap/backup/serializer/transaction"
7
7
  module Imap; end
8
8
 
9
9
  module Imap::Backup
10
+ class Serializer; end
11
+
10
12
  # Stores message metadata
11
13
  class Serializer::Imap
12
14
  # The version number to store in the metadata file
@@ -3,6 +3,8 @@ require "imap/backup/serializer/transaction"
3
3
  module Imap; end
4
4
 
5
5
  module Imap::Backup
6
+ class Serializer; end
7
+
6
8
  # Stores messages
7
9
  class Serializer::Mbox
8
10
  # @return [String] The path of the mailbox file, without the '.mbox' extension
@@ -5,6 +5,8 @@ require "imap/backup/email/mboxrd/message"
5
5
  module Imap; end
6
6
 
7
7
  module Imap::Backup
8
+ class Serializer; end
9
+
8
10
  # Represents a stored message
9
11
  class Serializer::Message
10
12
  # @return [Array[Symbol]] the message's flags
@@ -1,6 +1,8 @@
1
1
  module Imap; end
2
2
 
3
3
  module Imap::Backup
4
+ class Serializer; end
5
+
4
6
  # Enumerates over a list of stores messages
5
7
  class Serializer::MessageEnumerator
6
8
  # @param imap [Serializer::Imap] the metadata serializer for the folder
@@ -3,6 +3,8 @@ require "imap/backup/file_mode"
3
3
  module Imap; end
4
4
 
5
5
  module Imap::Backup
6
+ class Serializer; end
7
+
6
8
  # Ensures a file has the desired permissions
7
9
  class Serializer::PermissionChecker
8
10
  # @param filename [String] the file name
@@ -1,6 +1,8 @@
1
1
  module Imap; end
2
2
 
3
3
  module Imap::Backup
4
+ class Serializer; end
5
+
4
6
  # Stores data during a transaction
5
7
  class Serializer::Transaction
6
8
  # @return the transaction's stored data
@@ -3,6 +3,8 @@ require "imap/backup/serializer"
3
3
  module Imap; end
4
4
 
5
5
  module Imap::Backup
6
+ class Serializer; end
7
+
6
8
  # Finds a name that can be used to rename a serialized folder
7
9
  class Serializer::UnusedNameFinder
8
10
  # @param serializer [Serializer] a folder serializer
@@ -5,6 +5,8 @@ require "imap/backup/serializer/imap"
5
5
  module Imap; end
6
6
 
7
7
  module Imap::Backup
8
+ class Serializer; end
9
+
8
10
  # Migrates serialized folder metadata from the version 2 format to the version 3 format
9
11
  class Serializer::Version2Migrator
10
12
  # @param folder_path [String] the base pathv(without extension) of the folder backup
@@ -4,9 +4,9 @@ module Imap::Backup
4
4
  # @private
5
5
  MAJOR = 14
6
6
  # @private
7
- MINOR = 5
7
+ MINOR = 6
8
8
  # @private
9
- REVISION = 2
9
+ REVISION = 0
10
10
  # @private
11
11
  PRE = nil
12
12
  # The application version
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.5.2
4
+ version: 14.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-22 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -144,12 +144,12 @@ files:
144
144
  - lib/imap/backup/account/folder.rb
145
145
  - lib/imap/backup/account/folder_backup.rb
146
146
  - lib/imap/backup/account/folder_ensurer.rb
147
+ - lib/imap/backup/account/folder_mapper.rb
147
148
  - lib/imap/backup/account/local_only_folder_deleter.rb
148
149
  - lib/imap/backup/account/restore.rb
149
150
  - lib/imap/backup/account/serialized_folders.rb
150
151
  - lib/imap/backup/cli.rb
151
152
  - lib/imap/backup/cli/backup.rb
152
- - lib/imap/backup/cli/folder_enumerator.rb
153
153
  - lib/imap/backup/cli/helpers.rb
154
154
  - lib/imap/backup/cli/local.rb
155
155
  - lib/imap/backup/cli/local/check.rb