Skip to content

Commit 34564ad

Browse files
hoffiStefan Hoffmann
authored andcommitted
Implement UID EXPUNGE command
1 parent 174e35c commit 34564ad

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/net/imap.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,15 @@ def expunge
786786
end
787787
end
788788

789+
# Similar to #expunge, but takes a set of unique identifiers as
790+
# argument.
791+
def uid_expunge(set)
792+
synchronize do
793+
send_command("UID EXPUNGE", MessageSet.new(set))
794+
return @responses.delete("EXPUNGE")
795+
end
796+
end
797+
789798
# Sends a SEARCH command to search the mailbox for messages that
790799
# match the given searching criteria, and returns message sequence
791800
# numbers. +keys+ can either be a string holding the entire

test/net/imap/test_imap.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,39 @@ def test_id
775775
end
776776
end
777777

778+
def test_uid_expunge
779+
server = create_tcp_server
780+
port = server.addr[1]
781+
requests = []
782+
start_server do
783+
sock = server.accept
784+
begin
785+
sock.print("* OK test server\r\n")
786+
requests.push(sock.gets)
787+
sock.print("* 1 EXPUNGE\r\n")
788+
sock.print("* 1 EXPUNGE\r\n")
789+
sock.print("* 1 EXPUNGE\r\n")
790+
sock.print("RUBY0001 OK UID EXPUNGE completed\r\n")
791+
sock.gets
792+
sock.print("* BYE terminating connection\r\n")
793+
sock.print("RUBY0002 OK LOGOUT completed\r\n")
794+
ensure
795+
sock.close
796+
server.close
797+
end
798+
end
799+
800+
begin
801+
imap = Net::IMAP.new(server_addr, :port => port)
802+
response = imap.uid_expunge(1000..1003)
803+
assert_equal("RUBY0001 UID EXPUNGE 1000:1003\r\n", requests.pop)
804+
assert_equal(response.length, 3)
805+
imap.logout
806+
ensure
807+
imap.disconnect if imap
808+
end
809+
end
810+
778811
private
779812

780813
def imaps_test

0 commit comments

Comments
 (0)