imap-backup 1.0.5 → 1.0.6
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/.gitignore +0 -1
- data/.travis.yml +1 -1
- data/Gemfile +0 -1
- data/README.md +0 -1
- data/Rakefile +4 -9
- data/bin/imap-backup +0 -1
- data/imap-backup.gemspec +0 -1
- data/lib/email/mboxrd/message.rb +31 -32
- data/lib/imap/backup.rb +17 -4
- data/lib/imap/backup/account/connection.rb +70 -64
- data/lib/imap/backup/account/folder.rb +21 -26
- data/lib/imap/backup/configuration/account.rb +127 -73
- data/lib/imap/backup/configuration/asker.rb +38 -31
- data/lib/imap/backup/configuration/connection_tester.rb +9 -14
- data/lib/imap/backup/configuration/folder_chooser.rb +43 -48
- data/lib/imap/backup/configuration/list.rb +19 -24
- data/lib/imap/backup/configuration/setup.rb +56 -51
- data/lib/imap/backup/configuration/store.rb +47 -52
- data/lib/imap/backup/downloader.rb +11 -14
- data/lib/imap/backup/serializer/base.rb +8 -11
- data/lib/imap/backup/serializer/directory.rb +36 -41
- data/lib/imap/backup/serializer/mbox.rb +83 -88
- data/lib/imap/backup/utils.rb +0 -3
- data/lib/imap/backup/version.rb +1 -2
- data/spec/gather_rspec_coverage.rb +0 -1
- data/spec/spec_helper.rb +2 -7
- data/spec/unit/account/connection_spec.rb +0 -1
- data/spec/unit/account/folder_spec.rb +0 -1
- data/spec/unit/configuration/account_spec.rb +207 -136
- data/spec/unit/configuration/asker_spec.rb +59 -85
- data/spec/unit/configuration/connection_tester_spec.rb +36 -26
- data/spec/unit/configuration/folder_chooser_spec.rb +3 -6
- data/spec/unit/configuration/list_spec.rb +0 -1
- data/spec/unit/configuration/setup_spec.rb +8 -9
- data/spec/unit/configuration/store_spec.rb +1 -4
- data/spec/unit/downloader_spec.rb +0 -1
- data/spec/unit/email/mboxrd/message_spec.rb +0 -1
- data/spec/unit/serializer/base_spec.rb +0 -1
- data/spec/unit/serializer/directory_spec.rb +0 -1
- data/spec/unit/serializer/mbox_spec.rb +0 -1
- data/spec/unit/utils_spec.rb +0 -1
- metadata +2 -2
@@ -1,114 +1,88 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/email/)
|
4
|
+
module Imap::Backup::Configuration
|
5
|
+
describe Asker do
|
6
|
+
let(:highline) { double }
|
8
7
|
|
9
|
-
|
8
|
+
subject { Asker.new(highline) }
|
9
|
+
|
10
|
+
context '#initialize' do
|
11
|
+
its(:highline) { should eq(highline) }
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
q = stub('HighLine::Question', :default= => nil,
|
15
|
-
:readline= => nil,
|
16
|
-
:responses => {})
|
17
|
-
q.should_receive(:validate=).with(instance_of(Regexp))
|
14
|
+
context '#email' do
|
15
|
+
let(:email) { 'email@example.com' }
|
18
16
|
|
19
|
-
|
17
|
+
before do
|
18
|
+
allow(highline).to receive(:ask).and_return(email)
|
19
|
+
@result = subject.email
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
it 'should return the address' do
|
26
|
-
Imap::Backup::Configuration::Setup.highline.stub!(:ask).with(/email/).and_return('new@example.com')
|
27
|
-
|
28
|
-
Imap::Backup::Configuration::Asker.email.should == 'new@example.com'
|
29
|
-
end
|
30
|
-
end
|
22
|
+
it 'asks for an email' do
|
23
|
+
expect(highline).to have_received(:ask).with(/email/)
|
24
|
+
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Imap::Backup::Configuration::Setup.highline.stub!(:ask).with(/^repeat password/).and_return('secret')
|
26
|
+
it 'returns the address' do
|
27
|
+
expect(@result).to eq(email)
|
28
|
+
end
|
36
29
|
end
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
context '#password' do
|
32
|
+
let(:password1) { 'password' }
|
33
|
+
let(:password2) { 'password' }
|
34
|
+
let(:answers) { [answer1, answer2] }
|
35
|
+
let(:answer1) { true }
|
36
|
+
let(:answer2) { false }
|
37
|
+
|
38
|
+
before do
|
39
|
+
@i = 0
|
40
|
+
allow(highline).to receive(:ask).with('password: ').and_return(password1)
|
41
|
+
allow(highline).to receive(:ask).with('repeat password: ').and_return(password2)
|
42
|
+
allow(highline).to receive(:agree) do
|
43
|
+
answer = answers[@i]
|
44
|
+
@i += 1
|
45
|
+
answer
|
46
|
+
end
|
47
|
+
@result = subject.password
|
48
|
+
end
|
41
49
|
|
42
|
-
|
43
|
-
|
50
|
+
it 'asks for a password' do
|
51
|
+
expect(highline).to have_received(:ask).with('password: ')
|
52
|
+
end
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
|
54
|
+
it 'asks for confirmation' do
|
55
|
+
expect(highline).to have_received(:ask).with('repeat password: ')
|
56
|
+
end
|
48
57
|
|
49
|
-
|
50
|
-
|
51
|
-
Imap::Backup::Configuration::Setup.highline.stub!(:ask) do
|
52
|
-
case state
|
53
|
-
when :password1
|
54
|
-
state = :confirmation1
|
55
|
-
'secret'
|
56
|
-
when :confirmation1
|
57
|
-
state = :retry?
|
58
|
-
'wrong!!!'
|
59
|
-
when :retry?
|
60
|
-
state = :password2
|
61
|
-
'y'
|
62
|
-
when :password2
|
63
|
-
state = :confirmation2
|
64
|
-
'secret'
|
65
|
-
when :confirmation2
|
66
|
-
'secret'
|
67
|
-
end
|
58
|
+
it 'returns the password' do
|
59
|
+
expect(@result).to eq(password1)
|
68
60
|
end
|
69
61
|
|
70
|
-
|
71
|
-
|
62
|
+
context 'different answers' do
|
63
|
+
let(:password2) { 'secret' }
|
72
64
|
|
73
|
-
|
74
|
-
|
75
|
-
Imap::Backup::Configuration::Setup.highline.stub!(:ask) do
|
76
|
-
case state
|
77
|
-
when :password1
|
78
|
-
state = :confirmation1
|
79
|
-
'secret'
|
80
|
-
when :confirmation1
|
81
|
-
state = :retry?
|
82
|
-
'wrong!!!'
|
83
|
-
when :retry?
|
84
|
-
state = :password2
|
85
|
-
'n'
|
65
|
+
it 'asks to continue' do
|
66
|
+
expect(highline).to have_received(:agree).at_least(1).times.with(/Continue\?/)
|
86
67
|
end
|
87
68
|
end
|
88
|
-
|
89
|
-
Imap::Backup::Configuration::Asker.password.should be_nil
|
90
69
|
end
|
91
|
-
end
|
92
70
|
|
93
|
-
|
94
|
-
|
95
|
-
validator = /validator/
|
96
|
-
Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/directory/) do |&block|
|
97
|
-
q = stub('HighLine::Question', :responses => {}, :readline= => nil)
|
98
|
-
q.should_receive(:default=).with('default path')
|
99
|
-
q.should_receive(:validate=).with(validator)
|
71
|
+
context '#backup_path' do
|
72
|
+
let(:path) { '/path' }
|
100
73
|
|
101
|
-
|
74
|
+
before do
|
75
|
+
allow(highline).to receive(:ask).and_return(path)
|
76
|
+
@result = subject.backup_path('', //)
|
102
77
|
end
|
103
78
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
it 'should return the choice' do
|
108
|
-
Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/directory/).and_return('/path')
|
79
|
+
it 'asks for a directory' do
|
80
|
+
expect(highline).to have_received(:ask).with(/directory/)
|
81
|
+
end
|
109
82
|
|
110
|
-
|
83
|
+
it 'returns the path' do
|
84
|
+
expect(@result).to eq(path)
|
85
|
+
end
|
111
86
|
end
|
112
87
|
end
|
113
88
|
end
|
114
|
-
|
@@ -3,41 +3,51 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Imap::Backup::Configuration::ConnectionTester do
|
5
5
|
context '.test' do
|
6
|
-
|
7
|
-
Imap::Backup::Account::Connection.should_receive(:new).with('foo')
|
6
|
+
let(:connection) { double('Imap::Backup::Account::Connection', :imap => nil) }
|
8
7
|
|
9
|
-
|
8
|
+
before do
|
9
|
+
allow(Imap::Backup::Account::Connection).to receive(:new).and_return(connection)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
with('foo')
|
12
|
+
context 'call' do
|
13
|
+
before { @result = subject.test('foo') }
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
it 'tries to connect' do
|
16
|
+
expect(connection).to have_received(:imap)
|
17
|
+
end
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
Imap::Backup::Account::Connection.stub!(:new).
|
24
|
-
with('foo').
|
25
|
-
and_raise(e)
|
26
|
-
|
27
|
-
result = Imap::Backup::Configuration::ConnectionTester.test('foo')
|
20
|
+
context 'success' do
|
21
|
+
before { @result = subject.test('foo') }
|
28
22
|
|
29
|
-
|
23
|
+
it 'returns success' do
|
24
|
+
expect(@result).to match(/successful/)
|
25
|
+
end
|
30
26
|
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
context 'failure' do
|
29
|
+
before do
|
30
|
+
allow(connection).to receive(:imap).and_raise(error)
|
31
|
+
@result = subject.test('foo')
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'no connection' do
|
35
|
+
let(:error) do
|
36
|
+
data = double('foo', :text => 'bar')
|
37
|
+
Net::IMAP::NoResponseError.new(double('o', :data => data))
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns success' do
|
41
|
+
expect(@result).to match(/no response/i)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'other' do
|
46
|
+
let(:error) { 'Error' }
|
47
|
+
it 'returns success' do
|
48
|
+
expect(@result).to match(/unexpected error/i)
|
49
|
+
end
|
50
|
+
end
|
40
51
|
end
|
41
52
|
end
|
42
53
|
end
|
43
|
-
|
@@ -8,9 +8,7 @@ describe Imap::Backup::Configuration::FolderChooser do
|
|
8
8
|
|
9
9
|
context '#run' do
|
10
10
|
let(:connection) do
|
11
|
-
stub(
|
12
|
-
'Imap::Backup::Account::Connection'
|
13
|
-
)
|
11
|
+
stub('Imap::Backup::Account::Connection')
|
14
12
|
end
|
15
13
|
let(:existing_account) do
|
16
14
|
{
|
@@ -124,7 +122,7 @@ describe Imap::Backup::Configuration::FolderChooser do
|
|
124
122
|
subject.run
|
125
123
|
|
126
124
|
@output.string.should =~ /\d+\. \+ another_folder/
|
127
|
-
account[:folders].should include(
|
125
|
+
account[:folders].should include({:name => 'another_folder'})
|
128
126
|
end
|
129
127
|
|
130
128
|
it 'should remove folders' do
|
@@ -142,9 +140,8 @@ describe Imap::Backup::Configuration::FolderChooser do
|
|
142
140
|
subject.run
|
143
141
|
|
144
142
|
@output.string.should =~ /\d+\. \- my_folder/
|
145
|
-
account[:folders].should_not include(
|
143
|
+
account[:folders].should_not include({:name => 'my_folder'})
|
146
144
|
end
|
147
145
|
end
|
148
146
|
end
|
149
147
|
end
|
150
|
-
|
@@ -5,10 +5,10 @@ describe Imap::Backup::Configuration::Setup do
|
|
5
5
|
include HighLineTestHelpers
|
6
6
|
|
7
7
|
context '#initialize' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
context 'without a config file' do
|
9
|
+
it 'works' do
|
10
|
+
Imap::Backup::Configuration::Setup.new
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -20,8 +20,8 @@ describe Imap::Backup::Configuration::Setup do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def prepare_store
|
23
|
-
@account1 = {
|
24
|
-
@data = {
|
23
|
+
@account1 = {:username => 'account@example.com'}
|
24
|
+
@data = {:accounts => [@account1]}
|
25
25
|
@store = stub('Imap::Backup::Configuration::Store', :data => @data, :path => '/base/path')
|
26
26
|
Imap::Backup::Configuration::Store.stub!(:new).and_return(@store)
|
27
27
|
end
|
@@ -65,7 +65,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
@account = stub('Imap::Backup::Configuration::Account')
|
68
|
-
Imap::Backup::Configuration::Account.
|
68
|
+
allow(Imap::Backup::Configuration::Account).to receive(:new).with(@store, @account1, anything).and_return(@account)
|
69
69
|
@account.should_receive(:run).with()
|
70
70
|
|
71
71
|
subject.run
|
@@ -86,7 +86,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
86
86
|
blank_account = {:username=>"new@example.com", :password=>"", :local_path=>"/base/path/new_example.com", :folders=>[]}
|
87
87
|
Imap::Backup::Configuration::Asker.should_receive(:email).with().and_return('new@example.com')
|
88
88
|
@account = stub('Imap::Backup::Configuration::Account')
|
89
|
-
Imap::Backup::Configuration::Account.
|
89
|
+
allow(Imap::Backup::Configuration::Account).to receive(:new).with(@store, blank_account, anything).and_return(@account)
|
90
90
|
@account.should_receive(:run).once
|
91
91
|
|
92
92
|
subject.run
|
@@ -114,4 +114,3 @@ describe Imap::Backup::Configuration::Setup do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
@@ -146,9 +146,7 @@ describe Imap::Backup::Configuration::Store do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'should create a path for folders with slashes' do
|
149
|
-
folders = [
|
150
|
-
{ :name => 'folder/path' },
|
151
|
-
]
|
149
|
+
folders = [{:name => 'folder/path'}]
|
152
150
|
JSON.stub!(:parse).with('xxx', :symbolize_names => true).and_return(configuration(folders))
|
153
151
|
|
154
152
|
File.should_receive(:directory?).with('/my/backup/path/folder').and_return(true)
|
@@ -161,4 +159,3 @@ describe Imap::Backup::Configuration::Store do
|
|
161
159
|
end
|
162
160
|
end
|
163
161
|
end
|
164
|
-
|
data/spec/unit/utils_spec.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: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|