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::LabelManager.save if Redwood::LabelManager.instantiated?
108 Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
109 Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
110 Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
113 ## not really a good place for this, so I'll just dump it here.
114 def report_broken_sources opts={}
115 return unless BufferManager.instantiated?
117 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
118 unless broken_sources.empty?
119 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
120 Source error notification
121 -------------------------
123 Hi there. It looks like one or more message sources is reporting
124 errors. Until this is corrected, messages from these sources cannot
125 be viewed, and new messages will not be detected.
127 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join("\n\n")}
132 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
133 unless desynced_sources.empty?
134 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
135 Out-of-sync source notification
136 -------------------------------
138 Hi there. It looks like one or more sources has fallen out of sync
139 with my index. This can happen when you modify these sources with
140 other email clients. (Sorry, I don't play well with others.)
142 Until this is corrected, messages from these sources cannot be viewed,
143 and new messages will not be detected. Luckily, this is easy to correct!
145 #{desynced_sources.map do |s|
146 "Source: " + s.to_s +
147 "\n Error: " + s.error.message.wrap(70).join("\n ") +
148 "\n Fix: sup-sync --changed #{s.to_s}"
155 module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
156 :report_broken_sources
159 ## set up default configuration file
160 if File.exists? Redwood::CONFIG_FN
161 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
165 name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first
166 email = ENV["USER"] + "@" +
168 Socket.gethostbyname(Socket.gethostname).first
179 :sendmail => "/usr/sbin/sendmail -oem -ti",
180 :signature => File.join(ENV["HOME"], ".signature")
183 :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
184 :thread_by_subject => false,
187 FileUtils.mkdir_p Redwood::BASE_DIR
188 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
189 rescue StandardError => e
190 $stderr.puts "warning: #{e.message}"
196 require "sup/suicide"
197 require "sup/message"
200 require "sup/maildir"
203 require "sup/account"
206 require "sup/textfield"
210 require "sup/colormap"
212 require "sup/contact"
216 require "sup/modes/scroll-mode"
217 require "sup/modes/text-mode"
218 require "sup/modes/line-cursor-mode"
219 require "sup/modes/help-mode"
220 require "sup/modes/edit-message-mode"
221 require "sup/modes/compose-mode"
222 require "sup/modes/resume-mode"
223 require "sup/modes/forward-mode"
224 require "sup/modes/reply-mode"
225 require "sup/modes/label-list-mode"
226 require "sup/modes/contact-list-mode"
227 require "sup/modes/thread-view-mode"
228 require "sup/modes/thread-index-mode"
229 require "sup/modes/label-search-results-mode"
230 require "sup/modes/search-results-mode"
231 require "sup/modes/person-search-results-mode"
232 require "sup/modes/inbox-mode"
233 require "sup/modes/buffer-list-mode"
234 require "sup/modes/log-mode"
235 require "sup/modes/poll-mode"
240 def log s; Logger.log s; end
245 d = File.join base, "sup/share/modes/"
246 Redwood::Mode.load_all_modes d if File.directory? d