imap-backup 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 664cab74407b44814015417f5488f9ebf194554a
4
- data.tar.gz: 64acb39ad63cf6cf194e813c31c70edcb41afeba
3
+ metadata.gz: 7c42e0f05b9fe1321562fd54446d99f765ad1544
4
+ data.tar.gz: 6e005f9c0605e371063ea1b2eec65e04ad6bd71c
5
5
  SHA512:
6
- metadata.gz: 86a3fac151e45fc4d061e26a8569de2d89fb2b37063b11ae7374ee54400ce67eaa4e385ab37f9daef33fdd011305634cf37f50f908590829f037a7d8ca10fbdb
7
- data.tar.gz: 292a8b80a095a74091e8b981783f92730a1044c429a761b983770585ead60c5bcd35928193767fdf5daefdb7a1e2f67fbbcfc67df5b7c41e1d9b920d19244f69
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
- connection.imap.examine(folder)
18
- connection.imap.uid_search(['ALL']).sort
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
- connection.imap.examine(folder)
26
- message = connection.imap.uid_fetch([uid.to_i], REQUESTED_ATTRIBUTES)[0][1]
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.data[:accounts].select { |a| a != account}.map { |a| a[:username] }
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.data[:accounts].find do |a|
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.data[:accounts].reject! { |a| a[:username] == account[:username] }
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.data[:accounts]
34
+ @accounts = config.accounts
35
35
  else
36
- @accounts = config.data[:accounts].select{ |account| required_accounts.include?(account[:username]) }
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.data[:accounts].each do |account|
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.data[:debug]
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.data[:accounts].find { |a| a[:username] == username }
77
+ account = config.accounts.find { |a| a[:username] == username }
82
78
  if account.nil?
83
79
  account = default_account_config(username)
84
- config.data[:accounts] << account
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
- @data[:accounts].each do |account|
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
@@ -3,6 +3,6 @@ module Imap; end
3
3
  module Imap::Backup
4
4
  MAJOR = 1
5
5
  MINOR = 0
6
- REVISION = 11
6
+ REVISION = 12
7
7
  VERSION = [MAJOR, MINOR, REVISION].map(&:to_s).join('.')
8
8
  end
@@ -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', :data => data) }
46
- let(:data) { {:accounts => [account, account1]} }
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(data[:accounts].find{|a| a[:username] == existing_email}).to be_nil
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(data[:accounts].find{|a| a[:username] == existing_email}).to eq(account)
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', :data => {:accounts => accounts})
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(:data) { {:accounts => [account1]} }
18
+ let(:accounts) { [account1] }
19
19
  let(:store) do
20
20
  double(
21
21
  'Imap::Backup::Configuration::Store',
22
- :data => data,
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(data[:accounts][1]).to eq(blank_account)
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.11
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-16 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake