8 ## this is for debugging purposes because i keep calling #id on the
9 ## wrong object and i want it to throw an exception
11 raise "wrong id called on #{self.inspect}"
16 def yaml_properties *props
17 props = props.map { |p| p.to_s }
18 vars = props.map { |p| "@#{p}" }
20 path = klass.name.gsub(/::/, "/")
22 klass.instance_eval do
23 define_method(:to_yaml_properties) { vars }
24 define_method(:to_yaml_type) { "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" }
27 YAML.add_domain_type("#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}", path) do |type, val|
28 klass.new(*props.map { |p| val[p] })
36 BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
37 CONFIG_FN = File.join(BASE_DIR, "config.yaml")
38 SOURCE_FN = File.join(BASE_DIR, "sources.yaml")
39 LABEL_FN = File.join(BASE_DIR, "labels.txt")
40 PERSON_FN = File.join(BASE_DIR, "people.txt")
41 CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
42 DRAFT_DIR = File.join(BASE_DIR, "drafts")
43 SENT_FN = File.join(BASE_DIR, "sent.mbox")
45 YAML_DOMAIN = "masanjin.net"
46 YAML_DATE = "2006-10-01"
48 ## record exceptions thrown in threads nicely
58 File.open("sup-exception-log.txt", "w") do |f|
59 f.puts "--- #{e.class.name} at #{Time.now}"
60 f.puts e.message, e.backtrace
68 module_function :reporting_thread
70 ## one-stop shop for yamliciousness
71 def save_yaml_obj object, fn, compress=false
73 Zlib::GzipWriter.open(fn) { |f| f.puts object.to_yaml }
75 File.open(fn, "w") { |f| f.puts object.to_yaml }
79 def load_yaml_obj fn, compress=false
82 Zlib::GzipReader.open(fn) { |f| YAML::load f }
90 Redwood::PersonManager.new Redwood::PERSON_FN
91 Redwood::SentManager.new Redwood::SENT_FN
92 Redwood::ContactManager.new Redwood::CONTACT_FN
93 Redwood::LabelManager.new Redwood::LABEL_FN
94 Redwood::AccountManager.new $config[:accounts]
95 Redwood::DraftManager.new Redwood::DRAFT_DIR
96 Redwood::UpdateManager.new
97 Redwood::PollManager.new
101 Redwood::LabelManager.save
102 Redwood::ContactManager.save
103 Redwood::PersonManager.save
104 Redwood::BufferManager.deinstantiate!
107 ## not really a good place for this, so I'll just dump it here.
108 def report_broken_sources opts={}
109 return unless BufferManager.instantiated?
111 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
112 unless broken_sources.empty?
113 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
114 Source error notification
115 -------------------------
117 Hi there. It looks like one or more message sources is reporting
118 errors. Until this is corrected, messages from these sources cannot
119 be viewed, and new messages will not be detected.
121 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join("\n\n")}
126 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
127 unless desynced_sources.empty?
128 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
129 Out-of-sync source notification
130 -------------------------------
132 Hi there. It looks like one or more sources has fallen out of sync
133 with my index. This can happen when you modify these sources with
134 other email clients. (Sorry, I don't play well with others.)
136 Until this is corrected, messages from these sources cannot be viewed,
137 and new messages will not be detected. Luckily, this is easy to correct!
139 #{desynced_sources.map do |s|
140 "Source: " + s.to_s +
141 "\n Error: " + s.error.message.wrap(70).join("\n ") +
142 "\n Fix: sup-sync --changed #{s.to_s}"
149 module_function :save_yaml_obj, :load_yaml_obj, :start, :finish, :report_broken_sources
152 ## set up default configuration file
153 if File.exists? Redwood::CONFIG_FN
154 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
159 :name => "Sup Rocks",
160 :email => "sup-rocks@reading-my-emails",
162 :sendmail => "/usr/sbin/sendmail -oem -ti",
163 :signature => File.join(ENV["HOME"], ".signature")
166 :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
167 :thread_by_subject => false,
170 FileUtils.mkdir_p Redwood::BASE_DIR
171 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
172 rescue StandardError => e
173 $stderr.puts "warning: #{e.message}"
179 require "sup/message"
182 require "sup/maildir"
185 require "sup/account"
188 require "sup/textfield"
192 require "sup/colormap"
194 require "sup/contact"
198 require "sup/modes/scroll-mode"
199 require "sup/modes/text-mode"
200 require "sup/modes/line-cursor-mode"
201 require "sup/modes/help-mode"
202 require "sup/modes/edit-message-mode"
203 require "sup/modes/compose-mode"
204 require "sup/modes/resume-mode"
205 require "sup/modes/forward-mode"
206 require "sup/modes/reply-mode"
207 require "sup/modes/label-list-mode"
208 require "sup/modes/contact-list-mode"
209 require "sup/modes/thread-view-mode"
210 require "sup/modes/thread-index-mode"
211 require "sup/modes/label-search-results-mode"
212 require "sup/modes/search-results-mode"
213 require "sup/modes/person-search-results-mode"
214 require "sup/modes/inbox-mode"
215 require "sup/modes/buffer-list-mode"
216 require "sup/modes/log-mode"
217 require "sup/modes/poll-mode"
222 def log s; Logger.log s; end
227 d = File.join base, "sup/share/modes/"
228 Redwood::Mode.load_all_modes d if File.directory? d