net-imap 0.4.9.1 → 0.5.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/BSDL +22 -0
  3. data/COPYING +56 -0
  4. data/Gemfile +12 -1
  5. data/LICENSE.txt +3 -22
  6. data/README.md +10 -4
  7. data/docs/styles.css +75 -14
  8. data/lib/net/imap/authenticators.rb +2 -2
  9. data/lib/net/imap/command_data.rb +61 -48
  10. data/lib/net/imap/config/attr_accessors.rb +75 -0
  11. data/lib/net/imap/config/attr_inheritance.rb +90 -0
  12. data/lib/net/imap/config/attr_type_coercion.rb +61 -0
  13. data/lib/net/imap/config.rb +470 -0
  14. data/lib/net/imap/data_encoding.rb +4 -4
  15. data/lib/net/imap/data_lite.rb +226 -0
  16. data/lib/net/imap/deprecated_client_options.rb +9 -6
  17. data/lib/net/imap/errors.rb +7 -1
  18. data/lib/net/imap/esearch_result.rb +180 -0
  19. data/lib/net/imap/fetch_data.rb +126 -47
  20. data/lib/net/imap/flags.rb +1 -1
  21. data/lib/net/imap/response_data.rb +126 -239
  22. data/lib/net/imap/response_parser/parser_utils.rb +11 -6
  23. data/lib/net/imap/response_parser.rb +188 -34
  24. data/lib/net/imap/sasl/anonymous_authenticator.rb +3 -3
  25. data/lib/net/imap/sasl/authentication_exchange.rb +52 -20
  26. data/lib/net/imap/sasl/authenticators.rb +8 -4
  27. data/lib/net/imap/sasl/client_adapter.rb +77 -26
  28. data/lib/net/imap/sasl/cram_md5_authenticator.rb +4 -4
  29. data/lib/net/imap/sasl/digest_md5_authenticator.rb +218 -56
  30. data/lib/net/imap/sasl/external_authenticator.rb +3 -3
  31. data/lib/net/imap/sasl/gs2_header.rb +7 -7
  32. data/lib/net/imap/sasl/login_authenticator.rb +4 -3
  33. data/lib/net/imap/sasl/oauthbearer_authenticator.rb +6 -6
  34. data/lib/net/imap/sasl/plain_authenticator.rb +7 -7
  35. data/lib/net/imap/sasl/protocol_adapters.rb +60 -4
  36. data/lib/net/imap/sasl/scram_authenticator.rb +8 -8
  37. data/lib/net/imap/sasl.rb +8 -5
  38. data/lib/net/imap/sasl_adapter.rb +0 -1
  39. data/lib/net/imap/search_result.rb +4 -8
  40. data/lib/net/imap/sequence_set.rb +239 -88
  41. data/lib/net/imap/stringprep/nameprep.rb +1 -1
  42. data/lib/net/imap/stringprep/trace.rb +4 -4
  43. data/lib/net/imap/uidplus_data.rb +244 -0
  44. data/lib/net/imap/vanished_data.rb +56 -0
  45. data/lib/net/imap.rb +1012 -322
  46. data/net-imap.gemspec +4 -7
  47. data/rakelib/benchmarks.rake +1 -1
  48. data/rakelib/rfcs.rake +2 -0
  49. data/rakelib/string_prep_tables_generator.rb +2 -0
  50. data/sample/net-imap.rb +167 -0
  51. metadata +16 -40
  52. data/.github/dependabot.yml +0 -6
  53. data/.github/workflows/pages.yml +0 -46
  54. data/.github/workflows/test.yml +0 -31
  55. data/.gitignore +0 -12
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Authenticator for the "+PLAIN+" SASL mechanism, specified in
4
- # RFC-4616[https://tools.ietf.org/html/rfc4616]. See Net::IMAP#authenticate.
4
+ # RFC-4616[https://www.rfc-editor.org/rfc/rfc4616]. See Net::IMAP#authenticate.
5
5
  #
6
6
  # +PLAIN+ authentication sends the password in cleartext.
