### Home Classes Methods

### In Files

- lib/vmail/imap_client.rb
- lib/vmail/send_options.rb
- lib/vmail/sender.rb
- lib/vmail/query.rb
- lib/vmail/contacts_extractor.rb
- lib/vmail/message_formatter.rb
- lib/vmail/version.rb
- lib/vmail/address_quoter.rb
- lib/vmail/reply_template.rb
- lib/vmail/options.rb
- lib/vmail.rb

### Namespace

- MODULE Vmail::AddressQuoter
- MODULE Vmail::Sender
- CLASS Vmail::ContactsExtractor
- CLASS Vmail::ImapClient
- CLASS Vmail::MessageFormatter
- CLASS Vmail::Options
- CLASS Vmail::Query
- CLASS Vmail::ReplyTemplate
- CLASS Vmail::SendOptions

### Methods

- #batch_run
- #noninteractive_list_messages
- #start

### Class/Module Index

Quicksearch

- Vmail
- Vmail::AddressQuoter
- Vmail::ContactsExtractor
- Vmail::ImapClient
- Vmail::MessageFormatter
- Vmail::Options
- Vmail::Query
- Vmail::ReplyTemplate
- Vmail::SendOptions
- Vmail::Sender
- String

No matching classes.

# Vmail

### Constants

INSTRUCTIONS
VERSION

### Public Instance Methods

batch_run() click to toggle source

batch processing mode

    # File lib/vmail.rb, line 113
    def batch_run
      check_lynx
      opts = Vmail::Options.new(ARGV)
      opts.config
      config = opts.config.merge 'logfile' => 'vmail.log'
      # no search query args, but command args
      imap_client  = Vmail::ImapClient.new config
      lines = STDIN.readlines# .reverse
      mailbox = lines.shift.chomp
      puts "mailbox: #{mailbox}"
      uid_set = lines.map do |line|
        line[/(\d+)\s*$/,1].to_i
      end
      commands = {
        'rm' => ["flag", "+FLAGS", "Deleted"],
        'spam' => ["flag", "+FLAGS", "spam"],
        'mv' => ["move_to"],
        'cp' => ["copy_to"],
        'print' => ["append_to_file"]
      }
      args = commands[ARGV.first]
      if args.nil?
        abort "Command '#{args.inspect}' not recognized"
      end
      command = args.shift
      imap_client.with_open do |vmail|
        puts "Selecting mailbox: #{mailbox}"
        vmail.select_mailbox mailbox
        uid_set.each_slice(5) do |uid_set|
          params = [uid_set.join(',')] + args + ARGV[1..-1]
          puts "Executing: #{command} #{params.join(' ')}"
          vmail.send command, *params
        end
      end
    end

noninteractive_list_messages() click to toggle source

non-interactive mode

    # File lib/vmail.rb, line 98
    def noninteractive_list_messages
      check_lynx
      opts = Vmail::Options.new(ARGV)
      opts.config
      config = opts.config.merge 'logfile' => 'vmail.log'
      mailbox, query = parse_query
      query_string = Vmail::Query.args2string query
      imap_client  = Vmail::ImapClient.new config
      imap_client.with_open do |vmail|
        vmail.select_mailbox mailbox
        vmail.search query_string
      end
    end

start() click to toggle source

    # File lib/vmail.rb, line 11
    def start
      puts "Starting vmail #{Vmail::VERSION}"
      if  Gem::Version.new("1.9.0") > Gem::Version.new(RUBY_VERSION)
        puts "This version of vmail requires Ruby version 1.9.0 or higher (1.9.2 is recommended)"
        exit
      end

      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:\n"
        file.puts "- drb uri: #{drb_uri}"
        file.puts "- mailbox: #{mailbox}"
        file.puts "- query: #{query_string}\n"
        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

[Validate]

Generated with the Darkfish Rdoc Generator 2.