Skip to content

Commit 34f35ee

Browse files
committed
✨ Add support for UNSELECT extension (RFC3691)
This is needed for IMAP4rev2 #12. Fixes #40.
1 parent 7d07e74 commit 34f35ee

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/net/imap.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,20 @@ def close
796796
send_command("CLOSE")
797797
end
798798

799+
# Sends an {UNSELECT command [IMAP4rev2
800+
# §6.4.2]}[https://www.rfc-editor.org/rfc/rfc9051#section-6.4.2] to free the
801+
# session resources for a mailbox and return to the "_authenticated_" state.
802+
# This is the same as #close, except that <tt>\\Deleted</tt> messages are
803+
# not removed from the mailbox.
804+
#
805+
# ===== Capabilities
806+
#
807+
# The server's capabilities must include +UNSELECT+
808+
# [RFC3691[https://tools.ietf.org/html/rfc3691]].
809+
def unselect
810+
send_command("UNSELECT")
811+
end
812+
799813
# Sends a EXPUNGE command to permanently remove from the currently
800814
# selected mailbox all messages that have the \Deleted flag set.
801815
def expunge

test/net/imap/test_imap.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,27 @@ def test_close
915915
end
916916
end
917917

918+
def test_unselect
919+
requests = Queue.new
920+
port = yields_in_test_server_thread do |sock, gets|
921+
requests.push(gets[])
922+
sock.print("RUBY0001 OK UNSELECT completed\r\n")
923+
requests.push(gets[])
924+
"RUBY0002"
925+
end
926+
begin
927+
imap = Net::IMAP.new(server_addr, :port => port)
928+
resp = imap.unselect
929+
assert_equal(["RUBY0001", "UNSELECT", ""], requests.pop)
930+
assert_equal([Net::IMAP::TaggedResponse, "RUBY0001", "OK"],
931+
[resp.class, resp.tag, resp.name])
932+
imap.logout
933+
assert_equal(["RUBY0002", "LOGOUT", ""], requests.pop)
934+
ensure
935+
imap.disconnect if imap
936+
end
937+
end
938+
918939
private
919940

920941
def imaps_test

0 commit comments

Comments
 (0)