sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 28eb70cd90eb8198187db6c7f591ff13f8271ac2
parent 3a75ba2de021948280f4a6b477b4db644b13f727
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Sun,  6 Jun 2010 21:49:05 -0700

load config in Redwood.start

Diffstat:
M lib/sup.rb | 109 ++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 58 insertions(+), 51 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -121,6 +121,7 @@ module Redwood
   end
 
   def start
+    $config = load_config
     Redwood::SentManager.init $config[:sent_source] || 'sup://sent'
     Redwood::ContactManager.init Redwood::CONTACT_FN
     Redwood::LabelManager.init Redwood::LABEL_FN
@@ -140,6 +141,7 @@ module Redwood
     Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
     Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
     Redwood::SearchManager.save if Redwood::SearchManager.instantiated?
+    $config = nil
   end
 
   ## not really a good place for this, so I'll just dump it here.
@@ -221,60 +223,65 @@ EOS
     end
   end
 
-  module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
-                  :report_broken_sources, :check_library_version_against
-end
-
-## set up default configuration file
-if File.exists? Redwood::CONFIG_FN
-  $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
-  abort "#{Redwood::CONFIG_FN} is not a valid configuration file (it's a #{$config.class}, not a hash)" unless $config.is_a?(Hash)
-else
-  require 'etc'
-  require 'socket'
-  name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first rescue nil
-  name ||= ENV["USER"]
-  email = ENV["USER"] + "@" + 
-    begin
-      Socket.gethostbyname(Socket.gethostname).first
-    rescue SocketError
-      Socket.gethostname
-    end
+  ## set up default configuration file
+  def load_config
+    if File.exists? Redwood::CONFIG_FN
+      config = Redwood::load_yaml_obj Redwood::CONFIG_FN
+      abort "#{Redwood::CONFIG_FN} is not a valid configuration file (it's a #{config.class}, not a hash)" unless config.is_a?(Hash)
+      config
+    else
+      require 'etc'
+      require 'socket'
+      name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first rescue nil
+      name ||= ENV["USER"]
+      email = ENV["USER"] + "@" + 
+        begin
+          Socket.gethostbyname(Socket.gethostname).first
+        rescue SocketError
+          Socket.gethostname
+        end
 
-  $config = {
-    :accounts => {
-      :default => {
-        :name => name,
-        :email => email,
-        :alternates => [],
-        :sendmail => "/usr/sbin/sendmail -oem -ti",
-        :signature => File.join(ENV["HOME"], ".signature")
+      config = {
+        :accounts => {
+          :default => {
+            :name => name,
+            :email => email,
+            :alternates => [],
+            :sendmail => "/usr/sbin/sendmail -oem -ti",
+            :signature => File.join(ENV["HOME"], ".signature")
+          }
+        },
+        :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
+        :thread_by_subject => false,
+        :edit_signature => false,
+        :ask_for_from => false,
+        :ask_for_to => true,
+        :ask_for_cc => true,
+        :ask_for_bcc => false,
+        :ask_for_subject => true,
+        :confirm_no_attachments => true,
+        :confirm_top_posting => true,
+        :jump_to_open_message => true,
+        :discard_snippets_from_encrypted_messages => false,
+        :default_attachment_save_dir => "",
+        :sent_source => "sup://sent",
+        :poll_interval => 300,
+        :wrap_width => 0,
+        :slip_rows => 0
       }
-    },
-    :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
-    :thread_by_subject => false,
-    :edit_signature => false,
-    :ask_for_from => false,
-    :ask_for_to => true,
-    :ask_for_cc => true,
-    :ask_for_bcc => false,
-    :ask_for_subject => true,
-    :confirm_no_attachments => true,
-    :confirm_top_posting => true,
-    :jump_to_open_message => true,
-    :discard_snippets_from_encrypted_messages => false,
-    :default_attachment_save_dir => "",
-    :sent_source => "sup://sent",
-    :poll_interval => 300,
-    :wrap_width => 0,
-    :slip_rows => 0
-  }
-  begin
-    FileUtils.mkdir_p Redwood::BASE_DIR
-    Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
-  rescue StandardError => e
-    $stderr.puts "warning: #{e.message}"
+      begin
+        FileUtils.mkdir_p Redwood::BASE_DIR
+        Redwood::save_yaml_obj config, Redwood::CONFIG_FN
+      rescue StandardError => e
+        $stderr.puts "warning: #{e.message}"
+      end
+      config
+    end
   end
+
+  module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
+                  :report_broken_sources, :check_library_version_against,
+                  :load_config
 end
 
 require "sup/util"