### Home Classes Methods

### In Files

- lib/vmail/options.rb

### Parent

Object

### Methods

- ::new
- #parse

### 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::Options

### Constants

DEFAULT_CONTACTS_FILENAME

### Attributes

config[RW]
contacts_file[RW]

### Public Class Methods

new(argv) click to toggle source

    # File lib/vmail/options.rb, line 9
    def initialize(argv)
      config_file_locations = ['.vmailrc', "#{ENV['HOME']}/.vmailrc"]
      @config_file = config_file_locations.detect do |path|
        File.exists?(File.expand_path(path))
      end
      @contacts_file = [DEFAULT_CONTACTS_FILENAME, "#{ENV['HOME']}/#{DEFAULT_CONTACTS_FILENAME}"].detect  do |path|
        File.exists?(File.expand_path(path))
      end
      @config = {}
      parse argv
    end

### Public Instance Methods

parse(argv) click to toggle source

    # File lib/vmail/options.rb, line 21
    def parse(argv)
      OptionParser.new do |opts|
        opts.banner = "Usage:  vmail [ options ] [ limit ] [ imap search query ]"
        opts.separator ""
        opts.separator "Specific options:"
        opts.on("-c", "--config path", String, "Path to config file") do |config_file|
          @config_file = config_file
        end
        opts.on("-t", "--contacts path", String, "Path to contacts file") do |file|
          @contacts_file = file
        end
        opts.on("-g[n]", "--getcontacts[n]", Integer, "Generate contacts file. n is number of emails to scan (default 500).") do |n|
          @get_contacts = true
          @max_messages_to_scan = n || 500
        end
        opts.on("-v", "--version", "Show version") do
          require 'vmail/version'
          puts "vmail #{Vmail::VERSION}\nCopyright 2010 Daniel Choi under the MIT license"
          exit
        end
        opts.on("-h", "--help", "Show this message") do
          puts opts
          exit
        end
        opts.separator ""
        opts.separator INSTRUCTIONS

        begin
          opts.parse!(argv)
          if @config_file && File.exists?(@config_file)
            STDERR.puts "Using config file: #{@config_file}"
          else
            STDERR.puts Missing config file! #{INSTRUCTIONS}
            exit(1)
          end

          if STDOUT.tty?
            if @contacts_file.nil?
              STDERR.puts "No contacts file found for auto-completion. See help for how to generate it."
              sleep 0.5
            else
              STDERR.puts "Using contacts file: #{@contacts_file}"
            end
          end

          @config = YAML::load(File.read(@config_file))
          if @config['password'].nil?
            @config['password'] = ask("Enter gmail password (won't be visible & won't be persisted):") {|q| q.echo = false}
          end

          if @get_contacts
            require 'vmail/contacts_extractor'
            extractor = ContactsExtractor.new(@config['username'], @config['password'])
            File.open(DEFAULT_CONTACTS_FILENAME, 'w') do |file|
              extractor.extract(@max_messages_to_scan) do |address|
                STDERR.print '.'
                file.puts(address.strip)
                STDERR.flush
              end
            end
            STDERR.print "\n"
            puts "Saved file to #{DEFAULT_CONTACTS_FILENAME}"
            puts "Sorting address..."
            cmd = "sort #{DEFAULT_CONTACTS_FILENAME} | uniq > vmail-tmp.txt"
            cmd2 = "mv vmail-tmp.txt #{DEFAULT_CONTACTS_FILENAME}"
            `#{cmd}`
            `#{cmd2}`
            puts "Done"
            exit
          end

        rescue OptionParser::ParseError => e
          STDERR.puts e.message, "\n", opts
        end

      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.