Skip to content

Commit 6aaf660

Browse files
committed
🎨 Move response handlers after IMAP commands
1 parent f46d40a commit 6aaf660

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

lib/net/imap.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,28 +1850,6 @@ def uid_sort(sort_keys, search_keys, charset)
18501850
return sort_internal("UID SORT", sort_keys, search_keys, charset)
18511851
end
18521852

1853-
# Adds a response handler. For example, to detect when
1854-
# the server sends a new EXISTS response (which normally
1855-
# indicates new messages being added to the mailbox),
1856-
# add the following handler after selecting the
1857-
# mailbox:
1858-
#
1859-
# imap.add_response_handler { |resp|
1860-
# if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
1861-
# puts "Mailbox now has #{resp.data} messages"
1862-
# end
1863-
# }
1864-
#
1865-
def add_response_handler(handler = nil, &block)
1866-
raise ArgumentError, "two Procs are passed" if handler && block
1867-
@response_handlers.push(block || handler)
1868-
end
1869-
1870-
# Removes the response handler.
1871-
def remove_response_handler(handler)
1872-
@response_handlers.delete(handler)
1873-
end
1874-
18751853
# Sends a {THREAD command [RFC5256 §3]}[https://www.rfc-editor.org/rfc/rfc5256#section-3]
18761854
# to search a mailbox and return message sequence numbers in threaded
18771855
# format, as a ThreadMember tree. +search_keys+ are interpreted the same as
@@ -1975,6 +1953,28 @@ def idle_done
19751953
end
19761954
end
19771955

1956+
# Adds a response handler. For example, to detect when
1957+
# the server sends a new EXISTS response (which normally
1958+
# indicates new messages being added to the mailbox),
1959+
# add the following handler after selecting the
1960+
# mailbox:
1961+
#
1962+
# imap.add_response_handler { |resp|
1963+
# if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
1964+
# puts "Mailbox now has #{resp.data} messages"
1965+
# end
1966+
# }
1967+
#
1968+
def add_response_handler(handler = nil, &block)
1969+
raise ArgumentError, "two Procs are passed" if handler && block
1970+
@response_handlers.push(block || handler)
1971+
end
1972+
1973+
# Removes the response handler.
1974+
def remove_response_handler(handler)
1975+
@response_handlers.delete(handler)
1976+
end
1977+
19781978
private
19791979

19801980
CRLF = "\r\n" # :nodoc:

0 commit comments

Comments
 (0)