Sha256: e666b7cc0434cc7f89a043a80ef2f00d8586b21701abf920d1c30812b7c4b045

Contents?: true

Size: 1.74 KB

Versions: 29

Compression:

Stored size: 1.74 KB

Contents

module Vmail
  module Searching
    # The main function called by the client to retrieve messages
    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}" 
      clear_cached_message

      select_ids = search_query? ? @ids[-@limit,@limit] : @ids

      if select_ids.size > @limit
        raise "Too many messages to fetch headers for"
      end

      message_ids = fetch_and_cache_headers select_ids
      res = get_message_headers message_ids

      if STDOUT.tty?
        with_more_message_line(res)
      else
        # non interactive mode
        puts [@mailbox, res].join("\n")
      end
    rescue
      log "ERROR:\n#{$!.inspect}\n#{$!.backtrace.join("\n")}"
    end  

    def search_query?
      x = @query[-1] != 'all'
      log "Search query? #{x} #{@query.inspect}"
      x
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
vmail-1.9.7 lib/vmail/searching.rb
vmail-1.9.6 lib/vmail/searching.rb
vmail-1.9.5 lib/vmail/searching.rb
vmail-1.9.4 lib/vmail/searching.rb
vmail-1.9.3 lib/vmail/searching.rb
vmail-1.9.2 lib/vmail/searching.rb
vmail-1.9.1 lib/vmail/searching.rb
vmail-1.9.0 lib/vmail/searching.rb
vmail-1.8.9 lib/vmail/searching.rb
vmail-1.8.8 lib/vmail/searching.rb
vmail-1.8.7 lib/vmail/searching.rb
vmail-1.8.6 lib/vmail/searching.rb
vmail-1.8.5 lib/vmail/searching.rb
vmail-1.8.4 lib/vmail/searching.rb
vmail-1.8.3 lib/vmail/searching.rb
vmail-1.8.2 lib/vmail/searching.rb
vmail-1.8.1 lib/vmail/searching.rb
vmail-1.8.0 lib/vmail/searching.rb
vmail-1.7.9 lib/vmail/searching.rb
vmail-1.7.8 lib/vmail/searching.rb