net-imap 0.4.1 → 0.4.4

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.

Potentially problematic release.


This version of net-imap might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bba73e8db611b37b7c5b9be540d99c2288e9188e7f12620259862b30db47815
4
- data.tar.gz: fde1bcda99236beafea397d36768fb9fe185ec20ca2cd5d9c991b48cfdf51bd3
3
+ metadata.gz: da8cb634d9ee1613035c81a25d28ae9f36b3d0985bcb61da9a38aacb87854a5f
4
+ data.tar.gz: e504b145415da3a025c6f4ab973b212764c75ef4214d0fed485fdb0b17e83752
5
5
  SHA512:
6
- metadata.gz: 6ee43fab9eaea8c870940e0cc625e3223722e4b722e1055da6f3629707aaf12e580143139abb97ae1294757a99db977428c8aa23bc57d8e9a23ff9ab5eb695cf
7
- data.tar.gz: 67a965fdd6b4af0480917241a8efad57c3356c82ec975bcc10373242e477718a1751e78cc9f0e51286b553e6222c26cddca119dbaa9dfef855c9611de6a55a64
6
+ metadata.gz: 0cef39a5ac6454ded84c395fb2671df678e17611d7eff42665113c21f955ebcb6ffdf9035dd1e6fdb3de38aa38f43431537ded3d484ffba7d699b478bb8c3e1e
7
+ data.tar.gz: 23f777092b2940b725685285a6372b56744a9968fcc76872ebf9ef3136fb3665a89a85174dc34636e547b90d8d3a1945627ce79390f10122aadb57b57004f789
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /Gemfile.lock
11
+ benchmarks/Gemfile*
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gem "rake"
8
8
  gem "rdoc"
9
9
  gem "test-unit"
10
10
  gem "test-unit-ruby-core", git: "https://github.com/ruby/test-unit-ruby-core"
11
+
12
+ gem "benchmark-driver"
@@ -47,7 +47,27 @@ module Net
47
47
  class ByeResponseError < ResponseError
48
48
  end
49
49
 
50
+ # Error raised when the server sends an invalid response.
51
+ #
52
+ # This is different from UnknownResponseError: the response has been
53
+ # rejected. Although it may be parsable, the server is forbidden from
54
+ # sending it in the current context. The client should automatically
55
+ # disconnect, abruptly (without logout).
56
+ #
57
+ # Note that InvalidResponseError does not inherit from ResponseError: it
58
+ # can be raised before the response is fully parsed. A related
59
+ # ResponseParseError or ResponseError may be the #cause.
60
+ class InvalidResponseError < Error
61
+ end
62
+
50
63
  # Error raised upon an unknown response from the server.
64
+ #
65
+ # This is different from InvalidResponseError: the response may be a
66
+ # valid extension response and the server may be allowed to send it in
67
+ # this context, but Net::IMAP either does not know how to parse it or
68
+ # how to handle it. This could result from enabling unknown or
69
+ # unhandled extensions. The connection may still be usable,
70
+ # but—depending on context—it may be prudent to disconnect.
51
71
  class UnknownResponseError < ResponseError
52
72
  end
53
73
 
@@ -55,17 +55,54 @@ module Net
55
55
 
56
56
  # Net::IMAP::IgnoredResponse represents intentionally ignored responses.
57
57
  #
58
- # This includes untagged response "NOOP" sent by eg. Zimbra to avoid some
59
- # clients to close the connection.
58
+ # This includes untagged response "NOOP" sent by eg. Zimbra to avoid
59
+ # some clients to close the connection.
60
60
  #
61
61
  # It matches no IMAP standard.
62
+ class IgnoredResponse < UntaggedResponse
63
+ end
64
+
65
+ # **Note:** This represents an intentionally _unstable_ API. Where
66
+ # instances of this class are returned, future releases may return a
67
+ # different (incompatible) object <em>without deprecation or warning</em>.
68
+ #
69
+ # Net::IMAP::UnparsedData represents data for unknown response types or
70
+ # unknown extensions to response types without a well-defined extension
71
+ # grammar.
62
72
  #
63
- class IgnoredResponse < Struct.new(:raw_data)
73
+ # See also: UnparsedNumericResponseData
74
+ class UnparsedData < Struct.new(:unparsed_data)
64
75
  ##