7
- # RFC-3501[https://tools.ietf.org/html/rfc3501] encourages servers to disable
7
+ # RFC-3501[https://www.rfc-editor.org/rfc/rfc3501] encourages servers to disable
8
8
  # cleartext authentication until after TLS has been negotiated.
9
- # RFC-8314[https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
9
+ # RFC-8314[https://www.rfc-editor.org/rfc/rfc8314] recommends TLS version 1.2 or
10
10
  # greater be used for all traffic, and deprecate cleartext access ASAP. +PLAIN+
11
11
  # can be secured by TLS encryption.
12
12
  class Net::IMAP::SASL::PlainAuthenticator
@@ -16,11 +16,11 @@ class Net::IMAP::SASL::PlainAuthenticator
16
16
 
17
17
  # Authentication identity: the identity that matches the #password.
18
18
  #
19
- # RFC-2831[https://tools.ietf.org/html/rfc2831] uses the term +username+.
19
+ # RFC-2831[https://www.rfc-editor.org/rfc/rfc2831] uses the term +username+.
20
20
  # "Authentication identity" is the generic term used by
21
- # RFC-4422[https://tools.ietf.org/html/rfc4422].
22
- # RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
23
- # this to +authcid+.
21
+ # RFC-4422[https://www.rfc-editor.org/rfc/rfc4422].
22
+ # RFC-4616[https://www.rfc-editor.org/rfc/rfc4616] and many later RFCs
23
+ # abbreviate this to +authcid+.
24
24
  attr_reader :username
25
25
  alias authcid username
26
26
 
@@ -4,16 +4,72 @@ module Net
4
4
  class IMAP
5
5
  module SASL
6
6
 
7
+ # SASL::ProtocolAdapters modules are meant to be used as mixins for
8
+ # SASL::ClientAdapter and its subclasses. Where the client adapter must
9
+ # be customized for each client library, the protocol adapter mixin
10
+ # handles \SASL requirements that are part of the protocol specification,
11
+ # but not specific to any particular client library. In particular, see
12
+ # {RFC4422 §4}[https://www.rfc-editor.org/rfc/rfc4422.html#section-4]
13
+ #
14
+ # === Interface
15
+ #
16
+ # >>>
17
+ # NOTE: This API is experimental, and may change.
18
+ #
19
+ # - {#command_name}[rdoc-ref:Generic#command_name] -- The name of the
20
+ # command used to to initiate an authentication exchange.
21
+ # - {#service}[rdoc-ref:Generic#service] -- The GSSAPI service name.
22
+ # - {#encode_ir}[rdoc-ref:Generic#encode_ir]--Encodes an initial response.
23
+ # - {#decode}[rdoc-ref:Generic#decode] -- Decodes a server challenge.
24
+ # - {#encode}[rdoc-ref:Generic#encode] -- Encodes a client response.
25
+ # - {#cancel_response}[rdoc-ref:Generic#cancel_response] -- The encoded
26
+ # client response used to cancel an authentication exchange.
27
+ #
28
+ # Other protocol requirements of the \SASL authentication exchange are
29
+ # handled by SASL::ClientAdapter.
30
+ #
31
+ # === Included protocol adapters
32
+ #
33
+ # - Generic -- a basic implementation of all of the methods listed above.
34
+ # - IMAP -- An adapter for the IMAP4 protocol.
35
+ # - SMTP -- An adapter for the \SMTP protocol with the +AUTH+ capability.
36
+ # - POP -- An adapter for the POP3 protocol with the +SASL+ capability.
7
37
  module ProtocolAdapters
8
- # This API is experimental, and may change.
38
+ # See SASL::ProtocolAdapters@Interface.
9
39
  module Generic
40
+ # The name of the protocol command used to initiate a \SASL
41
+ # authentication exchange.
42
+ #
43
+ # The generic implementation returns <tt>"AUTHENTICATE"</tt>.
10
44
  def command_name; "AUTHENTICATE" end
