imap-backup 4.0.4 → 4.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69ed28d85dda7c3d30cd6c8d4a9888e9f477eedd6f8ff08741fcc7d27cf087f8
4
- data.tar.gz: 1a99e7143052a1d0b1b2d58381c5f9da0db2b1e0e3882c24e56036cebead043f
3
+ metadata.gz: 6eebcf60acbb2e97a007e5da03c63fb7c32e24413397f28d3ec9f94154b8def5
4
+ data.tar.gz: 5f81961b55811c8c9fadabf2def11e1e00ab8572fd844f44b8fda371aa190bbb
5
5
  SHA512:
6
- metadata.gz: deb80ed5d629c81253574d96a7da0dcc6382eb6d5216c1f317b8083ca0f4dac80a3188cbc0b7f46ffbc01229dad9ab913858649558ca7b3a29bf7b81395bcce3
7
- data.tar.gz: 2e6b2b8d2c67c6bc1e3ff5dcbb91c4eec92d0edb87ff33ad6e8a360b6635895c72cc7eb4cc68a7ff24bcfbad5a3533bda0a916e3c4d0c40ee67de70a010d4b2b
6
+ metadata.gz: 6ebb0d93413c0911487235584837f76f6409d66cc06a64ad9e7db7ec0a4ccca2694b9be363e02922bbf1c981d944a9772e6705190ad92b461252d7b57bf1e4b0
7
+ data.tar.gz: 6f29640122bf11c098050476e60caa073ebb868a0859624d6e7b74df435e85a1d6ebbcf964840058c6978a42d16034d86341741caead66d99722554ffc2ca4a3
@@ -1,6 +1,6 @@
1
- require "email/provider/default"
1
+ require "email/provider/base"
2
2
 
3
- class Email::Provider::AppleMail < Email::Provider::Default
3
+ class Email::Provider::AppleMail < Email::Provider::Base
4
4
  def host
5
5
  "imap.mail.me.com"
6
6
  end
@@ -0,0 +1,8 @@
1
+ module Email; end
2
+ class Email::Provider; end
3
+
4
+ class Email::Provider::Base
5
+ def options
6
+ {port: 993, ssl: {ssl_version: :TLSv1_2}}
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
- require "email/provider/default"
1
+ require "email/provider/base"
2
2
 
3
- class Email::Provider::Fastmail < Email::Provider::Default
3
+ class Email::Provider::Fastmail < Email::Provider::Base
4
4
  def host
5
5
  "imap.fastmail.com"
6
6
  end
@@ -1,6 +1,6 @@
1
- require "email/provider/default"
1
+ require "email/provider/base"
2
2
 
3
- class Email::Provider::GMail < Email::Provider::Default
3
+ class Email::Provider::GMail < Email::Provider::Base
4
4
  def host
5
5
  "imap.gmail.com"
6
6
  end
@@ -1,7 +1,6 @@
1
- module Email; end
2
- class Email::Provider; end
1
+ require "email/provider/base"
3
2
 
4
- class Email::Provider::Default
3
+ class Email::Provider::Unknown < Email::Provider::Base
5
4
  # We don't know how to guess the IMAP server
6
5
  def host
7
6
  end
@@ -1,7 +1,7 @@
1
- require "email/provider/default"
2
1
  require "email/provider/apple_mail"
3
2
  require "email/provider/fastmail"
4
3
  require "email/provider/gmail"
4
+ require "email/provider/unknown"
5
5
 
6
6
  module Email; end
7
7
 
@@ -21,7 +21,7 @@ class Email::Provider
21
21
  when address.end_with?("@me.com")
22
22
  Email::Provider::AppleMail.new
23
23
  else
