    # File lib/vmail.rb, line 11
      def start
        puts "starting vmail #{Vmail::VERSION}"

        vim = ENV['VMAIL_VIM'] || 'vim'
        ENV['VMAIL_BROWSER'] ||= if RUBY_PLATFORM.downcase.include?('linux')
                                   tools = ['gnome-open', 'kfmclient-exec', 'konqueror']
                                   tool = tools.detect { |tool|
                                     `which #{tool}`.size > 0
                                   }
                                   if tool.nil?
                                     puts "Can't find a VMAIL_BROWSER tool on your system. Please report this issue."
                                   else
                                     tool
                                   end
                                 else
                                   'open'
                                 end

        puts "setting VMAIL_BROWSER to '#{ENV['VMAIL_BROWSER']}'"
        check_lynx

        opts = Vmail::Options.new(ARGV)
        opts.config
        config = opts.config

        contacts_file = opts.contacts_file

        logfile = (vim == 'mvim') ? STDERR : 'vmail.log'
        config.merge! 'logfile' => logfile

        puts "starting vmail imap client for #{config['username']}"

        drb_uri = begin
                    Vmail::ImapClient.daemon config
                  rescue
                    puts "Failure:", $!
                    exit(1)
                  end

        server = DRbObject.new_with_uri drb_uri

        mailbox, query = parse_query
        query_string = Vmail::Query.args2string query
        server.select_mailbox mailbox

        STDERR.puts "mailbox: #{mailbox}"
        STDERR.puts "query: #{query.inspect} => #{query_string}"

        buffer_file = "vmailbuffer"
        # invoke vim
        vimscript = File.expand_path("../vmail.vim", __FILE__)
        vim_command = "DRB_URI=#{drb_uri} VMAIL_CONTACTS_FILE=#{contacts_file} VMAIL_MAILBOX=#{String.shellescape(mailbox)} VMAIL_QUERY=#{String.shellescape(query_string)} #{vim} -S #{vimscript} #{buffer_file}"
        STDERR.puts vim_command

        STDERR.puts "using buffer file: #{buffer_file}"
        File.open(buffer_file, "w") do |file|
          file.puts "vmail starting with values:"
          file.puts "- drb uri: #{drb_uri}"
          file.puts "- mailbox: #{mailbox}"
          file.puts "- query: #{query_string}"
          file.puts
          file.puts "fetching messages. please wait..."
        end

        system(vim_command)

        if vim == 'mvim'
          DRb.thread.join
        end

        File.delete(buffer_file)

        STDERR.puts "closing imap connection"
        begin
          Timeout::timeout(10) do
            $gmail.close
          end
        rescue Timeout::Error
          puts "close connection attempt timed out"
        end
        puts "bye"
        exit
      end