class IMAPGet::CLI

Public Class Methods

defaults() click to toggle source
Calls superclass method
# File lib/imapget/cli.rb, line 36
def defaults
  super.merge(
    config:    'config.yaml',
    directory: nil,
    check:     false,
    dupe:      false,
    uniq:      false
  )
end

Public Instance Methods

run(arguments) click to toggle source
# File lib/imapget/cli.rb, line 52
def run(arguments)
  profiles, default_config = config.partition { |k,| k.is_a?(String) }

  (arguments.empty? ? profiles.map(&:first) : arguments).each { |profile|
    profile_config = profile_config(profile, profiles, default_config) or next

    imapget = IMAPGet.new(profile_config)

    if options[:check]
      imapget.each { |mailbox| puts mailbox.name }
    elsif options[:dupes]
      imapget.each { |mailbox| imapget.dupes(mailbox.name) }
    elsif options[:uniq]
      imapget.each { |mailbox| imapget.uniq!(mailbox.name) {
        next unless agree('Really delete duplicates? ')
      } }
    else
      imapget.get(options[:directory] ||
        File.join(profile_config[:base_dir] || '.', profile))
    end
  }
end
usage() click to toggle source
# File lib/imapget/cli.rb, line 48
def usage
  "#{super} [profile]..."
end

Private Instance Methods

merge_config(*) click to toggle source
# File lib/imapget/cli.rb, line 77
def merge_config(*)
end
opts(opts) click to toggle source
# File lib/imapget/cli.rb, line 80
def opts(opts)
  opts.option(:directory__PATH, 'Path to directory to store mails in [Default: BASE_DIR/<profile>]')

  opts.separator

  opts.switch(:check, :C, "Only check include/exclude statements; don't download any mails")

  opts.switch(:dupes, :D, "Only check for duplicate mails; don't download any mails")

  opts.switch(:uniq, :U, "Only delete duplicate mails; don't download any mails")
end
profile_config(profile, profiles, default_config) click to toggle source
# File lib/imapget/cli.rb, line 92
def profile_config(profile, profiles, default_config)
  unless config = profiles.assoc(profile)
    warn "No such profile: #{profile}"
    return
  end

  config = config.last
  default_config.each { |key, value| config[key] ||= value }

  return if config[:skip]

  unless host = config[:host]
    warn "No host for profile: #{profile}"
    return
  end

  config[:user]     ||= ask("User for #{profile} on #{host}: ")
  config[:password] ||= askpass("Password for #{config[:user]}@#{host}: ")

  config
end