Skip to content

Commit

Permalink
🎨 Move response handlers after IMAP commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Dec 19, 2022
1 parent f12ea3b commit fdf2b7d
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1850,28 +1850,6 @@ def uid_sort(sort_keys, search_keys, charset)
return sort_internal("UID SORT", sort_keys, search_keys, charset)
end

# Adds a response handler. For example, to detect when
# the server sends a new EXISTS response (which normally
# indicates new messages being added to the mailbox),
# add the following handler after selecting the
# mailbox:
#
# imap.add_response_handler { |resp|
# if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
# puts "Mailbox now has #{resp.data} messages"
# end
# }
#
def add_response_handler(handler = nil, &block)
raise ArgumentError, "two Procs are passed" if handler && block
@response_handlers.push(block || handler)
end

# Removes the response handler.
def remove_response_handler(handler)
@response_handlers.delete(handler)
end

# Sends a {THREAD command [RFC5256 §3]}[https://www.rfc-editor.org/rfc/rfc5256#section-3]
# to search a mailbox and return message sequence numbers in threaded
# format, as a ThreadMember tree. +search_keys+ are interpreted the same as
Expand Down Expand Up @@ -1975,6 +1953,28 @@ def idle_done
end
end

# Adds a response handler. For example, to detect when
# the server sends a new EXISTS response (which normally
# indicates new messages being added to the mailbox),
# add the following handler after selecting the
# mailbox:
#
# imap.add_response_handler { |resp|
# if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
# puts "Mailbox now has #{resp.data} messages"
# end
# }
#
def add_response_handler(handler = nil, &block)
raise ArgumentError, "two Procs are passed" if handler && block
@response_handlers.push(block || handler)
end

# Removes the response handler.
def remove_response_handler(handler)
@response_handlers.delete(handler)
end

private

CRLF = "\r\n" # :nodoc:
Expand Down

0 comments on commit fdf2b7d

Please sign in to comment.