9 ## this is for debugging purposes because i keep calling #id on the
10 ## wrong object and i want it to throw an exception
12 raise "wrong id called on #{self.inspect}"
17 def yaml_properties *props
18 props = props.map { |p| p.to_s }
19 vars = props.map { |p| "@#{p}" }
21 path = klass.name.gsub(/::/, "/")
23 klass.instance_eval do
24 define_method(:to_yaml_properties) { vars }
25 define_method(:to_yaml_type) { "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" }
28 YAML.add_domain_type("#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}", path) do |type, val|
29 klass.new(*props.map { |p| val[p] })
37 BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
38 CONFIG_FN = File.join(BASE_DIR, "config.yaml")
39 SOURCE_FN = File.join(BASE_DIR, "sources.yaml")
40 LABEL_FN = File.join(BASE_DIR, "labels.txt")
41 PERSON_FN = File.join(BASE_DIR, "people.txt")
42 CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
43 DRAFT_DIR = File.join(BASE_DIR, "drafts")
44 SENT_FN = File.join(BASE_DIR, "sent.mbox")
45 LOCK_FN = File.join(BASE_DIR, "lock")
46 SUICIDE_FN = File.join(BASE_DIR, "please-kill-yourself")
47 HOOK_DIR = File.join(BASE_DIR, "hooks")
49 YAML_DOMAIN = "masanjin.net"
50 YAML_DATE = "2006-10-01"
52 ## determine encoding and character set
53 ## probably a better way to do this
54 $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8"
56 if $ctype =~ /\.(.*)?/
62 ## record exceptions thrown in threads nicely
72 File.open("sup-exception-log.txt", "w") do |f|
73 f.puts "--- #{e.class.name} at #{Time.now}"
74 f.puts e.message, e.backtrace
82 module_function :reporting_thread
84 ## one-stop shop for yamliciousness
85 def save_yaml_obj object, fn, safe=false
87 safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}"
88 mode = File.stat(fn) if File.exists? fn
89 File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml }
90 FileUtils.mv safe_fn, fn
92 File.open(fn, "w") { |f| f.puts object.to_yaml }
96 def load_yaml_obj fn, compress=false
99 Zlib::GzipReader.open(fn) { |f| YAML::load f }
107 Redwood::PersonManager.new Redwood::PERSON_FN
108 Redwood::SentManager.new Redwood::SENT_FN
109 Redwood::ContactManager.new Redwood::CONTACT_FN
110 Redwood::LabelManager.new Redwood::LABEL_FN
111 Redwood::AccountManager.new $config[:accounts]
112 Redwood::DraftManager.new Redwood::DRAFT_DIR
113 Redwood::UpdateManager.new
114 Redwood::PollManager.new
115 Redwood::SuicideManager.new Redwood::SUICIDE_FN
116 Redwood::CryptoManager.new
120 Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
121 Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
122 Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
123 Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
126 ## not really a good place for this, so I'll just dump it here.
127 def report_broken_sources opts={}
128 return unless BufferManager.instantiated?
130 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
131 unless broken_sources.empty?
132 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
133 Source error notification
134 -------------------------
136 Hi there. It looks like one or more message sources is reporting
137 errors. Until this is corrected, messages from these sources cannot
138 be viewed, and new messages will not be detected.
140 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join("\n\n")}
145 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
146 unless desynced_sources.empty?
147 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
148 Out-of-sync source notification
149 -------------------------------
151 Hi there. It looks like one or more sources has fallen out of sync
152 with my index. This can happen when you modify these sources with
153 other email clients. (Sorry, I don't play well with others.)
155 Until this is corrected, messages from these sources cannot be viewed,
156 and new messages will not be detected. Luckily, this is easy to correct!
158 #{desynced_sources.map do |s|
159 "Source: " + s.to_s +
160 "\n Error: " + s.error.message.wrap(70).join("\n ") +
161 "\n Fix: sup-sync --changed #{s.to_s}"
168 module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
169 :report_broken_sources
172 ## set up default configuration file
173 if File.exists? Redwood::CONFIG_FN
174 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
178 name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first
179 email = ENV["USER"] + "@" +
181 Socket.gethostbyname(Socket.gethostname).first
192 :sendmail => "/usr/sbin/sendmail -oem -ti",
193 :signature => File.join(ENV["HOME"], ".signature")
196 :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
197 :thread_by_subject => false,
198 :edit_signature => false,
200 :ask_for_bcc => false,
201 :confirm_no_attachments => true,
202 :confirm_top_posting => true,
205 FileUtils.mkdir_p Redwood::BASE_DIR
206 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
207 rescue StandardError => e
208 $stderr.puts "warning: #{e.message}"
215 ## we have to initialize this guy first, because other classes must
216 ## reference it in order to register hooks, and they do that at parse
218 Redwood::HookManager.new Redwood::HOOK_DIR
221 require "sup/suicide"
222 require "sup/message-chunks"
223 require "sup/message"
226 require "sup/maildir"
229 require "sup/account"
232 require "sup/textfield"
236 require "sup/colormap"
238 require "sup/contact"
243 require "sup/modes/scroll-mode"
244 require "sup/modes/text-mode"
245 require "sup/modes/line-cursor-mode"
246 require "sup/modes/help-mode"
247 require "sup/modes/edit-message-mode"
248 require "sup/modes/compose-mode"
249 require "sup/modes/resume-mode"
250 require "sup/modes/forward-mode"
251 require "sup/modes/reply-mode"
252 require "sup/modes/label-list-mode"
253 require "sup/modes/contact-list-mode"
254 require "sup/modes/thread-view-mode"
255 require "sup/modes/thread-index-mode"
256 require "sup/modes/label-search-results-mode"
257 require "sup/modes/search-results-mode"
258 require "sup/modes/person-search-results-mode"
259 require "sup/modes/inbox-mode"
260 require "sup/modes/buffer-list-mode"
261 require "sup/modes/log-mode"
262 require "sup/modes/poll-mode"
263 require "sup/modes/file-browser-mode"
264 require "sup/modes/completion-mode"
269 def log s; Logger.log s; end
274 d = File.join base, "sup/share/modes/"
275 Redwood::Mode.load_all_modes d if File.directory? d