]> git.notmuchmail.org Git - sup/blobdiff - lib/sup.rb
added maildir support (finally!)
[sup] / lib / sup.rb
index 5bf39285f861dbef7a059e8edbfb58a1204eea69..76b435dfe9623e78d86b7ea4c593530ee734066a 100644 (file)
@@ -4,23 +4,22 @@ require 'zlib'
 require 'thread'
 require 'fileutils'
 
-Thread.abort_on_exception = true # make debugging possible
-
 class Object
   ## this is for debugging purposes because i keep calling #id on the
   ## wrong object and i want it to throw an exception
   def id
-    raise "wrong id called"
+    raise "wrong id called on #{self.inspect}"
   end
 end
 
 module Redwood
-  VERSION = "0.0.1"
+  VERSION = "0.0.7"
 
-  BASE_DIR   = File.join(ENV["HOME"], ".sup")
+  BASE_DIR   = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
   CONFIG_FN  = File.join(BASE_DIR, "config.yaml")
   SOURCE_FN  = File.join(BASE_DIR, "sources.yaml")
   LABEL_FN   = File.join(BASE_DIR, "labels.txt")
+  PERSON_FN  = File.join(BASE_DIR, "people.txt")
   CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
   DRAFT_DIR  = File.join(BASE_DIR, "drafts")
   SENT_FN    = File.join(BASE_DIR, "sent.mbox")
@@ -28,6 +27,24 @@ module Redwood
   YAML_DOMAIN = "masanjin.net"
   YAML_DATE = "2006-10-01"
 
+## record exceptions thrown in threads nicely
+  $exception = nil
+  def reporting_thread
+    ::Thread.new do
+      begin
+        yield
+      rescue Exception => e
+        File.open("sup-exception-log.txt", "w") do |f|
+          f.puts "--- #{e.class.name} at #{Time.now}"
+          f.puts e.message, e.backtrace
+        end
+        $exception ||= e
+        raise
+      end
+    end
+  end
+  module_function :reporting_thread
+
 ## one-stop shop for yamliciousness
   def register_yaml klass, props
     vars = props.map { |p| "@#{p}" }
@@ -61,7 +78,24 @@ module Redwood
     end
   end
 
-  module_function :register_yaml, :save_yaml_obj, :load_yaml_obj
+  def start
+    Redwood::PersonManager.new Redwood::PERSON_FN
+    Redwood::SentManager.new Redwood::SENT_FN
+    Redwood::ContactManager.new Redwood::CONTACT_FN
+    Redwood::LabelManager.new Redwood::LABEL_FN
+    Redwood::AccountManager.new $config[:accounts]
+    Redwood::DraftManager.new Redwood::DRAFT_DIR
+    Redwood::UpdateManager.new
+    Redwood::PollManager.new
+  end
+
+  def finish
+    Redwood::LabelManager.save
+    Redwood::ContactManager.save
+    Redwood::PersonManager.save
+  end
+
+  module_function :register_yaml, :save_yaml_obj, :load_yaml_obj, :start, :finish
 end
 
 ## set up default configuration file
@@ -75,7 +109,7 @@ else
         :email => "your.email.here@domain.tld",
         :alternates => [],
         :sendmail => "/usr/sbin/sendmail -oem -ti",
-        :sig_file => File.join(ENV["HOME"], ".signature")
+        :signature => File.join(ENV["HOME"], ".signature")
       }
     },
     :editor => ENV["EDITOR"] || "/usr/bin/vi",
@@ -93,6 +127,7 @@ require "sup/update"
 require "sup/message"
 require "sup/source"
 require "sup/mbox"
+require "sup/maildir"
 require "sup/imap"
 require "sup/person"
 require "sup/account"