imap.rb 0.9.0 → 0.10.0

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: a11cb6eb95eff27b2d107a0e1ad8fc727b1eabb6d2c24523ada41b3906b9d42e
4
- data.tar.gz: 5a37e2eff7d0177f768aeb77182f04dd47d7686cdbd42f99814c35a140e4d270
3
+ metadata.gz: 68b300810859bc9e1aad02afe6eb9ae614581c114c05b175e59bffea2e94b4cd
4
+ data.tar.gz: fd607d6ddca5bf9f9993f5fcc29a56c658671ada38d056c9bb9f6ce0c65d3968
5
5
  SHA512:
6
- metadata.gz: 8a22fc1e24e9c7765d06733837547a29f581083586b0e9fdef601756ee1d61561b44689cb7dcf5ed62f3db8fc2096ac295ac8859fc765de30fd1135123a9aac6
7
- data.tar.gz: 22a69f98811483319992902f342267743bbb69acac1723b1dc8067a54f9805e8965d91925a289cfd376eac22fff3d8ec333125f4f8733cf05debd9025ad38843
6
+ metadata.gz: 4864d678e3d41d3ad94a001ebb08460c1f93d2441c5eeea117fffc859609de853ee6e833cb1fb46f285b5a9b3f13427e04b483754fbd00504cb71d6ef38f54fd
7
+ data.tar.gz: 87db28691770c3bd7885866e25f5507f86785b9accf9689099cc3423ef8f82873e9be8a86145c53084566ef49565776e18d5337e683d71189e35a12a21e0f540
data/CHANGELOG CHANGED
@@ -1,5 +1,16 @@
1
1
  # imap/CHANGELOG
2
2
 
3
+ ## 20260919
4
+
5
+ 0.10.0: ~ Imap.setup: + Imap::LoginFailed; ~ the gemspecs: /'~> 0.4'/'>= 0.4.5'/ upon net-imap. Imap.setup ignored the false which Imap#login returns when the server rejects the password, and handed back a client which was connected but not logged in.
6
+
7
+ 1. + Imap::LoginFailed
8
+ 2. + login!(): raises where the server rejects the password, and where only one of the username and the password is given.
9
+ 3. ~ Imap.setup: login!() for #login, and /&&/||/ upon the credentials.
10
+ 4. ~ imap.gemspec, imap.rb.gemspec: /'~> 0.4'/'>= 0.4.5'/ upon net-imap. FetchData#uid, #flags, #internaldate, #bodystructure and #message are absent in 0.4.0 and present in 0.4.5, and 0.7.0 reads all five. No ceiling, nothing being known to break at 1.0.
11
+ 5. + 4 tests: .setup upon a rejection, that it does not go on to select, a half-given pair, and neither given.
12
+ 6. ~ Imap::VERSION: /0.9.0/0.10.0/
13
+
3
14
  ## 20260917
4
15
 
5
16
  0.9.0: + all_of and ALL
data/imap.rb.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.required_ruby_version = '>= 2.7'
29
29
 
30
30
  spec.dependencies = [
31
- ['net-imap', '~> 0.4']
31
+ ['net-imap', '>= 0.4.5']
32
32
  ]
33
33
 
34
34
  spec.development_dependencies = [
data/lib/Imap/VERSION.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Imap
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
data/lib/imap.rb CHANGED
@@ -6,18 +6,31 @@ require_relative './Imap/Message'
6
6
  require_relative './Imap/VERSION'
7
7
 
8
8
  class Imap
9
+ class LoginFailed < StandardError; end
10
+
9
11
  class << self
10
12
 
11
13
  def setup(config)
12
14
  raise ArgumentError, "Server must be specified" unless config[:server]
13
15
  imap_client = Imap.new(**config)
14
- if config[:username] && config[:password]
15
- imap_client.login(username: config[:username], password: config[:password])
16
+ login!(imap_client, config) if config[:username] || config[:password]
17
+ imap_client.mailbox = config[:mailbox] if config[:mailbox]
18
+ imap_client
19
+ end
20
+
21
+ private
22
+
23
+ # A half-given pair is a mistake rather than a reason not to log in, and a
24
+ # refusal is not something to carry on from: what follows is a connection
25
+ # which answers BAD to whatever is asked of it, several commands away from
26
+ # the fault.
27
+ def login!(imap_client, config)
28
+ unless config[:username] && config[:password]
29
+ raise LoginFailed, "#{config[:server]} wants both a username and a password; only the #{config[:username] ? 'username' : 'password'} was given"
16
30
  end
17
- if config[:mailbox]
18
- imap_client.mailbox = config[:mailbox]
31
+ unless imap_client.login(username: config[:username], password: config[:password])
32
+ raise LoginFailed, "#{config[:server]} refused #{config[:username]}"
19
33
  end
20
- imap_client
21
34
  end
22
35
 
23
36
  end # class << self
data/test/Imap_test.rb CHANGED
@@ -36,6 +36,47 @@ describe Imap do
36
36
  end
37
37
  end
38
38
 
39
+ describe ".setup, upon a login which does not take" do
40
+ def refusing_mock
41
+ mock = MockIMAP.new('imap.example.com', ssl: true)
42
+ def mock.login(username, password)
43
+ raise Net::IMAP::NoResponseError, OpenStruct.new(data: OpenStruct.new(text: 'Authentication failed'))
44
+ end
45
+ mock
46
+ end
47
+
48
+ it 'raises rather than handing back a connection which is not logged in' do
49
+ Net::IMAP.stub(:new, refusing_mock) do
50
+ error = _(proc{Imap.setup(server: 'imap.example.com', username: 'user', password: 'wrong')}).must_raise(Imap::LoginFailed)
51
+ _(error.message).must_equal 'imap.example.com refused user'
52
+ end
53
+ end
54
+
55
+ it 'does not go on to select a mailbox' do
56
+ mock = refusing_mock
57
+ Net::IMAP.stub(:new, mock) do
58
+ _(proc{Imap.setup(server: 'imap.example.com', username: 'user', password: 'wrong', mailbox: 'INBOX')}).must_raise(Imap::LoginFailed)
59
+ end
60
+ _(mock.select_called).must_equal false
61
+ end
62
+
63
+ it 'raises where only one of the pair is given, rather than skipping the login' do
64
+ Net::IMAP.stub(:new, MockIMAP.new('imap.example.com', ssl: true)) do
65
+ error = _(proc{Imap.setup(server: 'imap.example.com', username: 'user')}).must_raise(Imap::LoginFailed)
66
+ _(error.message).must_match(/only the username was given/)
67
+ _(proc{Imap.setup(server: 'imap.example.com', password: 'secret')}).must_raise(Imap::LoginFailed)
68
+ end
69
+ end
70
+
71
+ it 'does not log in at all where neither is given' do
72
+ mock = MockIMAP.new('imap.example.com', ssl: true)
73
+ Net::IMAP.stub(:new, mock) do
74
+ _(Imap.setup(server: 'imap.example.com')).must_be_instance_of Imap
75
+ end
76
+ _(mock.login_called).must_equal false
77
+ end
78
+ end
79
+
39
80
  describe "#login" do
40
81
  it 'returns true on successful login' do
41
82
  Net::IMAP.stub(:new, MockIMAP.new('imap.example.com', ssl: true)) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: net-imap
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '0.4'
18
+ version: 0.4.5
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - "~>"
23
+ - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '0.4'
25
+ version: 0.4.5
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: minitest
28
28
  requirement: !ruby/object:Gem::Requirement