24
- Email::Provider::Default.new
24
+ Email::Provider::Unknown.new
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,103 @@
1
+ module Imap::Backup
2
+ class Account
3
+ attr_reader :username
4
+ attr_reader :password
5
+ attr_reader :local_path
6
+ attr_reader :folders
7
+ attr_reader :server
8
+ attr_reader :connection_options
9
+ attr_reader :changes
10
+ attr_reader :marked_for_deletion
11
+
12
+ def initialize(options)
13
+ @username = options[:username]
14
+ @password = options[:password]
15
+ @local_path = options[:local_path]
16
+ @folders = options[:folders]
17
+ @server = options[:server]
18
+ @connection_options = options[:connection_options]
19
+ @changes = {}
20
+ @marked_for_deletion = false
21
+ end
22
+
23
+ def valid?
24
+ username && password
25
+ end
26
+
27
+ def modified?
28
+ changes.any?
29
+ end
30
+
31
+ def clear_changes!
32
+ @changes = {}
33
+ end
34
+
35
+ def mark_for_deletion!
36
+ @marked_for_deletion = true
37
+ end
38
+
39
+ def marked_for_deletion?
40
+ @marked_for_deletion
41
+ end
42
+
43
+ def to_h
44
+ h = {
45
+ username: @username,
46
+ password: @password,
47
+ }
48
+ h[:local_path] = @local_path if @local_path
49
+ h[:folders] = @folders if @folders
50
+ h[:server] = @server if @server
51
+ h[:connection_options] = @connection_options if @connection_options
52
+ h
53
+ end
54
+
55
+ def username=(value)
56
+ update(:username, value)
57
+ end
58
+
59
+ def password=(value)
60
+ update(:password, value)
61
+ end
62
+
63
+ def local_path=(value)
64
+ update(:local_path, value)
65
+ end
66
+
67
+ def folders=(value)
68
+ raise "folders must be an Array" if !value.is_a?(Array)
69
+ update(:folders, value)
70
+ end
71
+
72
+ def server=(value)
73
+ update(:server, value)
74
+ end
75
+
76
+ def connection_options=(value)
77
+ parsed = JSON.parse(value)
78
+ update(:connection_options, parsed)
79
+ end
80
+
81
+ private
82
+
83
+ def update(field, value)
84
+ if changes[field]
85
+ change = changes[field]
86
+ if change[:from] == value
87
+ changes.delete(field)
88
+ else
89
+ set_field!(field, value)
90
+ end
91
+ else
92
+ set_field!(field, value)
93
+ end
94
+ end
95
+
96
+ def set_field!(field, value)
97
+ key = :"@#{field}"
98
+ current = instance_variable_get(key)
99
+ changes[field] = {from: current, to: value}
100
+ instance_variable_set(key, value)
101
+ end
102
+ end
103
+ end
@@ -148,7 +148,7 @@ module Imap::Backup
148
148
  def default_server(username)
149
149
  provider = Email::Provider.for_address(username)
150
150
 
151
- if provider.is_a?(Email::Provider::Default)
151
+ if provider.is_a?(Email::Provider::Unknown)
152
152
  Kernel.puts "Can't decide provider for email address '#{username}'"
153
153
  return nil
154
154
  end
@@ -3,7 +3,7 @@ module Imap; end
3
3
  module Imap::Backup
4
4
  MAJOR = 4
5
5
  MINOR = 0
6
- REVISION = 4
6
+ REVISION = 5
7
7
  PRE = nil
8
8
  VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
9
9
  end
@@ -1,10 +1,4 @@
1
1
  describe Email::Provider::Default do
2
- describe "#host" do
3
- it "is unset" do
4
- expect(subject.host).to be_nil
5
- end
6
- end
7
-
8
2
  describe "#options" do
9
3
  it "returns options" do
10
4
  expect(subject.options).to be_a(Hash)
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.0.4
4
+ version: 4.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -182,10 +182,12 @@ files:
182
182
  - lib/email/mboxrd/message.rb
183
183
  - lib/email/provider.rb
184
184
  - lib/email/provider/apple_mail.rb
185
- - lib/email/provider/default.rb
185
+ - lib/email/provider/base.rb
186
186
  - lib/email/provider/fastmail.rb
187
187
  - lib/email/provider/gmail.rb
188
+ - lib/email/provider/unknown.rb
188
189
  - lib/imap/backup.rb
190
+ - lib/imap/backup/account.rb
189
191
  - lib/imap/backup/account/connection.rb
190
192
  - lib/imap/backup/account/folder.rb
191
193
  - lib/imap/backup/cli.rb
@@ -239,7 +241,7 @@ files:
239
241
  - spec/support/silence_logging.rb
240
242
  - spec/unit/email/mboxrd/message_spec.rb
241
243
  - spec/unit/email/provider/apple_mail_spec.rb
242
- - spec/unit/email/provider/default_spec.rb
244
+ - spec/unit/email/provider/base_spec.rb
243
245
  - spec/unit/email/provider/fastmail_spec.rb
244
246
  - spec/unit/email/provider/gmail_spec.rb
245
247
  - spec/unit/email/provider_spec.rb
@@ -290,8 +292,8 @@ test_files:
290
292
  - spec/fixtures/connection.yml
291
293
  - spec/unit/email/provider/gmail_spec.rb
292
294
  - spec/unit/email/provider/apple_mail_spec.rb
293
- - spec/unit/email/provider/default_spec.rb
294
295
  - spec/unit/email/provider/fastmail_spec.rb
296
+ - spec/unit/email/provider/base_spec.rb
295
297
  - spec/unit/email/provider_spec.rb
296
298
  - spec/unit/email/mboxrd/message_spec.rb
297
299
  - spec/unit/imap/backup_spec.rb