imap-backup 1.0.11 → 1.0.12
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/lib/imap/backup/account/folder.rb +9 -4
- data/lib/imap/backup/configuration/account.rb +3 -3
- data/lib/imap/backup/configuration/list.rb +2 -2
- data/lib/imap/backup/configuration/setup.rb +4 -8
- data/lib/imap/backup/configuration/store.rb +9 -1
- data/lib/imap/backup/version.rb +1 -1
- data/spec/unit/configuration/account_spec.rb +4 -4
- data/spec/unit/configuration/list_spec.rb +1 -1
- data/spec/unit/configuration/setup_spec.rb +5 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c42e0f05b9fe1321562fd54446d99f765ad1544
|
4
|
+
data.tar.gz: 6e005f9c0605e371063ea1b2eec65e04ad6bd71c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea5b48a3cbbf5b9513efbb0f453941bf33e96e1f6008b8d4af4414ef5b03a8502c30393c512e630186c0ba49e6d232facc93433fa86616aaab97716ac5082d8d
|
7
|
+
data.tar.gz: c9d9a35daf1ed227922de3e7601a30a383ea4cc5d87259a546a1a8914db48206909b6c75c60993db12ee147a50ae204fe5d9bff41ca0ffd427fa72aa86a3cc24
|
@@ -1,29 +1,34 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
4
|
module Imap::Backup
|
4
5
|
module Account; end
|
5
6
|
|
6
7
|
class Account::Folder
|
8
|
+
extend Forwardable
|
9
|
+
|
7
10
|
REQUESTED_ATTRIBUTES = ['RFC822', 'FLAGS', 'INTERNALDATE']
|
8
11
|
|
9
12
|
attr_reader :connection
|
10
13
|
attr_reader :folder
|
11
14
|
|
15
|
+
delegate imap: :connection
|
16
|
+
|
12
17
|
def initialize(connection, folder)
|
13
18
|
@connection, @folder = connection, folder
|
14
19
|
end
|
15
20
|
|
16
21
|
def uids
|
17
|
-
|
18
|
-
|
22
|
+
imap.examine(folder)
|
23
|
+
imap.uid_search(['ALL']).sort
|
19
24
|
rescue Net::IMAP::NoResponseError => e
|
20
25
|
Imap::Backup.logger.warn "Folder '#{folder}' does not exist"
|
21
26
|
[]
|
22
27
|
end
|
23
28
|
|
24
29
|
def fetch(uid)
|
25
|
-
|
26
|
-
message =
|
30
|
+
imap.examine(folder)
|
31
|
+
message = imap.uid_fetch([uid.to_i], REQUESTED_ATTRIBUTES)[0][1]
|
27
32
|
message['RFC822'].force_encoding('utf-8') if RUBY_VERSION > '1.9'
|
28
33
|
message
|
29
34
|
rescue Net::IMAP::NoResponseError => e
|
@@ -49,7 +49,7 @@ Account:
|
|
49
49
|
menu.choice('modify email') do
|
50
50
|
username = Configuration::Asker.email(username)
|
51
51
|
puts "username: #{username}"
|
52
|
-
others = store.
|
52
|
+
others = store.accounts.select { |a| a != account}.map { |a| a[:username] }
|
53
53
|
puts "others: #{others.inspect}"
|
54
54
|
if others.include?(username)
|
55
55
|
puts 'There is already an account set up with that email address'
|
@@ -83,7 +83,7 @@ Account:
|
|
83
83
|
def modify_backup_path(menu)
|
84
84
|
menu.choice('modify backup path') do
|
85
85
|
validator = lambda do |p|
|
86
|
-
same = store.
|
86
|
+
same = store.accounts.find do |a|
|
87
87
|
a[:username] != account[:username] && a[:local_path] == p
|
88
88
|
end
|
89
89
|
if same
|
@@ -114,7 +114,7 @@ Account:
|
|
114
114
|
def delete_account(menu)
|
115
115
|
menu.choice('delete') do
|
116
116
|
if highline.agree("Are you sure? (y/n) ")
|
117
|
-
store.
|
117
|
+
store.accounts.reject! { |a| a[:username] == account[:username] }
|
118
118
|
throw :done
|
119
119
|
end
|
120
120
|
end
|
@@ -31,9 +31,9 @@ module Imap::Backup
|
|
31
31
|
def accounts
|
32
32
|
return @accounts if @accounts
|
33
33
|
if required_accounts.nil?
|
34
|
-
@accounts = config.
|
34
|
+
@accounts = config.accounts
|
35
35
|
else
|
36
|
-
@accounts = config.
|
36
|
+
@accounts = config.accounts.select{ |account| required_accounts.include?(account[:username]) }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -28,10 +28,6 @@ module Imap::Backup
|
|
28
28
|
menu.header = 'Choose an action'
|
29
29
|
account_items menu
|
30
30
|
add_account_item menu
|
31
|
-
menu.choice('add account') do
|
32
|
-
username = Configuration::Asker.email
|
33
|
-
edit_account username
|
34
|
-
end
|
35
31
|
menu.choice('save and exit') do
|
36
32
|
config.save
|
37
33
|
throw :done
|
@@ -41,7 +37,7 @@ module Imap::Backup
|
|
41
37
|
end
|
42
38
|
|
43
39
|
def account_items(menu)
|
44
|
-
config.
|
40
|
+
config.accounts.each do |account|
|
45
41
|
menu.choice("#{account[:username]}") do
|
46
42
|
edit_account account[:username]
|
47
43
|
end
|
@@ -61,7 +57,7 @@ module Imap::Backup
|
|
61
57
|
|
62
58
|
def setup_logging
|
63
59
|
Imap::Backup.logger.level =
|
64
|
-
if config.
|
60
|
+
if config.debug?
|
65
61
|
::Logger::Severity::DEBUG
|
66
62
|
else
|
67
63
|
::Logger::Severity::ERROR
|
@@ -78,10 +74,10 @@ module Imap::Backup
|
|
78
74
|
end
|
79
75
|
|
80
76
|
def edit_account(username)
|
81
|
-
account = config.
|
77
|
+
account = config.accounts.find { |a| a[:username] == username }
|
82
78
|
if account.nil?
|
83
79
|
account = default_account_config(username)
|
84
|
-
config.
|
80
|
+
config.accounts << account
|
85
81
|
end
|
86
82
|
Configuration::Account.new(config, account, Configuration::Setup.highline).run
|
87
83
|
end
|
@@ -33,7 +33,7 @@ module Imap::Backup
|
|
33
33
|
mkdir_private path
|
34
34
|
File.open(pathname, 'w') { |f| f.write(JSON.pretty_generate(data)) }
|
35
35
|
FileUtils.chmod 0600, pathname
|
36
|
-
|
36
|
+
accounts.each do |account|
|
37
37
|
mkdir_private account[:local_path]
|
38
38
|
account[:folders].each do |f|
|
39
39
|
parts = f[:name].split('/')
|
@@ -46,6 +46,14 @@ module Imap::Backup
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def accounts
|
50
|
+
data[:accounts]
|
51
|
+
end
|
52
|
+
|
53
|
+
def debug?
|
54
|
+
data.include?(:debug)
|
55
|
+
end
|
56
|
+
|
49
57
|
private
|
50
58
|
|
51
59
|
def data
|
data/lib/imap/backup/version.rb
CHANGED
@@ -42,8 +42,8 @@ describe Imap::Backup::Configuration::Account do
|
|
42
42
|
context '#run' do
|
43
43
|
let(:highline) { double('Highline') }
|
44
44
|
let(:menu) { MockHighlineMenu.new }
|
45
|
-
let(:store) { double('Imap::Backup::Configuration::Store', :
|
46
|
-
let(:
|
45
|
+
let(:store) { double('Imap::Backup::Configuration::Store', :accounts => accounts) }
|
46
|
+
let(:accounts) { [account, account1] }
|
47
47
|
let(:account) do
|
48
48
|
{
|
49
49
|
:username => existing_email,
|
@@ -292,14 +292,14 @@ describe Imap::Backup::Configuration::Account do
|
|
292
292
|
end
|
293
293
|
|
294
294
|
it 'deletes the account' do
|
295
|
-
expect(
|
295
|
+
expect(accounts.find { |a| a[:username] == existing_email }).to be_nil
|
296
296
|
end
|
297
297
|
|
298
298
|
context 'without confirmation' do
|
299
299
|
let(:confirmed) { false }
|
300
300
|
|
301
301
|
it 'does nothing' do
|
302
|
-
expect(
|
302
|
+
expect(accounts.find{|a| a[:username] == existing_email}).to eq(account)
|
303
303
|
end
|
304
304
|
end
|
305
305
|
end
|
@@ -9,7 +9,7 @@ describe Imap::Backup::Configuration::List do
|
|
9
9
|
]
|
10
10
|
end
|
11
11
|
let(:store) do
|
12
|
-
double('Imap::Backup::Configuration::Store', :
|
12
|
+
double('Imap::Backup::Configuration::Store', accounts: accounts)
|
13
13
|
end
|
14
14
|
let(:exists) { true }
|
15
15
|
let(:connection1) { double('Imap::Backup::Account::Connection', :disconnect => nil) }
|
@@ -15,13 +15,14 @@ describe Imap::Backup::Configuration::Setup do
|
|
15
15
|
context '#run' do
|
16
16
|
let(:account1) { {:username => 'account@example.com'} }
|
17
17
|
let(:account) { double('Imap::Backup::Configuration::Account', :run => nil) }
|
18
|
-
let(:
|
18
|
+
let(:accounts) { [account1] }
|
19
19
|
let(:store) do
|
20
20
|
double(
|
21
21
|
'Imap::Backup::Configuration::Store',
|
22
|
-
:
|
22
|
+
:accounts => accounts,
|
23
23
|
:path => '/base/path',
|
24
|
-
:save => nil
|
24
|
+
:save => nil,
|
25
|
+
:debug? => false,
|
25
26
|
)
|
26
27
|
end
|
27
28
|
|
@@ -76,7 +77,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
76
77
|
end
|
77
78
|
|
78
79
|
it 'adds account data' do
|
79
|
-
expect(
|
80
|
+
expect(accounts[1]).to eq(blank_account)
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|