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, compress=false
75 Zlib::GzipWriter.open(fn) { |f| f.puts object.to_yaml }
77 File.open(fn, "w") { |f| f.puts object.to_yaml }
81 def load_yaml_obj fn, compress=false
84 Zlib::GzipReader.open(fn) { |f| YAML::load f }
92 Redwood::PersonManager.new Redwood::PERSON_FN
93 Redwood::SentManager.new Redwood::SENT_FN
94 Redwood::ContactManager.new Redwood::CONTACT_FN
95 Redwood::LabelManager.new Redwood::LABEL_FN
96 Redwood::AccountManager.new $config[:accounts]
97 Redwood::DraftManager.new Redwood::DRAFT_DIR
98 Redwood::UpdateManager.new
99 Redwood::PollManager.new
100 Redwood::SuicideManager.new Redwood::SUICIDE_FN
104 Redwood::LabelManager.save
105 Redwood::ContactManager.save
106 Redwood::PersonManager.save
107 Redwood::BufferManager.deinstantiate!
110 ## not really a good place for this, so I'll just dump it here.
111 def report_broken_sources opts={}
112 return unless BufferManager.instantiated?
114 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
115 unless broken_sources.empty?
116 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
117 Source error notification
118 -------------------------
120 Hi there. It looks like one or more message sources is reporting
121 errors. Until this is corrected, messages from these sources cannot
122 be viewed, and new messages will not be detected.
124 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join("\n\n")}
129 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
130 unless desynced_sources.empty?
131 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
132 Out-of-sync source notification
133 -------------------------------
135 Hi there. It looks like one or more sources has fallen out of sync
136 with my index. This can happen when you modify these sources with
137 other email clients. (Sorry, I don't play well with others.)
139 Until this is corrected, messages from these sources cannot be viewed,
140 and new messages will not be detected. Luckily, this is easy to correct!
142 #{desynced_sources.map do |s|
143 "Source: " + s.to_s +
144 "\n Error: " + s.error.message.wrap(70).join("\n ") +
145 "\n Fix: sup-sync --changed #{s.to_s}"
152 module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
153 :report_broken_sources
156 ## set up default configuration file
157 if File.exists? Redwood::CONFIG_FN
158 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
162 name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first
163 email = ENV["USER"] + "@" +
165 Socket.gethostbyname(Socket.gethostname).first
176 :sendmail => "/usr/sbin/sendmail -oem -ti",
177 :signature => File.join(ENV["HOME"], ".signature")
180 :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
181 :thread_by_subject => false,
184 FileUtils.mkdir_p Redwood::BASE_DIR
185 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
186 rescue StandardError => e
187 $stderr.puts "warning: #{e.message}"
193 require "sup/suicide"
194 require "sup/message"
197 require "sup/maildir"
200 require "sup/account"
203 require "sup/textfield"
207 require "sup/colormap"
209 require "sup/contact"
213 require "sup/modes/scroll-mode"
214 require "sup/modes/text-mode"
215 require "sup/modes/line-cursor-mode"
216 require "sup/modes/help-mode"
217 require "sup/modes/edit-message-mode"
218 require "sup/modes/compose-mode"
219 require "sup/modes/resume-mode"
220 require "sup/modes/forward-mode"
221 require "sup/modes/reply-mode"
222 require "sup/modes/label-list-mode"
223 require "sup/modes/contact-list-mode"
224 require "sup/modes/thread-view-mode"
225 require "sup/modes/thread-index-mode"
226 require "sup/modes/label-search-results-mode"
227 require "sup/modes/search-results-mode"
228 require "sup/modes/person-search-results-mode"
229 require "sup/modes/inbox-mode"
230 require "sup/modes/buffer-list-mode"
231 require "sup/modes/log-mode"
232 require "sup/modes/poll-mode"
237 def log s; Logger.log s; end
242 d = File.join base, "sup/share/modes/"
243 Redwood::Mode.load_all_modes d if File.directory? d