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")
44 LOCK_FN = File.join(BASE_DIR, "lock")
45 SUICIDE_FN = File.join(BASE_DIR, "please-kill-yourself")
47 YAML_DOMAIN = "masanjin.net"
48 YAML_DATE = "2006-10-01"
50 ## record exceptions thrown in threads nicely
60 File.open("sup-exception-log.txt", "w") do |f|
61 f.puts "--- #{e.class.name} at #{Time.now}"
62 f.puts e.message, e.backtrace
70 module_function :reporting_thread
72 ## one-stop shop for yamliciousness
73 def save_yaml_obj object, fn, safe=false
75 safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}"
76 mode = File.stat(fn) if File.exists? fn
77 File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml }
78 FileUtils.mv safe_fn, fn
80 File.open(fn, "w") { |f| f.puts object.to_yaml }
84 def load_yaml_obj fn, compress=false
87 Zlib::GzipReader.open(fn) { |f| YAML::load f }
95 Redwood::PersonManager.new Redwood::PERSON_FN
96 Redwood::SentManager.new Redwood::SENT_FN
97 Redwood::ContactManager.new Redwood::CONTACT_FN
98 Redwood::LabelManager.new Redwood::LABEL_FN
99 Redwood::AccountManager.new $config[:accounts]
100 Redwood::DraftManager.new Redwood::DRAFT_DIR
101 Redwood::UpdateManager.new
102 Redwood::PollManager.new
103 Redwood::SuicideManager.new Redwood::SUICIDE_FN
107 Redwood::PollManager.stop
108 Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
109 Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
110 Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
111 Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
114 ## not really a good place for this, so I'll just dump it here.
115 def report_broken_sources opts={}
116 return unless BufferManager.instantiated?
118 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
119 unless broken_sources.empty?
120 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
121 Source error notification
122 -------------------------
124 Hi there. It looks like one or more message sources is reporting
125 errors. Until this is corrected, messages from these sources cannot
126 be viewed, and new messages will not be detected.
128 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join("\n\n")}
133 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
134 unless desynced_sources.empty?
135 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
136 Out-of-sync source notification
137 -------------------------------
139 Hi there. It looks like one or more sources has fallen out of sync
140 with my index. This can happen when you modify these sources with
141 other email clients. (Sorry, I don't play well with others.)
143 Until this is corrected, messages from these sources cannot be viewed,
144 and new messages will not be detected. Luckily, this is easy to correct!
146 #{desynced_sources.map do |s|
147 "Source: " + s.to_s +
148 "\n Error: " + s.error.message.wrap(70).join("\n ") +
149 "\n Fix: sup-sync --changed #{s.to_s}"
156 module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
157 :report_broken_sources
160 ## set up default configuration file
161 if File.exists? Redwood::CONFIG_FN
162 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
166 name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first
167 email = ENV["USER"] + "@" +
169 Socket.gethostbyname(Socket.gethostname).first
180 :sendmail => "/usr/sbin/sendmail -oem -ti",
181 :signature => File.join(ENV["HOME"], ".signature")
184 :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
185 :thread_by_subject => false,
188 FileUtils.mkdir_p Redwood::BASE_DIR
189 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
190 rescue StandardError => e
191 $stderr.puts "warning: #{e.message}"
197 require "sup/suicide"
198 require "sup/message"
201 require "sup/maildir"
204 require "sup/account"
207 require "sup/textfield"
211 require "sup/colormap"
213 require "sup/contact"
217 require "sup/modes/scroll-mode"
218 require "sup/modes/text-mode"
219 require "sup/modes/line-cursor-mode"
220 require "sup/modes/help-mode"
221 require "sup/modes/edit-message-mode"
222 require "sup/modes/compose-mode"
223 require "sup/modes/resume-mode"
224 require "sup/modes/forward-mode"
225 require "sup/modes/reply-mode"
226 require "sup/modes/label-list-mode"
227 require "sup/modes/contact-list-mode"
228 require "sup/modes/thread-view-mode"
229 require "sup/modes/thread-index-mode"
230 require "sup/modes/label-search-results-mode"
231 require "sup/modes/search-results-mode"
232 require "sup/modes/person-search-results-mode"
233 require "sup/modes/inbox-mode"
234 require "sup/modes/buffer-list-mode"
235 require "sup/modes/log-mode"
236 require "sup/modes/poll-mode"
241 def log s; Logger.log s; end
246 d = File.join base, "sup/share/modes/"
247 Redwood::Mode.load_all_modes d if File.directory? d