#!/usr/bin/env ruby require 'rubygems' require 'highline/import' require 'yaml' require 'trollop' require "sup" $opts = Trollop::options do version "sup-config (sup #{Redwood::VERSION})" banner < "mbox", :path => fn } when :maildir fn = axe "What's the full path to the maildir directory?", ENV["MAIL"] #"srm return if fn.nil? || fn.empty? { :scheme => "maildir", :path => fn } when :mboxssh srv = axe "What server is the mbox file located on?", $last_server return if srv.nil? || srv.empty? $last_server = srv fn = axe "What's the full path to the mbox file?", ENV["MAIL"] #"srm return if fn.nil? || fn.empty? fn = "/#{fn}" # lame { :scheme => "mbox+ssh", :host => srv, :path => fn } when :imap, :imaps srv = axe "What is the IMAP server?", $last_server return if srv.nil? || srv.empty? $last_server = srv fn = axe "What's the folder path?", "INBOX" #"srm return if fn.nil? || fn.empty? fn = "/#{fn}" # lame { :scheme => type.to_s, :host => srv, :path => fn } end uri = begin URI::Generic.build components rescue URI::Error => e say "Whoopsie! I couldn't build a URI from that: #{e.message}" if axe_yes("Try again?") then next else return end end say "I'm going to add this source: #{uri}." unless axe("Does that look right?", "y") =~ /^y|yes$/i if axe_yes("Try again?") then next else return end end usual = axe_yes "Does this source ever receive new messages?", "y" archive = usual ? axe_yes("Should those new messages be automatically archived?") : false cmd = build_cmd "sup-add" cmd += " --unusual" unless usual cmd += " --archive" if archive cmd += " #{uri}" puts "Ok, trying to run \"#{cmd}\"..." system cmd if $?.success? say "Great! Added!" break else say "Rats, that failed. You may have to do it manually." if axe_yes("Try again?") then next else return end end end end $terminal.wrap_at = :auto Redwood::start index = Redwood::Index.new index.load_sources say <" say "\nDo you have any alternate email addresses that also receive email?" say "If so, enter them now, separated by spaces." alts = axe("Alternate email addresses", account[:alternates].join(" ")).split(/\s+/) sigfn = axe "What file contains your signature?", account[:signature] editor = axe "What editor would you like to use?", $config[:editor] $config[:accounts][:default][:name] = name $config[:accounts][:default][:email] = email $config[:accounts][:default][:alternates] = alts $config[:accounts][:default][:signature] = sigfn $config[:editor] = editor Redwood::save_yaml_obj $config, Redwood::CONFIG_FN say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}." done = false until done say "\nNow, we'll tell Sup where to find all your email." index.load_sources say "Current sources:" if index.sources.empty? say " No sources!" else index.sources.each { |s| puts "* #{s}" } end say "\n" choose do |menu| menu.prompt = "Your wish?" menu.choice("Add a new source.") { add_source } menu.choice("Done adding sources!") { done = true } end end say <