class IMAPGet::CLI
Public Class Methods
defaults()
click to toggle source
Calls superclass method
# File lib/imapget/cli.rb 36 def defaults 37 super.merge( 38 config: 'config.yaml', 39 directory: nil, 40 check: false, 41 dupe: false, 42 uniq: false 43 ) 44 end
Public Instance Methods
run(arguments)
click to toggle source
# File lib/imapget/cli.rb 52 def run(arguments) 53 default_config, profiles = config.delete(:default_config), config.to_a 54 55 (arguments.empty? ? profiles.map(&:first) : arguments).each { |profile| 56 profile_config = profile_config(profile, profiles, default_config) or next 57 58 imapget = IMAPGet.new(profile_config) 59 60 if options[:check] 61 imapget.each { |mailbox| puts mailbox.name } 62 elsif options[:dupes] 63 imapget.each { |mailbox| imapget.dupes(mailbox.name) } 64 elsif options[:uniq] 65 imapget.each { |mailbox| imapget.uniq!(mailbox.name) { 66 next unless agree('Really delete duplicates? ') 67 } } 68 else 69 imapget.get(options[:directory] || 70 File.join(profile_config[:base_dir] || '.', profile.to_s)) 71 end 72 } 73 end
usage()
click to toggle source
# File lib/imapget/cli.rb 48 def usage 49 "#{super} [profile]..." 50 end
Private Instance Methods
merge_config(*)
click to toggle source
# File lib/imapget/cli.rb 77 def merge_config(*) 78 end
opts(opts)
click to toggle source
# File lib/imapget/cli.rb 80 def opts(opts) 81 opts.option(:directory__PATH, 'Path to directory to store mails in [Default: BASE_DIR/<profile>]') 82 83 opts.separator 84 85 opts.switch(:check, :C, "Only check include/exclude statements; don't download any mails") 86 87 opts.switch(:dupes, :D, "Only check for duplicate mails; don't download any mails") 88 89 opts.switch(:uniq, :U, "Only delete duplicate mails; don't download any mails") 90 end
profile_config(profile, profiles, default_config)
click to toggle source
# File lib/imapget/cli.rb 92 def profile_config(profile, profiles, default_config) 93 unless config = profiles.assoc(profile) 94 warn "No such profile: #{profile}" 95 return 96 end 97 98 config = config.last 99 default_config.each { |key, value| config[key] ||= value } 100 101 return if config[:skip] 102 103 unless host = config[:host] 104 warn "No host for profile: #{profile}" 105 return 106 end 107 108 config[:user] ||= ask("User for #{profile} on #{host}: ") 109 config[:password] ||= askpass("Password for #{config[:user]}@#{host}: ") 110 111 config 112 end