Exception: Net::IMAP::InvalidTaggedResponseError

Inherits:
InvalidResponseError show all
Defined in:
lib/net/imap/errors.rb

Overview

Error raised when the server sends a tagged #response that is invalid for the #command #state.

This could be caused by a bug in the server or in Net::IMAP. Or it might indicate a malicious server, a man-in-the-middle attack, or client-side command injection, so the client should disconnect automatically and abruptly (without logout).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, response:, command: nil) ⇒ InvalidTaggedResponseError

Returns a new instance of InvalidTaggedResponseError.



333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/net/imap/errors.rb', line 333

def initialize(state, response:, command: nil)
  response => TaggedResponse[tag:, name: status]
  case [state, status, command]
  in :unknown,                _,    nil
  in :incomplete,             "OK", {tag: ^tag, name:}
  in :unstarted | :completed, _,    {tag: ^tag, name:}
  end
  @state, @command, @response = state, command, response
  cmd_desc = name ? "#{state} #{name}" : state
  super "Received tagged #{status} to #{cmd_desc} command (tag=#{tag})"
rescue NoMatchingPatternError => err
  raise ArgumentError, err.message
end

Instance Attribute Details

#commandObject (readonly)

Metadata about the matching IMAP command.

Returns nil when #state is :unknown.

NOTE: The non-nil return type is an unstable API, for debug only. It may be changed by any release, without warning or deprecation.



328
329
330
# File 'lib/net/imap/errors.rb', line 328

def command
  @command
end

#responseObject (readonly)

The TaggedResponse which triggered this error



331
332
333
# File 'lib/net/imap/errors.rb', line 331

def response
  @response
end

#stateObject (readonly)

A symbol representing the state of the matching tagged command.

:unknown::

#response does not match any known command (#command will be +nil+).

:unstarted::

Any tagged #response is invalid before #command starts sending.

:incomplete::

A tagged +OK+ #response is invalid before #command is fully sent.

:completed::

Multiple tagged responses were received for the same command.

NOTE: Command state is neither anticipated nor remembered indefinitely. :unknown is used before the matching command is called and after the it is forgotten.

NOTE: This version of Net::IMAP does not detect or raise an exception for all of these states.



320
321
322
# File 'lib/net/imap/errors.rb', line 320

def state
  @state
end

Instance Method Details

#detailed_messageObject



347
348
349
350
351
352
353
# File 'lib/net/imap/errors.rb', line 347

def detailed_message(**)
  "#{message}.\n" \
    "Disconnecting: This could indicate a malicious server, a " \
    "man-in-the-middle attack, a client-side command injection, or " \
    "a bug in net-imap.\n" \
    "response.data=#{response.data.inspect}"
end