Permalink
Browse files

Fix UID SEARCH.

Previous implementation was carelessly written and untested.
  • Loading branch information...
1 parent 728f3bb commit 96cf2e9ea172e65fd256e0227906c55799463a81 @ConradIrwin committed Apr 3, 2012
Showing with 17 additions and 7 deletions.
  1. +1 −1 em-imap.gemspec
  2. +5 −4 lib/em-imap/client.rb
  3. +11 −2 spec/client_spec.rb
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |gem|
gem.name = 'em-imap'
- gem.version = '0.2.1'
+ gem.version = '0.2.2'
gem.summary = 'An EventMachine based IMAP client.'
gem.description = "Allows you to connect to an IMAP4rev1 server in a non-blocking fashion."
View
@@ -257,13 +257,13 @@ def expunge
# @succeed A list of message sequence numbers.
#
def search(*args)
- search_internal(["SEARCH"], *args)
+ search_internal("SEARCH", *args)
end
# The same as search, but succeeding with a list of UIDs not sequence numbers.
#
def uid_search(*args)
- search_internal(["UID", "SEARCH"], *args)
+ search_internal("UID SEARCH", *args)
end
# SORT and THREAD (like SEARCH) from http://tools.ietf.org/search/rfc5256
@@ -504,8 +504,9 @@ def store_internal(cmd, set, attr, flags)
end
def search_internal(command, *args)
- command += normalize_search_criteria(args)
- one_data_response(*command).transform{ |untagged_response| untagged_response.data }
+ collect_untagged_responses('SEARCH', command, *normalize_search_criteria(args)).transform do |untagged_responses|
+ untagged_responses.last.data
+ end
end
# Recursively find all the message sets in the arguments and convert them so that
View
@@ -162,7 +162,7 @@
end
end
- describe "uid_fetch" do
+ describe "in inbox" do
before :each do
@connection.should_receive(:send_data).with("RUBY0001 LOGIN conrad password\r\n")
@client.login('conrad', 'password')
@@ -172,7 +172,7 @@
@connection.receive_data "RUBY0002 OK Inbox selected. (Success)\r\n"
end
- it "should succeed" do
+ it "should be able to run a uid_fetch" do
a = nil
@connection.should_receive(:send_data).with("RUBY0003 UID FETCH 631 ALL\r\n")
@client.uid_fetch(631, 'ALL').callback{ |r| a = r }
@@ -182,6 +182,15 @@
a.size.should == 1
a.first.attr['ENVELOPE'].from.first.name.should == "Robbie Pamely"
end
+
+ it "should be able to run a uid_search" do
+ a = nil
+ @connection.should_receive(:send_data).with("RUBY0003 UID SEARCH CHARSET UTF-8 TEXT Robbie\r\n")
+ @client.uid_search('CHARSET', 'UTF-8', 'TEXT', 'Robbie').callback{ |r| a = r }
+ @connection.receive_data "* SEARCH 631\r\nRUBY0003 OK SEARCH completed (Success)\r\n"
+
+ a.should == [631]
+ end
end
end

0 comments on commit 96cf2e9

Please sign in to comment.