X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=bin%2Fsup-config;h=b37e0b2edce0417e8ac43ad1959be8c97460cf13;hb=ea8c342fdef36e1876016c25dd4d7f7d4829d7c6;hp=d68fac108c4eed2e441311718cceb86fc65ecdfe;hpb=db92b86c6d00e669e7b1b343d07e44a9f8d3c4ad;p=sup diff --git a/bin/sup-config b/bin/sup-config old mode 100644 new mode 100755 index d68fac1..b37e0b2 --- a/bin/sup-config +++ b/bin/sup-config @@ -17,14 +17,13 @@ Usage: Options: EOS -end #' stupid ruby-mode +end def axe q, default=nil - ans = - if default && !default.empty? + ans = if default && !default.empty? ask "#{q} (enter for \"#{default}\"): " else - ask "#{q} " + ask "#{q}: " end ans.empty? ? default : ans end @@ -42,7 +41,7 @@ def add_source say "Ok, adding a new source." choose do |menu| - menu.prompt = "What type of mail source is it?" + menu.prompt = "What type of mail source is it? " menu.choice("mbox file") { type = :mbox } menu.choice("maildir directory") { type = :maildir } menu.choice("remote mbox file (accessible via ssh)") { type = :mboxssh } @@ -52,54 +51,85 @@ def add_source end while true do - say "Now for the details." - - components = - case type - when :mbox - fn = axe "What's the full path to the mbox file?", ENV["MAIL"] #"srm - return if fn.nil? || fn.empty? - { :scheme => "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? - { :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 + say "Ok, now for the details." + + default_labels, components = case type + when :mbox + $last_fn ||= ENV["MAIL"] + fn = axe "What's the full path to the mbox file?", $last_fn + return if fn.nil? || fn.empty? + + $last_fn = fn + [Redwood::MBox::Loader.suggest_labels_for(fn), + { :scheme => "mbox", :path => fn }] + when :maildir + $last_fn ||= ENV["MAIL"] + fn = axe "What's the full path to the maildir directory?", $last_fn + return if fn.nil? || fn.empty? + + $last_fn = fn + [Redwood::Maildir.suggest_labels_for(fn), + { :scheme => "maildir", :path => fn }] + when :mboxssh + $last_server ||= "localhost" + srv = axe "What machine is the mbox file located on?", $last_server + return if srv.nil? || srv.empty? + $last_server = srv + + fn = axe "What's the path to the mbox file?", $last_fn + return if fn.nil? || fn.empty? + $last_fn = fn + fn = "/#{fn}" # lame + [Redwood::MBox::SSHLoader.suggest_labels_for(fn), + { :scheme => "mbox+ssh", :host => srv, :path => fn }] + when :imap, :imaps + $last_server ||= "localhost" + srv = axe "What is the IMAP server (host, or host:port notation)?", $last_server + return if srv.nil? || srv.empty? + $last_server = srv + + $last_folder ||= "INBOX" + fn = axe "What's the folder path?", $last_folder + return if fn.nil? || fn.empty? + $last_folder = fn + + fn = "/#{fn}" + if srv =~ /^(\S+):(\d+)$/ + host, port = $1, $2.to_i + else + host, port = srv, nil end + [Redwood::IMAP.suggest_labels_for(fn), + { :scheme => type.to_s, :host => host, :port => port, :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}." + 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 - + archive = usual ? axe_yes("Should new messages be automatically archived? (I.e. not appear in your inbox, though still be accessible via search.)") : false + + labels_str = axe("Enter any labels to be automatically added to all messages from this source, separated by spaces (or 'none')", default_labels.join(",")) + + labels = if labels_str =~ /^\s*none\s*$/i + nil + else + labels_str.split(/\s+/) + end + cmd = build_cmd "sup-add" cmd += " --unusual" unless usual cmd += " --archive" if archive + cmd += " --labels=#{labels.join(',')}" if labels && !labels.empty? cmd += " #{uri}" puts "Ok, trying to run \"#{cmd}\"..." @@ -117,8 +147,8 @@ end $terminal.wrap_at = :auto Redwood::start -index = Redwood::Index.new -index.load_sources +index = Redwood::Index.init +Redwood::SourceManager.load_sources say <" say "\nDo you have any alternate email addresses that also receive email?" @@ -154,43 +182,61 @@ $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 + Redwood::SourceManager.load_sources say "Current sources:" - if index.sources.empty? + if Redwood::SourceManager.sources.empty? say " No sources!" else - index.sources.each { |s| puts "* #{s}" } + Redwood::SourceManager.sources.each { |s| puts "* #{s}" } end say "\n" choose do |menu| - menu.prompt = "Your wish?" + menu.prompt = "Your wish? " menu.choice("Add a new source.") { add_source } menu.choice("Done adding sources!") { done = true } end end +say "\nSup needs to know where to store your sent messages." +say "Only sources capable of storing mail will be listed.\n\n" + +Redwood::SourceManager.load_sources +if Redwood::SourceManager.sources.empty? + say "\nUsing the default sup://sent, since you haven't configured other sources yet." + $config[:sent_source] = 'sup://sent' +else + # this handles the event that source.yaml already contains the SentLoader + # source. + have_sup_sent = false + + choose do |menu| + menu.prompt = "Store my sent mail in? " + + menu.choice('Default (an mbox in ~/.sup, aka sup://sent)') { $config[:sent_source] = 'sup://sent'} unless have_sup_sent + + valid_sents = Redwood::SourceManager.sources.each do |s| + have_sup_sent = true if s.to_s.eql?('sup://sent') + menu.choice(s.to_s) { $config[:sent_source] = s.to_s } if s.respond_to? :store_message + end + end +end + +Redwood::save_yaml_obj $config, Redwood::CONFIG_FN + +say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}." + say <