65
- # method: raw_data
66
- # :call-seq: raw_data -> string
76
+ # method: unparsed_data
77
+ # :call-seq: unparsed_data -> string
67
78
  #
68
- # The raw response data.
79
+ # The unparsed data
80
+ end
81
+
82
+ # **Note:** This represents an intentionally _unstable_ API. Where
83
+ # instances of this class are returned, future releases may return a
84
+ # different (incompatible) object <em>without deprecation or warning</em>.
85
+ #
86
+ # Net::IMAP::UnparsedNumericResponseData represents data for unhandled
87
+ # response types with a numeric prefix. See the documentation for #number.
88
+ #
89
+ # See also: UnparsedData
90
+ class UnparsedNumericResponseData < Struct.new(:number, :unparsed_data)
91
+ ##
92
+ # method: number
93
+ # :call-seq: number -> integer
94
+ #
95
+ # Returns a numeric response data prefix, when available.
96
+ #
97
+ # Many response types are prefixed with a non-negative #number. For
98
+ # message data, #number may represent a sequence number or a UID. For
99
+ # mailbox data, #number may represent a message count.
100
+
101
+ ##
102
+ # method: unparsed_data
103
+ # :call-seq: unparsed_data -> string
104
+ #
105
+ # The unparsed data, not including #number or UntaggedResponse#name.
69
106
  end
70
107
 
71
108
  # Net::IMAP::TaggedResponse represents tagged responses.
@@ -108,6 +145,9 @@ module Net
108
145
  # UntaggedResponse#data when the response type is a "condition" ("OK", "NO",
109
146
  # "BAD", "PREAUTH", or "BYE").
110
147
  class ResponseText < Struct.new(:code, :text)
148
+ # Used to avoid an allocation when ResponseText is empty
149
+ EMPTY = new(nil, "").freeze
150
+
111
151
  ##
112
152
  # method: code
113
153
  # :call-seq: code -> ResponseCode or nil
@@ -15,6 +15,7 @@ module Net
15
15
 
16
16
  # we can skip lexer for single character matches, as a shortcut
17
17
  def def_char_matchers(name, char, token)
18
+ byte = char.ord
18
19
  match_name = name.match(/\A[A-Z]/) ? "#{name}!" : name
19
20
  char = char.dump
20
21
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
@@ -27,7 +28,7 @@ module Net
27
28
 
28
29
  # use token or string peek
29
30
  def peek_#{name}?
30
- @token ? @token.symbol == #{token} : @str[@pos] == #{char}
31
+ @token ? @token.symbol == #{token} : @str.getbyte(@pos) == #{byte}
31
32
  end
32
33
 
33
34
  # like accept(token_symbols); returns token or nil
@@ -35,7 +36,7 @@ module Net
35
36
  if @token&.symbol == #{token}
36
37
  #{SHIFT_TOKEN}
37
38
  #{char}
38
- elsif !@token && @str[@pos] == #{char}
39
+ elsif !@token && @str.getbyte(@pos) == #{byte}
39
40
  @pos += 1
40
41
  #{char}
41
42
  end
@@ -46,7 +47,7 @@ module Net
46
47
  if @token&.symbol == #{token}
47
48
  #{SHIFT_TOKEN}
48
49
  #{char}
49
- elsif !@token && @str[@pos] == #{char}
50
+ elsif !@token && @str.getbyte(@pos) == #{byte}
50
51
  @pos += 1
51
52
  #{char}
52
53
  else
@@ -109,7 +110,6 @@ module Net
109
110
  end
110
111
  end
111
112
  RUBY
112
-
113
113
  end
114
114
 
115
115
  end
@@ -170,6 +170,16 @@ module Net
170
170
  @token ||= next_token
171
171
  end
172
172
 
173
+ # like match, without consuming the token
174
+ def lookahead!(*args)
175
+ if args.include?((@token ||= next_token)&.symbol)
176
+ @token
177
+ else
178
+ parse_error('unexpected token %s (expected %s)',
179
+ @token&.symbol, args.join(" or "))
180
+ end
181
+ end
182
+
173
183
  def peek_str?(str)
174
184
  assert_no_lookahead if Net::IMAP.debug
175
185
  @str[@pos, str.length] == str