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
20 end #' stupid ruby-mode
22 def axe q, default=nil
24 if default && !default.empty?
25 ask "#{q} (enter for \"#{default}\"): "
29 ans.empty? ? default : ans
32 def axe_yes q, default="n"
33 axe(q, default) =~ /^y|yes$/i
37 (ENV["RUBY_INVOCATION"] ? ENV["RUBY_INVOCATION"] + " " : "") + File.join(File.dirname($0), cmd)
43 say "Ok, adding a new source."
45 menu.prompt = "What type of mail source is it? "
46 menu.choice("mbox file") { type = :mbox }
47 menu.choice("maildir directory") { type = :maildir }
48 menu.choice("remote mbox file (accessible via ssh)") { type = :mboxssh }
49 menu.choice("IMAP server (secure)") { type = :imaps }
50 menu.choice("IMAP server (unsecure)") { type = :imap }
51 menu.choice("Get me out of here!") { return }
55 say "Ok, now for the details."
57 default_labels, components =
60 $last_fn ||= ENV["MAIL"]
61 fn = axe "What's the full path to the mbox file?", $last_fn #"srm
62 return if fn.nil? || fn.empty?
65 [Redwood::MBox::Loader.suggest_labels_for(fn),
66 { :scheme => "mbox", :path => fn }]
68 $last_fn ||= ENV["MAIL"]
69 fn = axe "What's the full path to the maildir directory?", $last_fn #"srm
70 return if fn.nil? || fn.empty?
73 [Redwood::Maildir.suggest_labels_for(fn),
74 { :scheme => "maildir", :path => fn }]
76 $last_server ||= "localhost"
77 srv = axe "What machine is the mbox file located on?", $last_server
78 return if srv.nil? || srv.empty?
81 fn = axe "What's the path to the mbox file?", $last_fn #" stupid ruby-mode
82 return if fn.nil? || fn.empty?
85 [Redwood::MBox::SSHLoader.suggest_labels_for(fn),
86 { :scheme => "mbox+ssh", :host => srv, :path => fn }]
88 $last_server ||= "localhost"
89 srv = axe "What is the IMAP server (host, or host:port notation)?", $last_server
90 return if srv.nil? || srv.empty?
93 $last_folder ||= "INBOX"
94 fn = axe "What's the folder path?", $last_folder #"srm
95 return if fn.nil? || fn.empty?
99 if srv =~ /^(\S+):(\d+)$/
100 host, port = $1, $2.to_i
102 host, port = srv, nil
104 [Redwood::IMAP.suggest_labels_for(fn),
105 { :scheme => type.to_s, :host => host, :port => port, :path => fn }]
110 URI::Generic.build components
111 rescue URI::Error => e
112 say "Whoopsie! I couldn't build a URI from that: #{e.message}"
113 if axe_yes("Try again?") then next else return end
116 say "I'm going to add this source: #{uri}"
117 unless axe("Does that look right?", "y") =~ /^y|yes$/i
118 if axe_yes("Try again?") then next else return end
121 usual = axe_yes "Does this source ever receive new messages?", "y"
122 archive = usual ? axe_yes("Should new messages be automatically archived? (I.e. not appear in your inbox, though still be accessible via search.)") : false
124 labels_str = axe("Enter any labels to be automatically added to all messages from this source, separated by spaces (or 'none')", default_labels.join(","))
127 if labels_str =~ /^\s*none\s*$/i
130 labels_str.split(/\s+/)
133 cmd = build_cmd "sup-add"
134 cmd += " --unusual" unless usual
135 cmd += " --archive" if archive
136 cmd += " --labels=#{labels.join(',')}" if labels && !labels.empty?
139 puts "Ok, trying to run \"#{cmd}\"..."
146 say "Rats, that failed. You may have to do it manually."
147 if axe_yes("Try again?") then next else return end
152 $terminal.wrap_at = :auto
154 index = Redwood::Index.new
158 Howdy neighbor! This here's sup-config, ready to help you jack in to
159 the next generation of digital cyberspace: the text-based email
160 program. Get ready to be the envy of everyone in your internets
161 with your amazing keyboarding skills! Jump from email to email with
162 nary a click of the mouse!
164 Just answer these simple questions and you'll be on your way.
169 account = $config[:accounts][:default]
171 name = axe "What's your name?", account[:name]
172 email = axe "What's your (primary) email address?", account[:email] #'srm
174 say "Ok, your header will look like this:"
175 say " From: #{name} <#{email}>"
177 say "\nDo you have any alternate email addresses that also receive email?"
178 say "If so, enter them now, separated by spaces."
179 alts = axe("Alternate email addresses", account[:alternates].join(" ")).split(/\s+/)
181 sigfn = axe "What file contains your signature?", account[:signature]
182 editor = axe "What editor would you like to use?", $config[:editor]
184 $config[:accounts][:default][:name] = name
185 $config[:accounts][:default][:email] = email
186 $config[:accounts][:default][:alternates] = alts
187 $config[:accounts][:default][:signature] = sigfn
188 $config[:editor] = editor
190 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
192 say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}."
196 say "\nNow, we'll tell Sup where to find all your email."
198 say "Current sources:"
199 if index.sources.empty?
202 index.sources.each { |s| puts "* #{s}" }
207 menu.prompt = "Your wish? "
208 menu.choice("Add a new source.") { add_source }
209 menu.choice("Done adding sources!") { done = true }
215 Ok. The final step is to import all your messages into the Sup index.
216 Depending on how many messages are in the sources, this could take
221 if axe_yes "Run sup-sync to import all messages now?"
223 cmd = build_cmd("sup-sync") + " --all-sources"
224 puts "Ok, trying to run \"#{cmd}\"..."
227 say "Great! It worked!"
230 say "Rats, that failed. You may have to do it manually."
231 if axe_yes("Try again?") then next else break end
240 Okee doke, you've got yourself an index of #{index.size} messages. Looks
241 like you're ready to jack in to cyberspace there, cowboy.
243 Just one last command: