imap-backup 15.0.1 → 15.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3504dad0e3f788bcfa95b38065e0ff4035239886461689c478a2e991f5e06cf9
4
- data.tar.gz: 7d1151b5fb25f2d84ae2013f8f9f74fee7f998ca36b29333bf44151e52726376
3
+ metadata.gz: de4f5bfc1260430435d380fd3fa6c315efad4ef503b0429bce041615d3ae2e10
4
+ data.tar.gz: 3c1541e30cb01d1ecd6da9372e79b8e8c71f119eee5a11770bef76b90e89e037
5
5
  SHA512:
6
- metadata.gz: 3ec40ec413bd6bedce02d4c823ae1654c06585223532d1260bf01fe4ef0e8ba6e0b8c25c7adf0d2b39f8ff29c5199251d07fb9234a75a3ac50856075c91ccc52
7
- data.tar.gz: d31020db8b37295d8d7209758161ce4fe5d16869a6976f3538e12b2d7a74f3cb363328d0dcd79ce665a2b113cf7f6289794ee328ded6e8a73cb544c4d0897428
6
+ metadata.gz: 25aa565a7860560958b59c5f88f67b470128405acc15fc67fe3683152d0ea9c63d8787287f006249a22b26a88d92425bed653254126ef92259ea85022b33efcb
7
+ data.tar.gz: 54d8df69cef34dcafd3ba97f63f202b0f00e2306f8e12c4ea7329dfae5028e42e9a4050630fae2d03131048aa3c70e90ee7bb8a49a1388084bd136ad3e0ce973
@@ -32,7 +32,7 @@ module Imap::Backup
32
32
  # @yieldparam serializer [Serializer] the folder's serializer
33
33
  # @yieldparam folder [Account::Folder] the online folder
34
34
  # @return [Enumerator, void]
35
- def each
35
+ def each(&block)
36
36
  return enum_for(:each) if !block_given?
37
37
 
38
38
  glob = File.join(source_local_path, "**", "*.imap")
@@ -40,7 +40,7 @@ module Imap::Backup
40
40
  name = source_folder_name(path)
41
41
  serializer = Serializer.new(source_local_path, name)
42
42
  folder = destination_folder_for_path(name)
43
- yield serializer, folder
43
+ block.call(serializer, folder)
44
44
  end
45
45
  end
46
46
 
@@ -1,5 +1,6 @@
1
1
  require "thor"
2
2
 
3
+ require "imap/backup/cli/options"
3
4
  require "imap/backup/configuration"
4
5
  require "imap/backup/configuration_not_found"
5
6
 
@@ -11,67 +12,8 @@ module Imap::Backup
11
12
  # Provides helper methods for CLI classes
12
13
  module CLI::Helpers
13
14
  def self.included(base)
14
- base.class_eval do
15
- def self.accounts_option
16
- method_option(
17
- "accounts",
18
- type: :string,
19
- desc: "a comma-separated list of accounts (defaults to all configured accounts)",
20
- aliases: ["-a"]
21
- )
22
- end
23
-
24
- def self.config_option
25
- method_option(
26
- "config",
27
- type: :string,
28
- desc: "supply the configuration file path (default: ~/.imap-backup/config.json)",
29
- aliases: ["-c"]
30
- )
31
- end
32
-
33
- def self.format_option
34
- method_option(
35
- "format",
36
- type: :string,
37
- desc: "the output type, 'text' for plain text or 'json'",
38
- aliases: ["-f"]
39
- )
40
- end
41
-
42
- def self.quiet_option
43
- method_option(
44
- "quiet",
45
- type: :boolean,
46
- desc: "silence all output",
47
- aliases: ["-q"]
48
- )
49
- end
50
-
51
- def self.refresh_option
52
- method_option(
53
- "refresh",
54
- type: :boolean,
55
- desc: "in the default 'keep all emails' mode, " \
56
- "updates flags for messages that are already downloaded",
57
- aliases: ["-r"]
58
- )
59
- end
60
-
61
- def self.verbose_option
62
- method_option(
63
- "verbose",
64
- type: :boolean,
65
- desc:
66
- "increase the amount of logging. " \
67
- "Without this option, the program gives minimal output. " \
68
- "Using this option once gives more detailed output. " \
69
- "Whereas, using this option twice also shows all IMAP network calls",
70
- aliases: ["-v"],
71
- repeatable: true
72
- )
73
- end
74
- end
15
+ options = CLI::Options.new(base: base)
16
+ options.define_options
75
17
  end
76
18
 
77
19
  # Processes command-line parameters
@@ -81,7 +23,7 @@ module Imap::Backup
81
23
  def options
82
24
  @symbolized_options ||= # rubocop:disable Naming/MemoizedInstanceVariableName
83
25
  begin
84
- options = super()
26
+ options = super
85
27
  options.each.with_object({}) do |(k, v), acc|
86
28
  key =
87
29
  if k.is_a?(String)