11
- def service; raise "Implement in subclass or module" end
12
- def host; client.host end
13
- def port; client.port end
45
+
46
+ # A service name from the {GSSAPI/Kerberos/SASL Service Names
47
+ # registry}[https://www.iana.org/assignments/gssapi-service-names/gssapi-service-names.xhtml].
48
+ #
49
+ # The generic implementation returns <tt>"host"</tt>, which is the
50
+ # generic GSSAPI host-based service name.
51
+ def service; "host" end
52
+
53
+ # Encodes an initial response string.
54
+ #
55
+ # The generic implementation returns the result of #encode, or returns
56
+ # <tt>"="</tt> when +string+ is empty.
14
57
  def encode_ir(string) string.empty? ? "=" : encode(string) end
58
+
59
+ # Encodes a client response string.
60
+ #
61
+ # The generic implementation returns the Base64 encoding of +string+.
15
62
  def encode(string) [string].pack("m0") end
63
+
64
+ # Decodes a server challenge string.
65
+ #
66
+ # The generic implementation returns the Base64 decoding of +string+.
16
67
  def decode(string) string.unpack1("m0") end
68
+
69
+ # Returns the message used by the client to abort an authentication
70
+ # exchange.
71
+ #
72
+ # The generic implementation returns <tt>"*"</tt>.
17
73
  def cancel_response; "*" end
18
74
  end
19
75
 
@@ -11,7 +11,7 @@ module Net
11
11
  module SASL
12
12
 
13
13
  # Abstract base class for the "+SCRAM-*+" family of SASL mechanisms,
14
- # defined in RFC5802[https://tools.ietf.org/html/rfc5802]. Use via
14
+ # defined in RFC5802[https://www.rfc-editor.org/rfc/rfc5802]. Use via
15
15
  # Net::IMAP#authenticate.
16
16
  #
17
17
  # Directly supported:
@@ -99,11 +99,11 @@ module Net
99
99
 
100
100
  # Authentication identity: the identity that matches the #password.
101
101
  #
102
- # RFC-2831[https://tools.ietf.org/html/rfc2831] uses the term +username+.
103
- # "Authentication identity" is the generic term used by
104
- # RFC-4422[https://tools.ietf.org/html/rfc4422].
105
- # RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
106
- # this to +authcid+.
102
+ # RFC-2831[https://www.rfc-editor.org/rfc/rfc2831] uses the term
103
+ # +username+. "Authentication identity" is the generic term used by
104
+ # RFC-4422[https://www.rfc-editor.org/rfc/rfc4422].
105
+ # RFC-4616[https://www.rfc-editor.org/rfc/rfc4616] and many later RFCs
106
+ # abbreviate this to +authcid+.
107
107
  attr_reader :username
108
108
  alias authcid username
109
109
 
@@ -263,7 +263,7 @@ module Net
263
263
  end
264
264
 
265
265
  # Authenticator for the "+SCRAM-SHA-1+" SASL mechanism, defined in
266
- # RFC5802[https://tools.ietf.org/html/rfc5802].
266
+ # RFC5802[https://www.rfc-editor.org/rfc/rfc5802].
267
267
  #
268
268
  # Uses the "SHA-1" digest algorithm from OpenSSL::Digest.
269
269
  #
@@ -273,7 +273,7 @@ module Net
273
273
  end
274
274
 
275
275
  # Authenticator for the "+SCRAM-SHA-256+" SASL mechanism, defined in
276
- # RFC7677[https://tools.ietf.org/html/rfc7677].
276
+ # RFC7677[https://www.rfc-editor.org/rfc/rfc7677].
277
277
  #
278
278
  # Uses the "SHA-256" digest algorithm from OpenSSL::Digest.
279
279
  #
data/lib/net/imap/sasl.rb CHANGED
@@ -5,7 +5,7 @@ module Net
5
5
 
6
6
  # Pluggable authentication mechanisms for protocols which support SASL
7
7
  # (Simple Authentication and Security Layer), such as IMAP4, SMTP, LDAP, and
8
- # XMPP. {RFC-4422}[https://tools.ietf.org/html/rfc4422] specifies the
8
+ # XMPP. {RFC-4422}[https://www.rfc-editor.org/rfc/rfc4422] specifies the
9
9
  # common \SASL framework:
10
10
  # >>>
11
11
  # SASL is conceptually a framework that provides an abstraction layer
@@ -37,7 +37,7 @@ module Net
37
37
  # See ExternalAuthenticator.
38
38
  #
39
39
  # Authenticates using already established credentials, such as a TLS
40
- # certificate or IPsec.
40
+ # certificate or IPSec.
41
41
  #
42
42
  # +OAUTHBEARER+::
43
43
  # See OAuthBearerAuthenticator.
@@ -114,8 +114,8 @@ module Net
114
114
  # messages has not passed integrity checks.
115
115
  AuthenticationFailed = Class.new(Error)
116
116
 
117
- # Indicates that authentication cannot proceed because one of the server's
118
- # ended authentication prematurely.
117
+ # Indicates that authentication cannot proceed because the server ended
118
+ # authentication prematurely.
119
119
  class AuthenticationIncomplete < AuthenticationFailed
120
120
  # The success response from the server
121
121
  attr_reader :response
@@ -159,7 +159,10 @@ module Net
159
159
  # Returns the default global SASL::Authenticators instance.
160
160
  def self.authenticators; @authenticators ||= Authenticators.new end
161
161
 
162
- # Delegates to <tt>registry.new</tt> See Authenticators#new.
162
+ # Creates a new SASL authenticator, using SASL::Authenticators#new.
163
+ #
164
+ # +registry+ defaults to SASL.authenticators. All other arguments are
165
+ # forwarded to to <tt>registry.new</tt>.
163
166
  def self.authenticator(*args, registry: authenticators, **kwargs, &block)
164
167
  registry.new(*args, **kwargs, &block)
165
168
  end
@@ -12,7 +12,6 @@ module Net
12
12
 
13
13
  def response_errors; RESPONSE_ERRORS end
14
14
  def sasl_ir_capable?; client.capable?("SASL-IR") end
15
- def auth_capable?(mechanism); client.auth_capable?(mechanism) end
16
15
  def drop_connection; client.logout! end
17
16
  def drop_connection!; client.disconnect end
18
17
  end
@@ -9,7 +9,7 @@ module Net
9
9
  # For backward compatibility, SearchResult inherits from Array.
10
10
  class SearchResult < Array
11
11
 
12
- # Returns a frozen SearchResult populated with the given +seq_nums+.
12
+ # Returns a SearchResult populated with the given +seq_nums+.
13
13
  #
14
14
  # Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
15
15
  # # => Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
@@ -22,19 +22,15 @@ module Net
22
22
  # §3.1.6]}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.1.6].
23
23
  attr_reader :modseq
24
24
 
25
- # Returns a frozen SearchResult populated with the given +seq_nums+.
25
+ # Returns a SearchResult populated with the given +seq_nums+.
26
26
  #
27
27
  # Net::IMAP::SearchResult.new([1, 3, 5], modseq: 9)
28
28
  # # => Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
29
29
  def initialize(seq_nums, modseq: nil)
30
30
  super(seq_nums.to_ary.map { Integer _1 })
31
31
  @modseq = Integer modseq if modseq
32
- freeze
33
32
  end
34
33
 
35
- # Returns a frozen copy of +other+.
36
- def initialize_copy(other); super; freeze end
37
-
38
34
  # Returns whether +other+ is a SearchResult with the same values and the
39
35
  # same #modseq. The order of numbers is irrelevant.
40
36
  #
@@ -104,10 +100,10 @@ module Net
104
100
  # data.to_s("SORT") # => "* SORT 2 8 32 128 256 512"
105
101
  # data.to_s(nil) # => "2 8 32 128 256 512"
106
102
  #
107
- # data = Net::IMAP::SearchResult[1, 3, 16, 1024, modseq: 2048].to_s
103
+ # data = Net::IMAP::SearchResult[1, 3, 16, 1024, modseq: 2048]
108
104
  # data.to_s # => "* SEARCH 1 3 16 1024 (MODSEQ 2048)"
109
105
  # data.to_s("SORT") # => "* SORT 1 3 16 1024 (MODSEQ 2048)"
110
- # data.to_s # => "1 3 16 1024 (MODSEQ 2048)"
106
+ # data.to_s(nil) # => "1 3 16 1024 (MODSEQ 2048)"
111
107
  #
112
108
  def to_s(type = "SEARCH")
113
109
  str = +""