imap-backup 14.5.1 → 14.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imap/backup/{cli/folder_enumerator.rb → account/folder_mapper.rb} +6 -6
- data/lib/imap/backup/account/restore.rb +20 -4
- data/lib/imap/backup/account.rb +0 -9
- data/lib/imap/backup/cli/local.rb +5 -5
- data/lib/imap/backup/cli/remote.rb +3 -3
- data/lib/imap/backup/cli/restore.rb +14 -4
- data/lib/imap/backup/cli/single.rb +6 -3
- data/lib/imap/backup/cli/transfer.rb +18 -22
- data/lib/imap/backup/cli/utils.rb +4 -1
- data/lib/imap/backup/cli.rb +15 -4
- data/lib/imap/backup/serializer/delayed_metadata_serializer.rb +2 -0
- data/lib/imap/backup/serializer/imap.rb +2 -0
- data/lib/imap/backup/serializer/mbox.rb +2 -0
- data/lib/imap/backup/serializer/message.rb +2 -0
- data/lib/imap/backup/serializer/message_enumerator.rb +2 -0
- data/lib/imap/backup/serializer/permission_checker.rb +2 -0
- data/lib/imap/backup/serializer/transaction.rb +2 -0
- data/lib/imap/backup/serializer/unused_name_finder.rb +2 -0
- data/lib/imap/backup/serializer/version2_migrator.rb +2 -0
- data/lib/imap/backup/serializer.rb +4 -2
- data/lib/imap/backup/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80b99aa3b4c713e6a88c9dbe504186fd64065a1d03d50d2d47a79de6ab14902f
|
4
|
+
data.tar.gz: c7a7d6f52b36819de9f660c488a8b4dfcf75794affa56547e197aab79c56cf7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
10
|
+
class Account; end
|
11
11
|
|
12
12
|
# Implements a folder enumerator for backed-up accounts
|
13
|
-
class
|
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 :
|
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
|
-
|
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/
|
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
|
-
|
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
|
data/lib/imap/backup/account.rb
CHANGED
@@ -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
|
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.
|
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
|
40
|
+
"Calling restore with the --account option is deprecated, " \
|
40
41
|
"please pass a single EMAIL parameter"
|
41
42
|
)
|
42
|
-
requested_accounts(config).each(
|
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.
|
@@ -104,9 +104,12 @@ module Imap::Backup
|
|
104
104
|
"path",
|
105
105
|
type: "string",
|
106
106
|
desc: "the path of the directory where backups are to be saved. " \
|
107
|
-
"If the directory does not
|
107
|
+
"If the directory does not exist, it will be created. " \
|
108
108
|
"If not set, this is set to a diretory under the current path " \
|
109
|
-
"which is derived from the username, by replacing '@' with '_'."
|
109
|
+
"which is derived from the username, by replacing '@' with '_'." \
|
110
|
+
"If this path parameter is not indicated, " \
|
111
|
+
"the default is the current directory plus the email " \
|
112
|
+
"with '@' replaced by '_'.",
|
110
113
|
aliases: ["-P"]
|
111
114
|
)
|
112
115
|
method_option(
|
@@ -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
|
13
|
-
include Thor::Actions
|
12
|
+
class CLI::Transfer
|
14
13
|
include CLI::Helpers
|
15
14
|
|
16
|
-
# The possible
|
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/
|
36
|
+
# or incompatible namespace/delimiter parameters have been supplied
|
39
37
|
# @return [void]
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
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
|
data/lib/imap/backup/cli.rb
CHANGED
@@ -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
|
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
|
-
|
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.
|
@@ -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
|
@@ -102,8 +102,10 @@ module Imap::Backup
|
|
102
102
|
@validated = true
|
103
103
|
return true
|
104
104
|
end
|
105
|
-
|
106
|
-
Logger.logger.info("
|
105
|
+
warn_imap = !imap_valid && imap.exist?
|
106
|
+
Logger.logger.info("Metadata file '#{imap.pathname}' is invalid") if warn_imap
|
107
|
+
warn_mbox = !mbox_valid && mbox.exist?
|
108
|
+
Logger.logger.info("Mailbox '#{mbox.pathname}' is invalid") if warn_mbox
|
107
109
|
|
108
110
|
delete
|
109
111
|
|
data/lib/imap/backup/version.rb
CHANGED
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
|
+
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-
|
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
|
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
233
|
- !ruby/object:Gem::Version
|
234
234
|
version: '0'
|
235
235
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
236
|
+
rubygems_version: 3.5.3
|
237
237
|
signing_key:
|
238
238
|
specification_version: 4
|
239
239
|
summary: Backup GMail (or other IMAP) accounts to disk
|