imap-backup 13.4.0 → 14.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -59
- data/docs/development.md +10 -1
- data/docs/performance.md +53 -0
- data/lib/imap/backup/cli/helpers.rb +10 -0
- data/lib/imap/backup/cli/local.rb +1 -0
- data/lib/imap/backup/cli/restore.rb +1 -0
- data/lib/imap/backup/cli/single/backup.rb +131 -0
- data/lib/imap/backup/cli/single.rb +179 -0
- data/lib/imap/backup/cli.rb +5 -6
- data/lib/imap/backup/downloader.rb +10 -4
- data/lib/imap/backup/logger.rb +1 -0
- data/lib/imap/backup/migrator.rb +2 -0
- data/lib/imap/backup/setup/account.rb +1 -0
- data/lib/imap/backup/setup/email.rb +1 -0
- data/lib/imap/backup/version.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cf96ff7b006e9e09f0ec63c75f594879a43be7065a90a35909f128077ff1a06
|
4
|
+
data.tar.gz: deb1c54af3238a9f8fea9f8cdb084acfde187590dc621f5280a2798dd48426cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f170fcdfbad3ebe441d3860eec5123cd2e165749e9fb64824e9e5db1948ba2ff01fb4d8d52da6ce3ad1d607d2235b0bc58f670b95b78a57595b34b039471a689
|
7
|
+
data.tar.gz: ad9180ddaf1ed6698627fc42bfb415cbf12abf5e6a9459483ec2c69c5bc6ef14c8465c95c5fd98934bb1d5bdbaf8c0a9c52bec27e0d6a7c34ff2fae7158b4aa7
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
[![Build Status](https://github.com/joeyates/imap-backup/actions/workflows/main.yml/badge.svg)][CI Status]
|
3
3
|
![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/joeyates/b54fe758bfb405c04bef72dad293d707/raw/coverage.json)
|
4
4
|
![License](https://img.shields.io/github/license/joeyates/imap-backup?color=brightgreen&label=License)
|
5
|
+
[![Stars](https://img.shields.io/github/stars/joeyates/imap-backup?style=social)][GitHub Stars]
|
5
6
|
|
6
7
|
# imap-backup
|
7
8
|
|
@@ -11,7 +12,7 @@ Backup, restore and migrate email accounts.
|
|
11
12
|
|
12
13
|
```sh
|
13
14
|
brew install imap-backup # for macOS
|
14
|
-
gem install imap-backup # for Linux
|
15
|
+
gem install imap-backup --no-document # for Linux
|
15
16
|
imap-backup setup
|
16
17
|
imap-backup
|
17
18
|
```
|
@@ -35,6 +36,8 @@ See below for a [full list of commands](#Commands).
|
|
35
36
|
|
36
37
|
## Homebrew (macOS)
|
37
38
|
|
39
|
+
![Homebrew installs](https://img.shields.io/homebrew/installs/dm/imap-backup?label=Homebrew%20installs)
|
40
|
+
|
38
41
|
If you have [Homebrew](https://brew.sh/), do this:
|
39
42
|
|
40
43
|
```sh
|
@@ -44,7 +47,7 @@ brew install imap-backup
|
|
44
47
|
## As a Ruby Gem
|
45
48
|
|
46
49
|
```sh
|
47
|
-
gem install imap-backup
|
50
|
+
gem install imap-backup --no-document
|
48
51
|
```
|
49
52
|
|
50
53
|
If that doesn't work, see the [detailed installation instructions](docs/installation/rubygem.md).
|
@@ -55,8 +58,10 @@ If you want to use imap-backup directly from the source code, see [here](docs/in
|
|
55
58
|
|
56
59
|
# Setup
|
57
60
|
|
58
|
-
|
59
|
-
|
61
|
+
Normally you will want to backup a number of email accounts.
|
62
|
+
Doing so requires the creation of a config file.
|
63
|
+
|
64
|
+
You do this via a menu-driven command line program:
|
60
65
|
|
61
66
|
Run:
|
62
67
|
|
@@ -64,6 +69,10 @@ Run:
|
|
64
69
|
imap-backup setup
|
65
70
|
```
|
66
71
|
|
72
|
+
As an alternative, if you only want to backup a single account,
|
73
|
+
you can pass all the necessary parameters directly to the `single backup` command
|
74
|
+
(see the [`single backup`](docs/commands/single-backup.md) docs).
|
75
|
+
|
67
76
|
## GMail
|
68
77
|
|
69
78
|
To use imap-backup with GMail, Office 365 and other services that require
|
@@ -80,24 +89,25 @@ imap-backup
|
|
80
89
|
|
81
90
|
Alternatively, add it to your crontab.
|
82
91
|
|
83
|
-
Backups can also be inspected, for example via [local show](docs/commands/local-show.md)
|
84
|
-
and exported via [utils export-to-thunderbird](docs/commands/utils-export-to-thunderbird.md).
|
92
|
+
Backups can also be inspected, for example via [`local show`](docs/commands/local-show.md)
|
93
|
+
and exported via [`utils export-to-thunderbird`](docs/commands/utils-export-to-thunderbird.md).
|
85
94
|
|
86
95
|
# Commands
|
87
96
|
|
88
|
-
* [backup](docs/commands/backup.md)
|
89
|
-
* [local accounts](docs/commands/local-accounts.md)
|
90
|
-
* [local check](docs/commands/local-check.md)
|
91
|
-
* [local folders](docs/commands/local-folders.md)
|
92
|
-
* [local list](docs/commands/local-list.md)
|
93
|
-
* [local show](docs/commands/local-show.md)
|
94
|
-
* [migrate](docs/commands/migrate.md)
|
95
|
-
* [mirror](docs/commands/mirror.md)
|
96
|
-
* [remote folders](docs/commands/remote-folders.md)
|
97
|
-
* [restore](docs/commands/restore.md)
|
98
|
-
* [setup](docs/commands/setup.md)
|
99
|
-
* [
|
100
|
-
* [utils
|
97
|
+
* [`backup`](docs/commands/backup.md)
|
98
|
+
* [`local accounts`](docs/commands/local-accounts.md)
|
99
|
+
* [`local check`](docs/commands/local-check.md)
|
100
|
+
* [`local folders`](docs/commands/local-folders.md)
|
101
|
+
* [`local list`](docs/commands/local-list.md)
|
102
|
+
* [`local show`](docs/commands/local-show.md)
|
103
|
+
* [`migrate`](docs/commands/migrate.md)
|
104
|
+
* [`mirror`](docs/commands/mirror.md)
|
105
|
+
* [`remote folders`](docs/commands/remote-folders.md)
|
106
|
+
* [`restore`](docs/commands/restore.md)
|
107
|
+
* [`setup`](docs/commands/setup.md)
|
108
|
+
* [`single backup`](docs/commands/single-backup.md)
|
109
|
+
* [`utils export-to-thunderbird`](docs/commands/utils-export-to-thunderbird.md)
|
110
|
+
* [`utils ignore-history`](docs/commands/utils-ignore-history.md)
|
101
111
|
|
102
112
|
For a full list of available commands, run
|
103
113
|
|
@@ -118,46 +128,10 @@ to improve backup speed.
|
|
118
128
|
|
119
129
|
These are activated via two settings:
|
120
130
|
|
121
|
-
* Global setting "Delay download writes"
|
122
|
-
* Account setting "Multi-fetch size"
|
123
|
-
|
124
|
-
As with all performance tweaks, there are trade-offs.
|
125
|
-
If you are using a small virtual server or Raspberry Pi
|
126
|
-
to run your backups, you will probably want to leave
|
127
|
-
the default settings.
|
128
|
-
If, on the other hand, you are using a computer with a
|
129
|
-
fair bit of RAM, and you are dealing with a *lot* of email,
|
130
|
-
then changing these settings may be worthwhile.
|
131
|
-
|
132
|
-
## Delay download writes
|
133
|
-
|
134
|
-
This setting affects all account backups.
|
135
|
-
|
136
|
-
By default, `imap-backup` uses the "delay metadata" strategy.
|
137
|
-
As messages are being backed-up, the message *text*
|
138
|
-
is written to disk, while the related metadata is stored in memory.
|
131
|
+
* Global setting "Delay download writes",
|
132
|
+
* Account setting "Multi-fetch size".
|
139
133
|
|
140
|
-
|
141
|
-
file for every message, speeding things up and reducing disk wear.
|
142
|
-
|
143
|
-
The alternative strategy, called "direct", writes everything to disk
|
144
|
-
as it is received. This method is slower, but has the advantage
|
145
|
-
of using slightly less memory, which may be important on very
|
146
|
-
resource-limited systems, like Raspberry Pis.
|
147
|
-
|
148
|
-
## Multi-fetch Size
|
149
|
-
|
150
|
-
By default, during backup, each message is downloaded one-by-one.
|
151
|
-
|
152
|
-
Using this setting, you can download chunks of emails at a time,
|
153
|
-
potentially speeding up the process.
|
154
|
-
|
155
|
-
Using multi-fetch *will* mean that the backup process will use
|
156
|
-
more memory - equivalent to the size of the groups of messages
|
157
|
-
that are downloaded.
|
158
|
-
|
159
|
-
This behaviour may also exceed the rate limits on your email provider,
|
160
|
-
so it's best to check before cranking it up!
|
134
|
+
See [the performance document](docs/performance.md) for more information.
|
161
135
|
|
162
136
|
# Troubleshooting
|
163
137
|
|
@@ -168,10 +142,12 @@ If you have problems:
|
|
168
142
|
|
169
143
|
# Development
|
170
144
|
|
145
|
+
![Activity](https://img.shields.io/github/last-commit/joeyates/imap-backup/main)
|
146
|
+
|
171
147
|
See the [Development documentation](./docs/development.md) for notes
|
172
148
|
on development and testing.
|
173
149
|
|
174
|
-
See [the CHANGELOG](./CHANGELOG.md)
|
150
|
+
See [the CHANGELOG](./CHANGELOG.md) for a list of changes that have been
|
175
151
|
made in each release.
|
176
152
|
|
177
153
|
* [Source Code]
|
@@ -180,6 +156,7 @@ made in each release.
|
|
180
156
|
* [CI Status]
|
181
157
|
|
182
158
|
[Source Code]: https://github.com/joeyates/imap-backup "Source code at GitHub"
|
159
|
+
[GitHub Stars]: https://github.com/joeyates/imap-backup/stargazers "GitHub Stars"
|
183
160
|
[Code Documentation]: https://rubydoc.info/gems/imap-backup/frames "Code Documentation at Rubydoc.info"
|
184
161
|
[Rubygem]: https://rubygems.org/gems/imap-backup "Ruby gem at rubygems.org"
|
185
162
|
[CI Status]: https://github.com/joeyates/imap-backup/actions/workflows/main.yml
|
data/docs/development.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
# Repository
|
2
|
+
|
3
|
+
After cloning the repo, run the following command to get
|
4
|
+
better `git blame` output:
|
5
|
+
|
6
|
+
```sh
|
7
|
+
git config --local blame.ignoreRevsFile .git-blame-ignore-revs
|
8
|
+
```
|
9
|
+
|
1
10
|
# Design Goals
|
2
11
|
|
3
|
-
* Secure - use a local file protected by permissions
|
12
|
+
* Secure - use a local configuration file protected by permissions
|
4
13
|
* Restartable - calculate start point based on already downloaded messages
|
5
14
|
* Standalone - do not rely on an email client or MTA
|
6
15
|
|
data/docs/performance.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Performace
|
2
|
+
|
3
|
+
The two performance-related settings are "Download strategy",
|
4
|
+
which is a global setting,
|
5
|
+
and "Multi-fetch size", which is an Account-level setting.
|
6
|
+
|
7
|
+
As with all performance tweaks, there are trade-offs.
|
8
|
+
|
9
|
+
# Overview
|
10
|
+
|
11
|
+
The defaults, which suit most machines and plays nice with servers is:
|
12
|
+
|
13
|
+
* Download strategy: "delay writing metadata",
|
14
|
+
* Multi-fetch size: 1.
|
15
|
+
|
16
|
+
If you are using a resource-limited machine like
|
17
|
+
a small virtual server or Raspberry Pi
|
18
|
+
to run your backups, you can change "Download strategy".
|
19
|
+
|
20
|
+
If your email provider supports it,
|
21
|
+
and you don't have tight memeory limits,
|
22
|
+
increase "Multi-fetch size" for faster backups.
|
23
|
+
|
24
|
+
# Delay download writes
|
25
|
+
|
26
|
+
This is a global setting, affecting all account backups.
|
27
|
+
|
28
|
+
By default, `imap-backup` uses the "delay writing metadata" strategy.
|
29
|
+
As messages are being backed-up, the message *text*
|
30
|
+
is written to disk, while the related metadata is stored in memory.
|
31
|
+
|
32
|
+
While this uses a *little* more memory, it avoids rewiting a growing JSON
|
33
|
+
file for every message, speeding things up and reducing disk wear.
|
34
|
+
|
35
|
+
The alternative strategy, called "write straight to disk",
|
36
|
+
writes everything to disk as it is received.
|
37
|
+
This method is slower, but has the advantage
|
38
|
+
of using slightly less memory, which may be important on very
|
39
|
+
resource-limited systems, like Raspberry Pis.
|
40
|
+
|
41
|
+
# Multi-fetch Size
|
42
|
+
|
43
|
+
By default, during backup, each message is downloaded one-by-one.
|
44
|
+
|
45
|
+
Using this setting, you can download chunks of emails at a time,
|
46
|
+
potentially speeding up the process.
|
47
|
+
|
48
|
+
Using multi-fetch *will* mean that the backup process will use
|
49
|
+
more memory - equivalent to the size of the groups of messages
|
50
|
+
that are downloaded.
|
51
|
+
|
52
|
+
This behaviour may also exceed the rate limits on your email provider,
|
53
|
+
so it's best to check before cranking it up!
|
@@ -47,6 +47,16 @@ module Imap::Backup
|
|
47
47
|
)
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.refresh_option
|
51
|
+
method_option(
|
52
|
+
"refresh",
|
53
|
+
type: :boolean,
|
54
|
+
desc: "in the default 'keep all emails' mode, " \
|
55
|
+
"updates flags for messages that are already downloaded",
|
56
|
+
aliases: ["-r"]
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
50
60
|
def self.verbose_option
|
51
61
|
method_option(
|
52
62
|
"verbose",
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
require "imap/backup/account"
|
4
|
+
require "imap/backup/account/backup"
|
5
|
+
require "imap/backup/configuration"
|
6
|
+
|
7
|
+
module Imap; end
|
8
|
+
|
9
|
+
module Imap::Backup
|
10
|
+
class CLI < Thor; end
|
11
|
+
class CLI::Single < Thor; end
|
12
|
+
|
13
|
+
class CLI::Single::Backup
|
14
|
+
attr_reader :options
|
15
|
+
attr_reader :password
|
16
|
+
|
17
|
+
def initialize(options)
|
18
|
+
@options = options
|
19
|
+
@password = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
process_options!
|
24
|
+
account = Account.new(
|
25
|
+
username: email,
|
26
|
+
password: password,
|
27
|
+
server: server,
|
28
|
+
download_strategy: download_strategy,
|
29
|
+
folder_blacklist: folder_blacklist,
|
30
|
+
local_path: local_path,
|
31
|
+
mirror: mirror,
|
32
|
+
reset_seen_flags_after_fetch: reset_seen_flags_after_fetch
|
33
|
+
)
|
34
|
+
account.connection_options = connection_options if connection_options
|
35
|
+
account.folders = folders if folders.any?
|
36
|
+
account.multi_fetch_size = multi_fetch_size if multi_fetch_size
|
37
|
+
backup = Account::Backup.new(account: account, refresh: refresh)
|
38
|
+
backup.run
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def process_options!
|
44
|
+
if !email
|
45
|
+
raise Thor::RequiredArgumentMissingError,
|
46
|
+
"No value provided for required options '--email'"
|
47
|
+
end
|
48
|
+
if !server
|
49
|
+
raise Thor::RequiredArgumentMissingError,
|
50
|
+
"No value provided for required options '--server'"
|
51
|
+
end
|
52
|
+
handle_password_options!
|
53
|
+
end
|
54
|
+
|
55
|
+
def handle_password_options!
|
56
|
+
plain = options[:password]
|
57
|
+
env = options[:password_environment_variable]
|
58
|
+
file = options[:password_file]
|
59
|
+
case [plain, env, file]
|
60
|
+
when [nil, nil, nil]
|
61
|
+
raise Thor::RequiredArgumentMissingError,
|
62
|
+
"Supply one of the --password... parameters"
|
63
|
+
when [plain, nil, nil]
|
64
|
+
@password = plain
|
65
|
+
when [nil, env, nil]
|
66
|
+
@password = ENV.fetch(env)
|
67
|
+
when [nil, nil, file]
|
68
|
+
@password = File.read(file).gsub(/\n$/, "")
|
69
|
+
else
|
70
|
+
raise ArgumentError, "Supply only one of the --password... parameters"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def connection_options
|
75
|
+
options[:connection_options]
|
76
|
+
end
|
77
|
+
|
78
|
+
def download_strategy
|
79
|
+
@download_strategy =
|
80
|
+
case options[:download_strategy]
|
81
|
+
when nil
|
82
|
+
Configuration::DEFAULT_STRATEGY
|
83
|
+
when "delay"
|
84
|
+
"delay_metadata"
|
85
|
+
when "direct"
|
86
|
+
"direct"
|
87
|
+
else
|
88
|
+
raise ArgumentError, "Unknown download_strategy: '#{options[:download_strategy]}'"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def email
|
93
|
+
options[:email]
|
94
|
+
end
|
95
|
+
|
96
|
+
def folder_blacklist
|
97
|
+
options[:folder_blacklist] ? true : false
|
98
|
+
end
|
99
|
+
|
100
|
+
def folders
|
101
|
+
@folders ||= options[:folder] || []
|
102
|
+
end
|
103
|
+
|
104
|
+
def local_path
|
105
|
+
return options[:path] if options.key?(:path)
|
106
|
+
|
107
|
+
for_account = email.tr("@", "_")
|
108
|
+
File.join(Dir.pwd, for_account)
|
109
|
+
end
|
110
|
+
|
111
|
+
def mirror
|
112
|
+
options[:mirror] ? true : false
|
113
|
+
end
|
114
|
+
|
115
|
+
def multi_fetch_size
|
116
|
+
options[:multi_fetch_size]
|
117
|
+
end
|
118
|
+
|
119
|
+
def refresh
|
120
|
+
options[:refresh] ? true : false
|
121
|
+
end
|
122
|
+
|
123
|
+
def reset_seen_flags_after_fetch
|
124
|
+
options[:reset_seen_flags_after_fetch] ? true : false
|
125
|
+
end
|
126
|
+
|
127
|
+
def server
|
128
|
+
options[:server]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
require "imap/backup/logger"
|
4
|
+
require "imap/backup/cli/helpers"
|
5
|
+
require "imap/backup/cli/single/backup"
|
6
|
+
|
7
|
+
module Imap; end
|
8
|
+
|
9
|
+
module Imap::Backup
|
10
|
+
class CLI < Thor; end
|
11
|
+
|
12
|
+
class CLI::Single < Thor
|
13
|
+
include CLI::Helpers
|
14
|
+
|
15
|
+
desc "backup", "Backup a single email account based on command-line parameters"
|
16
|
+
long_desc <<~DESC
|
17
|
+
This is a "stand-alone" backup command that doesn't require
|
18
|
+
a configuration file.
|
19
|
+
|
20
|
+
At a minimum, you need to supply the email, the server and the
|
21
|
+
password. (There are three ways of specifying the password)
|
22
|
+
|
23
|
+
$ imap-backup single backup
|
24
|
+
--email me@example.com
|
25
|
+
--password MyS3kr1t
|
26
|
+
--server imap.example.com
|
27
|
+
|
28
|
+
Instead of supplying the password directly on the command line,
|
29
|
+
there are two alternatives.
|
30
|
+
You can set an environment variable (with any name) to your
|
31
|
+
password, then pass the name of the environment variable.
|
32
|
+
|
33
|
+
For example, if MY_IMAP_PASSWORD is set to your password,
|
34
|
+
|
35
|
+
$ imap-backup single backup
|
36
|
+
--email me@example.com
|
37
|
+
--password-environment-variable MY_IMAP_PASSWORD
|
38
|
+
--server imap.example.com
|
39
|
+
|
40
|
+
Alternatively, you can supply the name of a file that contains
|
41
|
+
the password.
|
42
|
+
|
43
|
+
For example, in `~/imap-password`:
|
44
|
+
|
45
|
+
`MyS3kr1t`
|
46
|
+
|
47
|
+
$ imap-backup single backup
|
48
|
+
--email me@example.com
|
49
|
+
--password-file ~/imap-password
|
50
|
+
--server imap.example.com
|
51
|
+
|
52
|
+
If you need to use an insecure connection (this normally happens
|
53
|
+
when running an OAuth2 proxy), you can specify server connection options
|
54
|
+
in JSON:
|
55
|
+
|
56
|
+
$ imap-backup single backup
|
57
|
+
--email me@example.com
|
58
|
+
--password MyS3kr1t
|
59
|
+
--server imap.example.com
|
60
|
+
--connection-options '{"ssl":{"verify_mode":0}}'
|
61
|
+
DESC
|
62
|
+
method_option(
|
63
|
+
"email",
|
64
|
+
type: :string,
|
65
|
+
desc: "the email address",
|
66
|
+
aliases: ["-e"]
|
67
|
+
)
|
68
|
+
method_option(
|
69
|
+
"server",
|
70
|
+
type: :string,
|
71
|
+
desc: "the address of the IMAP server",
|
72
|
+
aliases: ["-s"]
|
73
|
+
)
|
74
|
+
method_option(
|
75
|
+
"password",
|
76
|
+
type: :string,
|
77
|
+
desc: "your password. " \
|
78
|
+
"As an alternative, use the --password-environment-variable " \
|
79
|
+
"or --password-file parameter. " \
|
80
|
+
"You need to pass exactly one of these parameters. " \
|
81
|
+
"If you pass more than one of the --password... parameters together " \
|
82
|
+
"you will get an error.",
|
83
|
+
aliases: ["-p"]
|
84
|
+
)
|
85
|
+
method_option(
|
86
|
+
"password-environment-variable",
|
87
|
+
type: :string,
|
88
|
+
desc: "an environment variable that is set to your password",
|
89
|
+
aliases: ["-e"]
|
90
|
+
)
|
91
|
+
method_option(
|
92
|
+
"password-file",
|
93
|
+
type: :string,
|
94
|
+
desc: "a file containing your password. " \
|
95
|
+
"Note that to make it easier to create such files, " \
|
96
|
+
"trailing newlines will be removed. " \
|
97
|
+
"If you happen to have a password that ends in a newline (!), " \
|
98
|
+
"you can't use this parameter.",
|
99
|
+
aliases: ["-W"]
|
100
|
+
)
|
101
|
+
method_option(
|
102
|
+
"path",
|
103
|
+
type: "string",
|
104
|
+
desc: "the path of the directory where backups are to be saved. " \
|
105
|
+
"If the directory does not exists, it will be created. " \
|
106
|
+
"If not set, this is set to a diretory under the current path " \
|
107
|
+
"which is derived from the username, by replacing '@' with '_'.",
|
108
|
+
aliases: ["-P"]
|
109
|
+
)
|
110
|
+
method_option(
|
111
|
+
"folder",
|
112
|
+
type: :string,
|
113
|
+
desc: "a folder (this option can be given any number of times). " \
|
114
|
+
"By default, all of an account's folders are backed up. " \
|
115
|
+
"If you supply any --folder parameters, " \
|
116
|
+
"only **those** folders are backed up. " \
|
117
|
+
"See also --folder-blacklist.",
|
118
|
+
repeatable: true,
|
119
|
+
aliases: ["-F"]
|
120
|
+
)
|
121
|
+
method_option(
|
122
|
+
"folder-blacklist",
|
123
|
+
type: :boolean,
|
124
|
+
desc: "if this option is given, the list of --folders specified " \
|
125
|
+
"will treated as a blacklist - " \
|
126
|
+
"those folders will be skipped and " \
|
127
|
+
"all others will be backed up.",
|
128
|
+
default: false,
|
129
|
+
aliases: ["-b"]
|
130
|
+
)
|
131
|
+
method_option(
|
132
|
+
"mirror",
|
133
|
+
type: :boolean,
|
134
|
+
desc: "if this option is given, " \
|
135
|
+
"emails that are removed from the server " \
|
136
|
+
"will be removed from the local backup.",
|
137
|
+
aliases: ["-m"]
|
138
|
+
)
|
139
|
+
method_option(
|
140
|
+
"multi-fetch-size",
|
141
|
+
type: :numeric,
|
142
|
+
desc: "the number of emails to download at a time",
|
143
|
+
default: 1,
|
144
|
+
aliases: ["-n"]
|
145
|
+
)
|
146
|
+
method_option(
|
147
|
+
"connection-options",
|
148
|
+
type: :string,
|
149
|
+
desc: "an optional JSON string with options for the IMAP connection",
|
150
|
+
aliases: ["-o"]
|
151
|
+
)
|
152
|
+
method_option(
|
153
|
+
"download-strategy",
|
154
|
+
type: :string,
|
155
|
+
desc: "the download strategy to adopt. " \
|
156
|
+
"For details, see the documentation for this setting " \
|
157
|
+
"in the setup program.",
|
158
|
+
enum: %w(delay direct),
|
159
|
+
default: "delay",
|
160
|
+
aliases: ["-S"]
|
161
|
+
)
|
162
|
+
refresh_option
|
163
|
+
method_option(
|
164
|
+
"reset-seen-flags-after-fetch",
|
165
|
+
type: :boolean,
|
166
|
+
desc: "reset 'Seen' flags after backup. " \
|
167
|
+
"For details, see the documentation for this setting " \
|
168
|
+
"in the setup program.",
|
169
|
+
aliases: ["-R"]
|
170
|
+
)
|
171
|
+
quiet_option
|
172
|
+
verbose_option
|
173
|
+
def backup
|
174
|
+
non_logging_options = Imap::Backup::Logger.setup_logging(options)
|
175
|
+
direct = Backup.new(non_logging_options)
|
176
|
+
direct.run
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
data/lib/imap/backup/cli.rb
CHANGED
@@ -14,6 +14,7 @@ module Imap::Backup
|
|
14
14
|
autoload :Remote, "imap/backup/cli/remote"
|
15
15
|
autoload :Restore, "imap/backup/cli/restore"
|
16
16
|
autoload :Setup, "imap/backup/cli/setup"
|
17
|
+
autoload :Single, "imap/backup/cli/single"
|
17
18
|
autoload :Stats, "imap/backup/cli/stats"
|
18
19
|
autoload :Transfer, "imap/backup/cli/transfer"
|
19
20
|
autoload :Utils, "imap/backup/cli/utils"
|
@@ -78,13 +79,8 @@ module Imap::Backup
|
|
78
79
|
accounts_option
|
79
80
|
config_option
|
80
81
|
quiet_option
|
82
|
+
refresh_option
|
81
83
|
verbose_option
|
82
|
-
method_option(
|
83
|
-
"refresh",
|
84
|
-
type: :boolean,
|
85
|
-
desc: "in 'keep all emails' mode, update flags for messages that are already downloaded",
|
86
|
-
aliases: ["-r"]
|
87
|
-
)
|
88
84
|
def backup
|
89
85
|
non_logging_options = Imap::Backup::Logger.setup_logging(options)
|
90
86
|
Backup.new(non_logging_options).run
|
@@ -239,6 +235,9 @@ module Imap::Backup
|
|
239
235
|
CLI::Setup.new(non_logging_options).run
|
240
236
|
end
|
241
237
|
|
238
|
+
desc "single SUBCOMMAND [OPTIONS]", "Run actions on a single account"
|
239
|
+
subcommand "single", Single
|
240
|
+
|
242
241
|
desc "stats EMAIL [OPTIONS]", "Print stats for each account folder"
|
243
242
|
long_desc <<~DESC
|
244
243
|
For each account folder, lists three counts of emails:
|
@@ -96,18 +96,24 @@ module Imap::Backup
|
|
96
96
|
debug("uid: #{uid} (#{index}/#{uids.count}) - #{body.size} bytes")
|
97
97
|
serializer.append uid, body, flags
|
98
98
|
end
|
99
|
+
rescue StandardError => e
|
100
|
+
error(e)
|
99
101
|
end
|
100
102
|
|
101
103
|
def uids
|
102
104
|
@uids ||= folder.uids - serializer.uids
|
103
105
|
end
|
104
106
|
|
105
|
-
def info(message)
|
106
|
-
Logger.logger.info("[#{folder.name}] #{message}")
|
107
|
-
end
|
108
|
-
|
109
107
|
def debug(message)
|
110
108
|
Logger.logger.debug("[#{folder.name}] #{message}")
|
111
109
|
end
|
110
|
+
|
111
|
+
def error(message)
|
112
|
+
Logger.logger.error("[#{folder.name}] #{message}")
|
113
|
+
end
|
114
|
+
|
115
|
+
def info(message)
|
116
|
+
Logger.logger.info("[#{folder.name}] #{message}")
|
117
|
+
end
|
112
118
|
end
|
113
119
|
end
|
data/lib/imap/backup/logger.rb
CHANGED
data/lib/imap/backup/migrator.rb
CHANGED
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:
|
4
|
+
version: 14.1.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: 2023-10-
|
11
|
+
date: 2023-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- docs/delimiters-and-prefixes.md
|
137
137
|
- docs/development.md
|
138
138
|
- docs/migrate-server-keep-address.md
|
139
|
+
- docs/performance.md
|
139
140
|
- imap-backup.gemspec
|
140
141
|
- lib/cli_coverage.rb
|
141
142
|
- lib/email/mboxrd/message.rb
|
@@ -165,6 +166,8 @@ files:
|
|
165
166
|
- lib/imap/backup/cli/remote.rb
|
166
167
|
- lib/imap/backup/cli/restore.rb
|
167
168
|
- lib/imap/backup/cli/setup.rb
|
169
|
+
- lib/imap/backup/cli/single.rb
|
170
|
+
- lib/imap/backup/cli/single/backup.rb
|
168
171
|
- lib/imap/backup/cli/stats.rb
|
169
172
|
- lib/imap/backup/cli/transfer.rb
|
170
173
|
- lib/imap/backup/cli/utils.rb
|