Module: Vmail::Searching
- Included in:
- ImapClient
- Defined in:
- lib/vmail/searching.rb
Instance Method Summary collapse
-
#search(query) ⇒ Object
The main function called by the client to retrieve messages.
- #search_query? ⇒ Boolean
Instance Method Details
#search(query) ⇒ Object
The main function called by the client to retrieve messages
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vmail/searching.rb', line 4 def search(query) @query = Vmail::Query.parse(query) # customizable @limit is Deprecated @limit = 100 if search_query? #@num_messages = @all_ids.size query_string = Vmail::Query.args2string(@query) @ids = reconnect_if_necessary(180) do # timeout of 3 minutes @imap.search(query_string) end @start_index = [@ids.size - @limit, 0].max else # set the target range to the whole set, unless it is too big @start_index = [@num_messages - @limit, 0].max + 1 @query.unshift "#{@start_index}:#@num_messages" query_string = Vmail::Query.args2string(@query) log "Query: #{query_string.inspect}" @ids = reconnect_if_necessary(180) do # timeout of 3 minutes @imap.search(query_string) end end if @ids.empty? return "No messages" end self.max_seqno = @ids[-1] # this is a instance var log "- Query got #{@ids.size} results; max seqno: #{self.max_seqno}" select_ids = search_query? ? @ids[-@limit,@limit] : @ids if select_ids.size > @limit raise "Too many messages to fetch headers for" end = fetch_and_cache_headers select_ids res = if STDOUT.tty? (res) else # non interactive mode puts [@mailbox, res].join("\n") end rescue log "ERROR:\n#{$!.inspect}\n#{$!.backtrace.join("\n")}" end |
#search_query? ⇒ Boolean
54 55 56 57 58 |
# File 'lib/vmail/searching.rb', line 54 def search_query? x = @query[-1] != 'all' log "Search query? #{x} #{@query.inspect}" x end |