imap-backup 16.2.0 → 16.3.0
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/docs/performance.md +1 -1
- data/lib/imap/backup/account/folder.rb +3 -1
- data/lib/imap/backup/account.rb +1 -1
- data/lib/imap/backup/cli/helpers.rb +69 -2
- data/lib/imap/backup/cli/local.rb +5 -0
- data/lib/imap/backup/cli/migrate.rb +1 -0
- data/lib/imap/backup/cli/mirror.rb +1 -0
- data/lib/imap/backup/cli/options.rb +13 -0
- data/lib/imap/backup/cli/remote.rb +3 -0
- data/lib/imap/backup/cli/single.rb +1 -1
- data/lib/imap/backup/cli/utils.rb +2 -0
- data/lib/imap/backup/cli.rb +4 -0
- data/lib/imap/backup/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1dbb91a882b2679944560fe5d0f16fd11b59dce626386626d151463a8354a981
|
|
4
|
+
data.tar.gz: 7b57013410b24ed4625a0405cc9b950f6cdf528e5d50d51b2919a81048f92947
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '04508eb2303ed44b9fdd8cd361958ed66eb5279a91dc310e10e404432a9e504094b4ff2d3972a645dc35ea2eff47f79f408466e3cf23cf6ac761ef1e5d3601fe'
|
|
7
|
+
data.tar.gz: a96050615e046863111e79a3350c38dc3d6e3e05f7be967fdd5003e295c1d896f07b48d0aad719c0d2571f0f7aa315833f343bb7b0432c0e3cef556f915b1cfc
|
data/docs/performance.md
CHANGED
|
@@ -43,7 +43,7 @@ By default, during backup, each message is downloaded one-by-one.
|
|
|
43
43
|
Using this setting, you can download chunks of emails at a time,
|
|
44
44
|
potentially speeding up the process.
|
|
45
45
|
|
|
46
|
-
Using multi-fetch
|
|
46
|
+
Using multi-fetch means that the backup process *will* use
|
|
47
47
|
more memory - equivalent to the size of the groups of messages
|
|
48
48
|
that are downloaded.
|
|
49
49
|
|
|
@@ -196,7 +196,9 @@ module Imap::Backup
|
|
|
196
196
|
def extract_uid(response)
|
|
197
197
|
uid_data = response.data.code.data
|
|
198
198
|
@uid_validity = uid_data.uidvalidity
|
|
199
|
-
|
|
199
|
+
# With net-imap >= 0.6, assigned_uids is a `Net::IMAP::SequenceSet`
|
|
200
|
+
uids = uid_data.assigned_uids.to_a
|
|
201
|
+
uids.to_a.first
|
|
200
202
|
end
|
|
201
203
|
|
|
202
204
|
def utf7_encoded_name
|
data/lib/imap/backup/account.rb
CHANGED
|
@@ -57,7 +57,7 @@ module Imap::Backup
|
|
|
57
57
|
# mark messages as '\Seen' when accessed).
|
|
58
58
|
# @return [Boolean]
|
|
59
59
|
attr_reader :reset_seen_flags_after_fetch
|
|
60
|
-
# The status of the account - controls backup and migration
|
|
60
|
+
# The status of the account - controls backup and migration behaviour
|
|
61
61
|
# "active" - the account is available for backup and migration,
|
|
62
62
|
# "archived" - the account is available for migration, but not backup,
|
|
63
63
|
# "offline" - the account is not available for backup or migration.
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
require "json"
|
|
3
|
+
require "tempfile"
|
|
1
4
|
require "thor"
|
|
2
5
|
|
|
3
6
|
require "imap/backup/cli/options"
|
|
@@ -19,7 +22,7 @@ module Imap::Backup
|
|
|
19
22
|
# @return [String] a description of the namespace configuration
|
|
20
23
|
NAMESPACE_CONFIGURATION_DESCRIPTION = <<~DESC.freeze
|
|
21
24
|
Some IMAP servers use namespaces (i.e. prefixes like "INBOX"),
|
|
22
|
-
while others
|
|
25
|
+
while others concatenate the names of subfolders
|
|
23
26
|
with a charater ("delimiter") other than "/".
|
|
24
27
|
|
|
25
28
|
In these cases there are two choices.
|
|
@@ -60,9 +63,24 @@ module Imap::Backup
|
|
|
60
63
|
|
|
61
64
|
# Loads the application configuration
|
|
62
65
|
# @raise [ConfigurationNotFound] if the configuration file does not exist
|
|
66
|
+
# @raise [RuntimeError] if both config and erb_configuration are provided
|
|
67
|
+
# @raise [RuntimeError] if ERB template has syntax errors
|
|
68
|
+
# @raise [RuntimeError] if ERB template renders invalid JSON
|
|
63
69
|
# @return [Configuration]
|
|
64
70
|
def load_config(**options)
|
|
65
|
-
|
|
71
|
+
config_path = options[:config]
|
|
72
|
+
erb_config_path = options[:erb_configuration]
|
|
73
|
+
|
|
74
|
+
# Check mutual exclusivity
|
|
75
|
+
if config_path && erb_config_path
|
|
76
|
+
raise "Cannot specify both --config and --erb-configuration options"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Handle ERB configuration
|
|
80
|
+
return load_erb_config(erb_config_path, options) if erb_config_path
|
|
81
|
+
|
|
82
|
+
# Handle regular JSON configuration
|
|
83
|
+
path = config_path
|
|
66
84
|
require_exists = options.key?(:require_exists) ? options[:require_exists] : true
|
|
67
85
|
if require_exists
|
|
68
86
|
exists = Configuration.exist?(path: path)
|
|
@@ -94,5 +112,54 @@ module Imap::Backup
|
|
|
94
112
|
config.accounts
|
|
95
113
|
end
|
|
96
114
|
end
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
# Processes an ERB template and loads it as configuration
|
|
119
|
+
# @raise [ConfigurationNotFound] if the ERB file does not exist
|
|
120
|
+
# @raise [RuntimeError] if ERB processing fails
|
|
121
|
+
# @raise [RuntimeError] if rendered output is invalid JSON
|
|
122
|
+
# @return [Configuration]
|
|
123
|
+
def load_erb_config(erb_path, _options)
|
|
124
|
+
# Check if file exists
|
|
125
|
+
unless File.exist?(erb_path)
|
|
126
|
+
raise ConfigurationNotFound, "ERB configuration file '#{erb_path}' not found"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
begin
|
|
130
|
+
# Read and process ERB template
|
|
131
|
+
erb_content = File.read(erb_path)
|
|
132
|
+
erb = ERB.new(erb_content)
|
|
133
|
+
rendered_json = erb.result
|
|
134
|
+
rescue SyntaxError => e
|
|
135
|
+
raise "ERB template has syntax error: #{e.message}"
|
|
136
|
+
rescue StandardError => e
|
|
137
|
+
raise "Error processing ERB template: #{e.message}"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Validate rendered JSON
|
|
141
|
+
begin
|
|
142
|
+
JSON.parse(rendered_json)
|
|
143
|
+
rescue JSON::ParserError => e
|
|
144
|
+
raise "ERB template rendered invalid JSON: #{e.message}"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Create temporary file with rendered JSON
|
|
148
|
+
temp_file = Tempfile.new(["config", ".json"])
|
|
149
|
+
begin
|
|
150
|
+
temp_file.write(rendered_json)
|
|
151
|
+
temp_file.flush
|
|
152
|
+
temp_file.close
|
|
153
|
+
|
|
154
|
+
# Load configuration from temporary file
|
|
155
|
+
config = Configuration.new(path: temp_file.path)
|
|
156
|
+
# Force loading of data before temp file is deleted
|
|
157
|
+
config.accounts
|
|
158
|
+
config
|
|
159
|
+
ensure
|
|
160
|
+
# Clean up temporary file
|
|
161
|
+
temp_file&.unlink
|
|
162
|
+
end
|
|
163
|
+
end
|
|
97
164
|
end
|
|
98
165
|
end
|
|
@@ -17,6 +17,7 @@ module Imap::Backup
|
|
|
17
17
|
|
|
18
18
|
desc "accounts [OPTIONS]", "List locally backed-up accounts"
|
|
19
19
|
config_option
|
|
20
|
+
erb_configuration_option
|
|
20
21
|
format_option
|
|
21
22
|
quiet_option
|
|
22
23
|
verbose_option
|
|
@@ -44,6 +45,7 @@ module Imap::Backup
|
|
|
44
45
|
)
|
|
45
46
|
accounts_option
|
|
46
47
|
config_option
|
|
48
|
+
erb_configuration_option
|
|
47
49
|
format_option
|
|
48
50
|
quiet_option
|
|
49
51
|
verbose_option
|
|
@@ -56,6 +58,7 @@ module Imap::Backup
|
|
|
56
58
|
|
|
57
59
|
desc "folders EMAIL [OPTIONS]", "List backed up folders"
|
|
58
60
|
config_option
|
|
61
|
+
erb_configuration_option
|
|
59
62
|
format_option
|
|
60
63
|
quiet_option
|
|
61
64
|
verbose_option
|
|
@@ -78,6 +81,7 @@ module Imap::Backup
|
|
|
78
81
|
|
|
79
82
|
desc "list EMAIL FOLDER [OPTIONS]", "List emails in a folder"
|
|
80
83
|
config_option
|
|
84
|
+
erb_configuration_option
|
|
81
85
|
format_option
|
|
82
86
|
quiet_option
|
|
83
87
|
verbose_option
|
|
@@ -108,6 +112,7 @@ module Imap::Backup
|
|
|
108
112
|
the UID.
|
|
109
113
|
DESC
|
|
110
114
|
config_option
|
|
115
|
+
erb_configuration_option
|
|
111
116
|
format_option
|
|
112
117
|
quiet_option
|
|
113
118
|
verbose_option
|
|
@@ -25,6 +25,19 @@ module Imap::Backup
|
|
|
25
25
|
desc: "supply the configuration file path (default: ~/.imap-backup/config.json)"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
+
{
|
|
29
|
+
name: "erb_configuration",
|
|
30
|
+
parameters: {
|
|
31
|
+
type: :string,
|
|
32
|
+
desc:
|
|
33
|
+
"supply an ERB template file path for configuration. " \
|
|
34
|
+
"This is an alternative to the --config option. " \
|
|
35
|
+
"The file will be processed with ERB before being parsed as JSON. " \
|
|
36
|
+
"This allows use of environment variables and other dynamic content. " \
|
|
37
|
+
"Note that using this option is a potential security risk as it allows " \
|
|
38
|
+
"execution of arbitrary code."
|
|
39
|
+
}
|
|
40
|
+
},
|
|
28
41
|
{
|
|
29
42
|
name: "format",
|
|
30
43
|
parameters: {
|
|
@@ -15,6 +15,7 @@ module Imap::Backup
|
|
|
15
15
|
|
|
16
16
|
desc "folders EMAIL [OPTIONS]", "List account folders"
|
|
17
17
|
config_option
|
|
18
|
+
erb_configuration_option
|
|
18
19
|
format_option
|
|
19
20
|
quiet_option
|
|
20
21
|
verbose_option
|
|
@@ -36,6 +37,7 @@ module Imap::Backup
|
|
|
36
37
|
Lists the IMAP capabilities supported by the IMAP server.
|
|
37
38
|
DESC
|
|
38
39
|
config_option
|
|
40
|
+
erb_configuration_option
|
|
39
41
|
format_option
|
|
40
42
|
quiet_option
|
|
41
43
|
verbose_option
|
|
@@ -57,6 +59,7 @@ module Imap::Backup
|
|
|
57
59
|
the `imap-backup migrate` and `imap-backup mirror` commands.
|
|
58
60
|
DESC
|
|
59
61
|
config_option
|
|
62
|
+
erb_configuration_option
|
|
60
63
|
format_option
|
|
61
64
|
quiet_option
|
|
62
65
|
verbose_option
|
|
@@ -105,7 +105,7 @@ module Imap::Backup
|
|
|
105
105
|
type: "string",
|
|
106
106
|
desc: "the path of the directory where backups are to be saved. " \
|
|
107
107
|
"If the directory does not exist, it will be created. " \
|
|
108
|
-
"If not set, this is set to a
|
|
108
|
+
"If not set, this is set to a directory under the current path " \
|
|
109
109
|
"which is derived from the username, by replacing '@' with '_'." \
|
|
110
110
|
"If this path parameter is not indicated, " \
|
|
111
111
|
"the default is the current directory plus the email " \
|
|
@@ -23,6 +23,7 @@ module Imap::Backup
|
|
|
23
23
|
"Skip downloading emails up to today for all configured folders"
|
|
24
24
|
)
|
|
25
25
|
config_option
|
|
26
|
+
erb_configuration_option
|
|
26
27
|
quiet_option
|
|
27
28
|
verbose_option
|
|
28
29
|
# Creates fake downloaded emails so that only the account's future emails
|
|
@@ -52,6 +53,7 @@ module Imap::Backup
|
|
|
52
53
|
DOC
|
|
53
54
|
)
|
|
54
55
|
config_option
|
|
56
|
+
erb_configuration_option
|
|
55
57
|
quiet_option
|
|
56
58
|
verbose_option
|
|
57
59
|
method_option(
|
data/lib/imap/backup/cli.rb
CHANGED
|
@@ -64,6 +64,7 @@ module Imap::Backup
|
|
|
64
64
|
DESC
|
|
65
65
|
accounts_option
|
|
66
66
|
config_option
|
|
67
|
+
erb_configuration_option
|
|
67
68
|
quiet_option
|
|
68
69
|
refresh_option
|
|
69
70
|
verbose_option
|
|
@@ -101,6 +102,7 @@ module Imap::Backup
|
|
|
101
102
|
#{Helpers::NAMESPACE_CONFIGURATION_DESCRIPTION}
|
|
102
103
|
DESC
|
|
103
104
|
config_option
|
|
105
|
+
erb_configuration_option
|
|
104
106
|
quiet_option
|
|
105
107
|
verbose_option
|
|
106
108
|
method_option(
|
|
@@ -153,6 +155,7 @@ module Imap::Backup
|
|
|
153
155
|
DESC
|
|
154
156
|
accounts_option
|
|
155
157
|
config_option
|
|
158
|
+
erb_configuration_option
|
|
156
159
|
quiet_option
|
|
157
160
|
verbose_option
|
|
158
161
|
method_option(
|
|
@@ -203,6 +206,7 @@ module Imap::Backup
|
|
|
203
206
|
on the server).
|
|
204
207
|
DESC
|
|
205
208
|
config_option
|
|
209
|
+
erb_configuration_option
|
|
206
210
|
format_option
|
|
207
211
|
quiet_option
|
|
208
212
|
verbose_option
|
data/lib/imap/backup/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imap-backup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 16.
|
|
4
|
+
version: 16.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joe Yates
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: highline
|
|
@@ -248,7 +247,6 @@ licenses:
|
|
|
248
247
|
- MIT
|
|
249
248
|
metadata:
|
|
250
249
|
rubygems_mfa_required: 'true'
|
|
251
|
-
post_install_message:
|
|
252
250
|
rdoc_options: []
|
|
253
251
|
require_paths:
|
|
254
252
|
- lib
|
|
@@ -263,8 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
263
261
|
- !ruby/object:Gem::Version
|
|
264
262
|
version: '0'
|
|
265
263
|
requirements: []
|
|
266
|
-
rubygems_version: 3.
|
|
267
|
-
signing_key:
|
|
264
|
+
rubygems_version: 3.6.7
|
|
268
265
|
specification_version: 4
|
|
269
266
|
summary: Backup GMail (or other IMAP) accounts to disk
|
|
270
267
|
test_files: []
|