4 require 'highline/import'
9 $opts = Trollop::options do
10 version "sup-config (sup #{Redwood::VERSION})"
12 Interactive configuration tool for Sup. Won't destroy existing
22 def axe q, default=nil
23 ans = if default && !default.empty?
24 ask "#{q} (enter for \"#{default}\"): "
28 ans.empty? ? default : ans
31 def axe_yes q, default="n"
32 axe(q, default) =~ /^y|yes$/i
36 (ENV["RUBY_INVOCATION"] ? ENV["RUBY_INVOCATION"] + " " : "") + File.join(File.dirname($0), cmd)
42 say "Ok, adding a new source."
44 menu.prompt = "What type of mail source is it? "
45 menu.choice("mbox file") { type = :mbox }
46 menu.choice("maildir directory") { type = :maildir }
47 menu.choice("remote mbox file (accessible via ssh)") { type = :mboxssh }
48 menu.choice("IMAP server (secure)") { type = :imaps }
49 menu.choice("IMAP server (unsecure)") { type = :imap }
50 menu.choice("Get me out of here!") { return }
54 say "Ok, now for the details."
56 default_labels, components = case type
58 $last_fn ||= ENV["MAIL"]
59 fn = axe "What's the full path to the mbox file?", $last_fn
60 return if fn.nil? || fn.empty?
63 [Redwood::MBox::Loader.suggest_labels_for(fn),
64 { :scheme => "mbox", :path => fn }]
66 $last_fn ||= ENV["MAIL"]
67 fn = axe "What's the full path to the maildir directory?", $last_fn
68 return if fn.nil? || fn.empty?
71 [Redwood::Maildir.suggest_labels_for(fn),
72 { :scheme => "maildir", :path => fn }]
74 $last_server ||= "localhost"
75 srv = axe "What machine is the mbox file located on?", $last_server
76 return if srv.nil? || srv.empty?
79 fn = axe "What's the path to the mbox file?", $last_fn
80 return if fn.nil? || fn.empty?
83 [Redwood::MBox::SSHLoader.suggest_labels_for(fn),
84 { :scheme => "mbox+ssh", :host => srv, :path => fn }]
86 $last_server ||= "localhost"
87 srv = axe "What is the IMAP server (host, or host:port notation)?", $last_server
88 return if srv.nil? || srv.empty?
91 $last_folder ||= "INBOX"
92 fn = axe "What's the folder path?", $last_folder
93 return if fn.nil? || fn.empty?
97 if srv =~ /^(\S+):(\d+)$/
98 host, port = $1, $2.to_i
100 host, port = srv, nil
102 [Redwood::IMAP.suggest_labels_for(fn),
103 { :scheme => type.to_s, :host => host, :port => port, :path => fn }]
107 URI::Generic.build components
108 rescue URI::Error => e
109 say "Whoopsie! I couldn't build a URI from that: #{e.message}"
110 if axe_yes("Try again?") then next else return end
113 say "I'm going to add this source: #{uri}"
114 unless axe("Does that look right?", "y") =~ /^y|yes$/i
115 if axe_yes("Try again?") then next else return end
118 usual = axe_yes "Does this source ever receive new messages?", "y"
119 archive = usual ? axe_yes("Should new messages be automatically archived? (I.e. not appear in your inbox, though still be accessible via search.)") : false
121 labels_str = axe("Enter any labels to be automatically added to all messages from this source, separated by spaces (or 'none')", default_labels.join(","))
123 labels = if labels_str =~ /^\s*none\s*$/i
126 labels_str.split(/\s+/)
129 cmd = build_cmd "sup-add"
130 cmd += " --unusual" unless usual
131 cmd += " --archive" if archive
132 cmd += " --labels=#{labels.join(',')}" if labels && !labels.empty?
135 puts "Ok, trying to run \"#{cmd}\"..."
142 say "Rats, that failed. You may have to do it manually."
143 if axe_yes("Try again?") then next else return end
148 $terminal.wrap_at = :auto
150 index = Redwood::Index.init
151 Redwood::SourceManager.load_sources
154 Howdy neighbor! This here's sup-config, ready to help you jack in to
155 the next generation of digital cyberspace: the text-based email
156 program. Get ready to be the envy of everyone in your internets
157 with your amazing keyboarding skills! Jump from email to email with
158 nary a click of the mouse!
160 Just answer these simple questions and you'll be on your way.
164 account = $config[:accounts][:default]
166 name = axe "What's your name?", account[:name]
167 email = axe "What's your (primary) email address?", account[:email]
169 say "Ok, your header will look like this:"
170 say " From: #{name} <#{email}>"
172 say "\nDo you have any alternate email addresses that also receive email?"
173 say "If so, enter them now, separated by spaces."
174 alts = axe("Alternate email addresses", account[:alternates].join(" ")).split(/\s+/)
176 sigfn = axe "What file contains your signature?", account[:signature]
177 editor = axe "What editor would you like to use?", $config[:editor]
179 $config[:accounts][:default][:name] = name
180 $config[:accounts][:default][:email] = email
181 $config[:accounts][:default][:alternates] = alts
182 $config[:accounts][:default][:signature] = sigfn
183 $config[:editor] = editor
187 say "\nNow, we'll tell Sup where to find all your email."
188 Redwood::SourceManager.load_sources
189 say "Current sources:"
190 if Redwood::SourceManager.sources.empty?
193 Redwood::SourceManager.sources.each { |s| puts "* #{s}" }
198 menu.prompt = "Your wish? "
199 menu.choice("Add a new source.") { add_source }
200 menu.choice("Done adding sources!") { done = true }
204 say "\nSup needs to know where to store your sent messages."
205 say "Only sources capable of storing mail will be listed.\n\n"
207 Redwood::SourceManager.load_sources
208 if Redwood::SourceManager.sources.empty?
209 say "\nUsing the default sup://sent, since you haven't configured other sources yet."
210 $config[:sent_source] = 'sup://sent'
212 # this handles the event that source.yaml already contains the SentLoader
214 have_sup_sent = false
217 menu.prompt = "Store my sent mail in? "
219 valid_sents = Redwood::SourceManager.sources.each do |s|
220 have_sup_sent = true if s.to_s.eql?('sup://sent')
222 menu.choice(s.to_s) { $config[:sent_source] = s.to_s } if s.respond_to? :store_message
225 menu.choice('Default (sup://sent)') { $config[:sent_source] = 'sup://sent'} unless have_sup_sent
230 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
232 say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}."
236 Ok. The final step is to import all your messages into the Sup index.
237 Depending on how many messages are in the sources, this could take
242 if axe_yes "Run sup-sync to import all messages now?"
244 cmd = build_cmd("sup-sync") + " --all-sources"
245 puts "Ok, trying to run \"#{cmd}\"..."
248 say "Great! It worked!"
251 say "Rats, that failed. You may have to do it manually."
252 if axe_yes("Try again?") then next else break end
261 Okee doke, you've got yourself an index of #{index.size} messages. Looks
262 like you're ready to jack in to cyberspace there, cowboy.
264 Just one last command: