imap-backup 4.0.7 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/imap-backup +5 -2
- data/lib/imap/backup/account/connection.rb +53 -33
- data/lib/imap/backup/account/folder.rb +22 -2
- data/lib/imap/backup/account.rb +4 -0
- data/lib/imap/backup/cli/accounts.rb +43 -0
- data/lib/imap/backup/cli/folders.rb +3 -1
- data/lib/imap/backup/cli/helpers.rb +8 -9
- data/lib/imap/backup/cli/local.rb +4 -2
- data/lib/imap/backup/cli/setup.rb +1 -1
- data/lib/imap/backup/cli/utils.rb +3 -2
- data/lib/imap/backup/{configuration/store.rb → configuration.rb} +16 -3
- data/lib/imap/backup/downloader.rb +26 -12
- data/lib/imap/backup/logger.rb +42 -0
- data/lib/imap/backup/sanitizer.rb +42 -0
- data/lib/imap/backup/serializer/mbox_store.rb +2 -2
- data/lib/imap/backup/{configuration → setup}/account.rb +29 -19
- data/lib/imap/backup/{configuration → setup}/asker.rb +5 -5
- data/lib/imap/backup/setup/connection_tester.rb +26 -0
- data/lib/imap/backup/{configuration → setup}/folder_chooser.rb +18 -8
- data/lib/imap/backup/setup/helpers.rb +15 -0
- data/lib/imap/backup/{configuration/setup.rb → setup.rb} +23 -17
- data/lib/imap/backup/uploader.rb +2 -2
- data/lib/imap/backup/version.rb +2 -2
- data/lib/imap/backup.rb +7 -33
- data/lib/retry_on_error.rb +1 -1
- data/spec/features/backup_spec.rb +1 -0
- data/spec/features/support/email_server.rb +5 -2
- data/spec/support/higline_test_helpers.rb +1 -1
- data/spec/support/silence_logging.rb +1 -1
- data/spec/unit/imap/backup/account/connection_spec.rb +14 -9
- data/spec/unit/imap/backup/cli/accounts_spec.rb +47 -0
- data/spec/unit/imap/backup/cli/local_spec.rb +7 -3
- data/spec/unit/imap/backup/cli/utils_spec.rb +15 -5
- data/spec/unit/imap/backup/{configuration/store_spec.rb → configuration_spec.rb} +2 -2
- data/spec/unit/imap/backup/downloader_spec.rb +1 -1
- data/spec/unit/imap/backup/logger_spec.rb +48 -0
- data/spec/unit/imap/backup/{configuration → setup}/account_spec.rb +31 -24
- data/spec/unit/imap/backup/{configuration → setup}/asker_spec.rb +2 -2
- data/spec/unit/imap/backup/{configuration → setup}/connection_tester_spec.rb +10 -10
- data/spec/unit/imap/backup/{configuration → setup}/folder_chooser_spec.rb +8 -8
- data/spec/unit/imap/backup/{configuration/setup_spec.rb → setup_spec.rb} +48 -40
- metadata +49 -46
- data/lib/imap/backup/configuration/connection_tester.rb +0 -14
- data/lib/imap/backup/configuration/list.rb +0 -53
- data/spec/unit/imap/backup/configuration/list_spec.rb +0 -96
- data/spec/unit/imap/backup_spec.rb +0 -28
@@ -1,8 +1,10 @@
|
|
1
|
+
require "imap/backup/setup/helpers"
|
2
|
+
|
1
3
|
module Imap::Backup
|
2
|
-
|
4
|
+
class Setup; end
|
3
5
|
|
4
|
-
|
5
|
-
def initialize(
|
6
|
+
Setup::Account = Struct.new(:config, :account, :highline) do
|
7
|
+
def initialize(config, account, highline)
|
6
8
|
super
|
7
9
|
end
|
8
10
|
|
@@ -28,34 +30,38 @@ module Imap::Backup
|
|
28
30
|
modify_connection_options menu
|
29
31
|
test_connection menu
|
30
32
|
delete_account menu
|
31
|
-
menu.choice("return to main menu") { throw :done }
|
33
|
+
menu.choice("(q) return to main menu") { throw :done }
|
32
34
|
menu.hidden("quit") { throw :done }
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
def header(menu)
|
39
|
+
modified = account.modified? ? "*" : ""
|
37
40
|
connection_options =
|
38
41
|
if account.connection_options
|
39
42
|
escaped =
|
40
43
|
JSON.generate(account.connection_options).
|
41
44
|
gsub('"', '\"')
|
42
|
-
"\n connection options
|
45
|
+
"\n connection options #{escaped}"
|
43
46
|
end
|
44
|
-
menu.header = <<~HEADER
|
45
|
-
Account
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
menu.header = <<~HEADER.chomp
|
48
|
+
#{helpers.title_prefix} Account#{modified}
|
49
|
+
|
50
|
+
email #{account.username}
|
51
|
+
password #{masked_password}
|
52
|
+
path #{account.local_path}
|
53
|
+
folders #{folders.map { |f| f[:name] }.join(', ')}
|
54
|
+
server #{account.server}#{connection_options}
|
55
|
+
|
56
|
+
Choose an action
|
51
57
|
HEADER
|
52
58
|
end
|
53
59
|
|
54
60
|
def modify_email(menu)
|
55
61
|
menu.choice("modify email") do
|
56
|
-
username =
|
62
|
+
username = Setup::Asker.email(username)
|
57
63
|
Kernel.puts "username: #{username}"
|
58
|
-
other_accounts =
|
64
|
+
other_accounts = config.accounts.reject { |a| a == account }
|
59
65
|
others = other_accounts.map { |a| a.username }
|
60
66
|
Kernel.puts "others: #{others.inspect}"
|
61
67
|
if others.include?(username)
|
@@ -76,7 +82,7 @@ module Imap::Backup
|
|
76
82
|
|
77
83
|
def modify_password(menu)
|
78
84
|
menu.choice("modify password") do
|
79
|
-
password =
|
85
|
+
password = Setup::Asker.password
|
80
86
|
|
81
87
|
account.password = password if !password.nil?
|
82
88
|
end
|
@@ -97,7 +103,7 @@ module Imap::Backup
|
|
97
103
|
end
|
98
104
|
|
99
105
|
def path_modification_validator(path)
|
100
|
-
same =
|
106
|
+
same = config.accounts.find do |a|
|
101
107
|
a.username != account.username && a.local_path == path
|
102
108
|
end
|
103
109
|
if same
|
@@ -112,7 +118,7 @@ module Imap::Backup
|
|
112
118
|
def modify_backup_path(menu)
|
113
119
|
menu.choice("modify backup path") do
|
114
120
|
existing = account.local_path.clone
|
115
|
-
account.local_path =
|
121
|
+
account.local_path = Setup::Asker.backup_path(
|
116
122
|
account.local_path, ->(path) { path_modification_validator(path) }
|
117
123
|
)
|
118
124
|
end
|
@@ -120,13 +126,13 @@ module Imap::Backup
|
|
120
126
|
|
121
127
|
def choose_folders(menu)
|
122
128
|
menu.choice("choose backup folders") do
|
123
|
-
|
129
|
+
Setup::FolderChooser.new(account).run
|
124
130
|
end
|
125
131
|
end
|
126
132
|
|
127
133
|
def test_connection(menu)
|
128
134
|
menu.choice("test connection") do
|
129
|
-
result =
|
135
|
+
result = Setup::ConnectionTester.new(account).test
|
130
136
|
Kernel.puts result
|
131
137
|
highline.ask "Press a key "
|
132
138
|
end
|
@@ -163,5 +169,9 @@ module Imap::Backup
|
|
163
169
|
|
164
170
|
provider.host
|
165
171
|
end
|
172
|
+
|
173
|
+
def helpers
|
174
|
+
Setup::Helpers.new
|
175
|
+
end
|
166
176
|
end
|
167
177
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Imap::Backup
|
2
|
-
|
2
|
+
class Setup; end
|
3
3
|
|
4
|
-
|
4
|
+
Setup::Asker = Struct.new(:highline) do
|
5
5
|
EMAIL_MATCHER = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$/i.freeze
|
6
6
|
|
7
7
|
def initialize(highline)
|
@@ -40,15 +40,15 @@ module Imap::Backup
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.email(default = "")
|
43
|
-
new(
|
43
|
+
new(Setup.highline).email(default)
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.password
|
47
|
-
new(
|
47
|
+
new(Setup.highline).password
|
48
48
|
end
|
49
49
|
|
50
50
|
def self.backup_path(default, validator)
|
51
|
-
new(
|
51
|
+
new(Setup.highline).backup_path(default, validator)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Imap::Backup
|
2
|
+
class Setup; end
|
3
|
+
|
4
|
+
class Setup::ConnectionTester
|
5
|
+
attr_reader :account
|
6
|
+
|
7
|
+
def initialize(account)
|
8
|
+
@account = account
|
9
|
+
end
|
10
|
+
|
11
|
+
def test
|
12
|
+
connection.client
|
13
|
+
"Connection successful"
|
14
|
+
rescue Net::IMAP::NoResponseError
|
15
|
+
"No response"
|
16
|
+
rescue StandardError => e
|
17
|
+
"Unexpected error: #{e}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def connection
|
23
|
+
Account::Connection.new(account)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
require "imap/backup/setup/helpers"
|
2
|
+
|
1
3
|
module Imap::Backup
|
2
|
-
|
4
|
+
class Setup; end
|
3
5
|
|
4
|
-
class
|
6
|
+
class Setup::FolderChooser
|
5
7
|
attr_reader :account
|
6
8
|
|
7
9
|
def initialize(account)
|
@@ -10,13 +12,13 @@ module Imap::Backup
|
|
10
12
|
|
11
13
|
def run
|
12
14
|
if connection.nil?
|
13
|
-
Imap::Backup.logger.warn "Connection failed"
|
15
|
+
Imap::Backup::Logger.logger.warn "Connection failed"
|
14
16
|
highline.ask "Press a key "
|
15
17
|
return
|
16
18
|
end
|
17
19
|
|
18
20
|
if imap_folders.nil?
|
19
|
-
Imap::Backup.logger.warn "Unable to get folder list"
|
21
|
+
Imap::Backup::Logger.logger.warn "Unable to get folder list"
|
20
22
|
highline.ask "Press a key "
|
21
23
|
return
|
22
24
|
end
|
@@ -35,10 +37,14 @@ module Imap::Backup
|
|
35
37
|
|
36
38
|
def show_menu
|
37
39
|
highline.choose do |menu|
|
38
|
-
menu.header =
|
40
|
+
menu.header = <<~MENU.chomp
|
41
|
+
#{helpers.title_prefix} Add/remove folders
|
42
|
+
|
43
|
+
Select a folder (toggles)
|
44
|
+
MENU
|
39
45
|
menu.index = :number
|
40
46
|
add_folders menu
|
41
|
-
menu.choice("return to the account menu") { throw :done }
|
47
|
+
menu.choice("(q) return to the account menu") { throw :done }
|
42
48
|
menu.hidden("quit") { throw :done }
|
43
49
|
end
|
44
50
|
end
|
@@ -99,11 +105,15 @@ module Imap::Backup
|
|
99
105
|
end
|
100
106
|
|
101
107
|
def imap_folders
|
102
|
-
@imap_folders ||= connection.
|
108
|
+
@imap_folders ||= connection.folder_names
|
103
109
|
end
|
104
110
|
|
105
111
|
def highline
|
106
|
-
|
112
|
+
Setup.highline
|
113
|
+
end
|
114
|
+
|
115
|
+
def helpers
|
116
|
+
Setup::Helpers.new
|
107
117
|
end
|
108
118
|
end
|
109
119
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require "highline"
|
2
2
|
|
3
3
|
require "imap/backup/account"
|
4
|
+
require "imap/backup/setup/helpers"
|
4
5
|
|
5
6
|
module Imap::Backup
|
6
|
-
|
7
|
-
|
8
|
-
class Configuration::Setup
|
7
|
+
class Setup
|
9
8
|
class << self
|
10
9
|
attr_accessor :highline
|
11
10
|
end
|
12
11
|
self.highline = HighLine.new
|
13
12
|
|
14
13
|
def run
|
15
|
-
Imap::Backup.setup_logging config
|
16
14
|
catch :done do
|
17
15
|
loop do
|
18
16
|
Kernel.system("clear")
|
@@ -25,16 +23,22 @@ module Imap::Backup
|
|
25
23
|
|
26
24
|
def show_menu
|
27
25
|
self.class.highline.choose do |menu|
|
28
|
-
menu.header =
|
26
|
+
menu.header = <<~MENU.chomp
|
27
|
+
#{helpers.title_prefix} Main Menu
|
28
|
+
|
29
|
+
Choose an action
|
30
|
+
MENU
|
29
31
|
account_items menu
|
30
32
|
add_account_item menu
|
31
33
|
toggle_logging_item menu
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
throw :done
|
34
|
+
if config.modified?
|
35
|
+
menu.choice("save and exit") do
|
36
|
+
config.save
|
37
|
+
throw :done
|
38
|
+
end
|
39
|
+
menu.choice("exit without saving changes") { throw :done }
|
40
|
+
else
|
41
|
+
menu.choice("quit") { throw :done }
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -53,7 +57,7 @@ module Imap::Backup
|
|
53
57
|
|
54
58
|
def add_account_item(menu)
|
55
59
|
menu.choice("add account") do
|
56
|
-
username =
|
60
|
+
username = Asker.email
|
57
61
|
edit_account username
|
58
62
|
end
|
59
63
|
end
|
@@ -63,12 +67,12 @@ module Imap::Backup
|
|
63
67
|
new_setting = !config.debug?
|
64
68
|
menu.choice(menu_item) do
|
65
69
|
config.debug = new_setting
|
66
|
-
Imap::Backup.setup_logging
|
70
|
+
Imap::Backup::Logger.setup_logging(config)
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
70
74
|
def config
|
71
|
-
@config ||= Configuration
|
75
|
+
@config ||= Configuration.new
|
72
76
|
end
|
73
77
|
|
74
78
|
def default_account_config(username)
|
@@ -89,9 +93,11 @@ module Imap::Backup
|
|
89
93
|
account = default_account_config(username)
|
90
94
|
config.accounts << account
|
91
95
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
96
|
+
Account.new(config, account, Setup.highline).run
|
97
|
+
end
|
98
|
+
|
99
|
+
def helpers
|
100
|
+
Helpers.new
|
95
101
|
end
|
96
102
|
end
|
97
103
|
end
|
data/lib/imap/backup/uploader.rb
CHANGED
@@ -12,12 +12,12 @@ module Imap::Backup
|
|
12
12
|
count = missing_uids.count
|
13
13
|
return if count.zero?
|
14
14
|
|
15
|
-
Imap::Backup.logger.debug "[#{folder.name}] #{count} to restore"
|
15
|
+
Imap::Backup::Logger.logger.debug "[#{folder.name}] #{count} to restore"
|
16
16
|
serializer.each_message(missing_uids).with_index do |(uid, message), i|
|
17
17
|
next if message.nil?
|
18
18
|
|
19
19
|
log_prefix = "[#{folder.name}] uid: #{uid} (#{i + 1}/#{count}) -"
|
20
|
-
Imap::Backup.logger.debug(
|
20
|
+
Imap::Backup::Logger.logger.debug(
|
21
21
|
"#{log_prefix} #{message.supplied_body.size} bytes"
|
22
22
|
)
|
23
23
|
|
data/lib/imap/backup/version.rb
CHANGED
data/lib/imap/backup.rb
CHANGED
@@ -3,46 +3,20 @@ module Imap; end
|
|
3
3
|
require "imap/backup/utils"
|
4
4
|
require "imap/backup/account/connection"
|
5
5
|
require "imap/backup/account/folder"
|
6
|
-
require "imap/backup/configuration
|
7
|
-
require "imap/backup/configuration/asker"
|
8
|
-
require "imap/backup/configuration/connection_tester"
|
9
|
-
require "imap/backup/configuration/folder_chooser"
|
10
|
-
require "imap/backup/configuration/list"
|
11
|
-
require "imap/backup/configuration/setup"
|
12
|
-
require "imap/backup/configuration/store"
|
6
|
+
require "imap/backup/configuration"
|
13
7
|
require "imap/backup/downloader"
|
8
|
+
require "imap/backup/logger"
|
14
9
|
require "imap/backup/uploader"
|
15
10
|
require "imap/backup/serializer"
|
16
11
|
require "imap/backup/serializer/mbox"
|
12
|
+
require "imap/backup/setup"
|
13
|
+
require "imap/backup/setup/account"
|
14
|
+
require "imap/backup/setup/asker"
|
15
|
+
require "imap/backup/setup/connection_tester"
|
16
|
+
require "imap/backup/setup/folder_chooser"
|
17
17
|
require "imap/backup/version"
|
18
18
|
require "email/provider"
|
19
19
|
|
20
|
-
require "logger"
|
21
|
-
|
22
20
|
module Imap::Backup
|
23
21
|
class ConfigurationNotFound < StandardError; end
|
24
|
-
|
25
|
-
class Logger
|
26
|
-
include Singleton
|
27
|
-
|
28
|
-
attr_reader :logger
|
29
|
-
|
30
|
-
def initialize
|
31
|
-
@logger = ::Logger.new($stdout)
|
32
|
-
$stdout.sync = true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.logger
|
37
|
-
Logger.instance.logger
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.setup_logging(config)
|
41
|
-
logger.level =
|
42
|
-
if config.debug?
|
43
|
-
::Logger::Severity::DEBUG
|
44
|
-
else
|
45
|
-
::Logger::Severity::ERROR
|
46
|
-
end
|
47
|
-
end
|
48
22
|
end
|
data/lib/retry_on_error.rb
CHANGED
@@ -58,6 +58,7 @@ RSpec.describe "backup", type: :feature, docker: true do
|
|
58
58
|
email3
|
59
59
|
original_folder_uid_validity
|
60
60
|
connection.run_backup
|
61
|
+
connection.disconnect
|
61
62
|
server_rename_folder folder, new_name
|
62
63
|
end
|
63
64
|
let(:renamed_folder) { "#{folder}.#{original_folder_uid_validity}" }
|
@@ -63,11 +63,14 @@ module EmailServerHelpers
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def server_folders
|
66
|
-
root_info = imap.list("", "")[0]
|
67
|
-
root = root_info.name
|
68
66
|
imap.list(root, "*")
|
69
67
|
end
|
70
68
|
|
69
|
+
def root
|
70
|
+
root_info = imap.list("", "")[0]
|
71
|
+
root_info.name
|
72
|
+
end
|
73
|
+
|
71
74
|
def server_create_folder(folder)
|
72
75
|
imap.create(folder)
|
73
76
|
imap.disconnect
|
@@ -2,7 +2,7 @@ module HighLineTestHelpers
|
|
2
2
|
def prepare_highline
|
3
3
|
@input = instance_double(IO, eof?: false, gets: "q\n")
|
4
4
|
@output = StringIO.new
|
5
|
-
Imap::Backup::
|
5
|
+
Imap::Backup::Setup.highline = HighLine.new(@input, @output)
|
6
6
|
[@input, @output]
|
7
7
|
end
|
8
8
|
end
|
@@ -5,6 +5,7 @@ describe Imap::Backup::Account::Connection do
|
|
5
5
|
FOLDER_CONFIG = {name: BACKUP_FOLDER}.freeze
|
6
6
|
FOLDER_NAME = "my_folder".freeze
|
7
7
|
GMAIL_IMAP_SERVER = "imap.gmail.com".freeze
|
8
|
+
IMAP_FOLDER = "imap_folder".freeze
|
8
9
|
LOCAL_PATH = "local_path".freeze
|
9
10
|
LOCAL_UID = "local_uid".freeze
|
10
11
|
PASSWORD = "secret".freeze
|
@@ -101,19 +102,23 @@ describe Imap::Backup::Account::Connection do
|
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
104
|
-
describe "#
|
105
|
+
describe "#folder_names" do
|
105
106
|
let(:imap_folders) do
|
106
|
-
[
|
107
|
+
[IMAP_FOLDER]
|
107
108
|
end
|
108
109
|
|
109
110
|
it "returns the list of folders" do
|
110
|
-
expect(subject.
|
111
|
+
expect(subject.folder_names).to eq([IMAP_FOLDER])
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
115
|
describe "#status" do
|
115
116
|
let(:folder) do
|
116
|
-
instance_double(
|
117
|
+
instance_double(
|
118
|
+
Imap::Backup::Account::Folder,
|
119
|
+
uids: [remote_uid],
|
120
|
+
name: IMAP_FOLDER
|
121
|
+
)
|
117
122
|
end
|
118
123
|
let(:remote_uid) { "remote_uid" }
|
119
124
|
|
@@ -123,7 +128,7 @@ describe Imap::Backup::Account::Connection do
|
|
123
128
|
end
|
124
129
|
|
125
130
|
it "returns the names of folders" do
|
126
|
-
expect(subject.status[0][:name]).to eq(
|
131
|
+
expect(subject.status[0][:name]).to eq(IMAP_FOLDER)
|
127
132
|
end
|
128
133
|
|
129
134
|
it "returns local message uids" do
|
@@ -139,7 +144,7 @@ describe Imap::Backup::Account::Connection do
|
|
139
144
|
let(:folder) do
|
140
145
|
instance_double(
|
141
146
|
Imap::Backup::Account::Folder,
|
142
|
-
name:
|
147
|
+
name: IMAP_FOLDER,
|
143
148
|
exist?: exists,
|
144
149
|
uid_validity: uid_validity
|
145
150
|
)
|
@@ -150,11 +155,11 @@ describe Imap::Backup::Account::Connection do
|
|
150
155
|
|
151
156
|
before do
|
152
157
|
allow(Imap::Backup::Downloader).
|
153
|
-
to receive(:new).with(folder, serializer) { downloader }
|
158
|
+
to receive(:new).with(folder, serializer, anything) { downloader }
|
154
159
|
allow(Imap::Backup::Account::Folder).to receive(:new).
|
155
160
|
with(subject, BACKUP_FOLDER) { folder }
|
156
161
|
allow(Imap::Backup::Serializer::Mbox).to receive(:new).
|
157
|
-
with(LOCAL_PATH,
|
162
|
+
with(LOCAL_PATH, IMAP_FOLDER) { serializer }
|
158
163
|
end
|
159
164
|
|
160
165
|
context "with supplied config_folders" do
|
@@ -248,7 +253,7 @@ describe Imap::Backup::Account::Connection do
|
|
248
253
|
Imap::Backup::Account::Folder,
|
249
254
|
create: nil,
|
250
255
|
uids: uids,
|
251
|
-
name:
|
256
|
+
name: IMAP_FOLDER,
|
252
257
|
uid_validity: uid_validity
|
253
258
|
)
|
254
259
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "imap/backup/cli/accounts"
|
2
|
+
|
3
|
+
describe Imap::Backup::CLI::Accounts do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
let(:accounts) { [account1, account2] }
|
7
|
+
let(:account1) do
|
8
|
+
instance_double(
|
9
|
+
Imap::Backup::Account,
|
10
|
+
username: "a1@example.com"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
let(:account2) do
|
14
|
+
instance_double(
|
15
|
+
Imap::Backup::Account,
|
16
|
+
username: "a2@example.com"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
let(:store) do
|
20
|
+
instance_double(Imap::Backup::Configuration, accounts: accounts)
|
21
|
+
end
|
22
|
+
let(:exists) { true }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(Imap::Backup::Configuration).to receive(:new) { store }
|
26
|
+
allow(Imap::Backup::Configuration).
|
27
|
+
to receive(:exist?) { exists }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#each" do
|
31
|
+
specify "calls the block with each account" do
|
32
|
+
result = subject.map { |a| a }
|
33
|
+
|
34
|
+
expect(result).to eq(accounts)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when the configuration file is missing" do
|
38
|
+
let(:exists) { false }
|
39
|
+
|
40
|
+
it "fails" do
|
41
|
+
expect do
|
42
|
+
subject.each {}
|
43
|
+
end.to raise_error(Imap::Backup::ConfigurationNotFound, /not found/)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
describe Imap::Backup::CLI::Local do
|
2
|
-
let(:
|
3
|
-
instance_double(
|
2
|
+
let(:accounts) do
|
3
|
+
instance_double(
|
4
|
+
Imap::Backup::CLI::Accounts,
|
5
|
+
find: ->(&block) { [account].find { |a| block.call(a) } }
|
6
|
+
)
|
4
7
|
end
|
5
8
|
let(:account) do
|
6
9
|
instance_double(
|
@@ -38,9 +41,10 @@ describe Imap::Backup::CLI::Local do
|
|
38
41
|
|
39
42
|
before do
|
40
43
|
allow(Kernel).to receive(:puts)
|
41
|
-
allow(Imap::Backup::
|
44
|
+
allow(Imap::Backup::CLI::Accounts).to receive(:new) { accounts }
|
42
45
|
allow(Imap::Backup::Account::Connection).to receive(:new) { connection }
|
43
46
|
allow(Mail).to receive(:new) { mail }
|
47
|
+
allow(accounts).to receive(:each).and_yield(account)
|
44
48
|
end
|
45
49
|
|
46
50
|
describe "accounts" do
|
@@ -1,16 +1,25 @@
|
|
1
1
|
module Imap::Backup
|
2
2
|
describe CLI::Utils do
|
3
|
-
let(:
|
4
|
-
instance_double(
|
3
|
+
let(:accounts) do
|
4
|
+
instance_double(
|
5
|
+
CLI::Accounts,
|
6
|
+
find: ->(&block) { [account].find { |a| block.call(a) } }
|
7
|
+
)
|
5
8
|
end
|
6
9
|
let(:account) { instance_double(Account, username: email) }
|
7
10
|
let(:connection) do
|
8
11
|
instance_double(
|
9
12
|
Account::Connection,
|
10
|
-
|
13
|
+
account: account,
|
14
|
+
backup_folders: [folder]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
let(:account) do
|
18
|
+
instance_double(
|
19
|
+
Account,
|
20
|
+
local_path: "path"
|
11
21
|
)
|
12
22
|
end
|
13
|
-
let(:local_folders) { [[serializer, folder]] }
|
14
23
|
let(:folder) do
|
15
24
|
instance_double(
|
16
25
|
Account::Folder,
|
@@ -31,8 +40,9 @@ module Imap::Backup
|
|
31
40
|
let(:email) { "foo@example.com" }
|
32
41
|
|
33
42
|
before do
|
34
|
-
allow(
|
43
|
+
allow(CLI::Accounts).to receive(:new) { accounts }
|
35
44
|
allow(Account::Connection).to receive(:new) { connection }
|
45
|
+
allow(Serializer::Mbox).to receive(:new) { serializer }
|
36
46
|
end
|
37
47
|
|
38
48
|
describe "ignore_history" do
|