@@ -0,0 +1,74 @@
1
+ require "thor"
2
+
3
+ module Imap; end
4
+
5
+ module Imap::Backup
6
+ class CLI < Thor; end
7
+
8
+ # Defines option methods for CLI classes
9
+ class CLI::Options
10
+ attr_reader :base
11
+
12
+ # Options common to many commands
13
+ OPTIONS = [
14
+ {
15
+ name: "accounts",
16
+ parameters: {
17
+ type: :string, aliases: ["-a"],
18
+ desc: "a comma-separated list of accounts (defaults to all configured accounts)"
19
+ }
20
+ },
21
+ {
22
+ name: "config",
23
+ parameters: {
24
+ type: :string, aliases: ["-c"],
25
+ desc: "supply the configuration file path (default: ~/.imap-backup/config.json)"
26
+ }
27
+ },
28
+ {
29
+ name: "format",
30
+ parameters: {
31
+ type: :string, desc: "the output type, 'text' for plain text or 'json'", aliases: ["-f"]
32
+ }
33
+ },
34
+ {
35
+ name: "quiet",
36
+ parameters: {
37
+ type: :boolean, desc: "silence all output", aliases: ["-q"]
38
+ }
39
+ },
40
+ {
41
+ name: "refresh",
42
+ parameters: {
43
+ type: :boolean, aliases: ["-r"],
44
+ desc: "in the default 'keep all emails' mode, " \
45
+ "updates flags for messages that are already downloaded"
46
+ }
47
+ },
48
+ {
49
+ name: "verbose",
50
+ parameters: {
51
+ type: :boolean, aliases: ["-v"], repeatable: true,
52
+ desc: "increase the amount of logging. " \
53
+ "Without this option, the program gives minimal output. " \
54
+ "Using this option once gives more detailed output. " \
55
+ "Whereas, using this option twice also shows all IMAP network calls"
56
+ }
57
+ }
58
+ ].freeze
59
+
60
+ def initialize(base:)
61
+ @base = base
62
+ end
63
+
64
+ def define_options
65
+ OPTIONS.each do |option|
66
+ base.singleton_class.class_eval do
67
+ define_method("#{option[:name]}_option") do
68
+ method_option(option[:name], **option[:parameters])
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -28,6 +28,13 @@ module Imap::Backup
28
28
 
29
29
  def refresh_block(uids)
30
30
  uids_and_flags = folder.fetch_multi(uids, ["FLAGS"])
31
+ if !uids_and_flags
32
+ Logger.logger.debug(
33
+ "[#{folder.name}] failed to fetch flags for #{uids} - " \
34
+ "cannot refresh flags"
35
+ )
36
+ return
37
+ end
31
38
  uids_and_flags.each do |uid_and_flags|
32
39
  uid = uid_and_flags[:uid]
33
40
  flags = uid_and_flags[:flags]
@@ -51,11 +51,11 @@ module Imap::Backup
51
51
  # Wraps a block, filtering output to standard error,
52
52
  # hidng passwords and outputs the results to standard out
53
53
  # @return [void]
54
- def self.sanitize_stderr
54
+ def self.sanitize_stderr(&block)
55
55
  sanitizer = Text::Sanitizer.new($stdout)
56
56
  previous_stderr = $stderr
57
57
  $stderr = sanitizer
58
- yield
58
+ block.call
59
59
  ensure
60
60
  sanitizer.flush
61
61
  $stderr = previous_stderr
@@ -13,9 +13,9 @@ module Imap::Backup
13
13
  # @param on_error [Proc] a block to call when an error occurs
14
14
  # @raise any error ocurring more than `limit` times
15
15
  # @return the result of any successful completion of the block
16
- def retry_on_error(errors:, limit: 10, on_error: nil)
16
+ def retry_on_error(errors:, limit: 10, on_error: nil, &block)
17
17
  tries ||= 1
18
- yield
18
+ block.call
19
19
  rescue *errors => e
20
20
  if tries < limit
21
21
  message = "#{e}, attempt #{tries} of #{limit}"
@@ -14,14 +14,14 @@ module Imap::Backup
14
14
  # @param uids [Array<Integer>] the message UIDs of the messages to iterate over
15
15
  # @yieldparam message [Serializer::Message]
16
16
  # @return [void]
17
- def run(uids:)
17
+ def run(uids:, &block)
18
18
  uids.each do |uid_maybe_string|
19
19
  uid = uid_maybe_string.to_i
20
20
  message = imap.get(uid)
21
21
 
22
22
  next if !message
23
23
 
24
- yield message
24
+ block.call(message)
25
25
  end
26
26
  end
27
27
 
@@ -6,7 +6,7 @@ module Imap::Backup
6
6
  # @private
7
7
  MINOR = 0
8
8
  # @private
9
- REVISION = 1
9
+ REVISION = 2
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: 15.0.1
4
+ version: 15.0.2
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-06-04 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -153,6 +153,7 @@ files:
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
156
+ - lib/imap/backup/cli/options.rb
156
157
  - lib/imap/backup/cli/remote.rb
157
158
  - lib/imap/backup/cli/restore.rb
158
159
  - lib/imap/backup/cli/setup.rb