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")
46 HOOK_DIR = File.join(BASE_DIR, "hooks")
48 YAML_DOMAIN = "masanjin.net"
49 YAML_DATE = "2006-10-01"
51 ## determine encoding and character set
52 ## probably a better way to do this
53 $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8"
55 if $ctype =~ /\.(.*)?/
61 ## record exceptions thrown in threads nicely
71 File.open("sup-exception-log.txt", "w") do |f|
72 f.puts "--- #{e.class.name} at #{Time.now}"
73 f.puts e.message, e.backtrace
81 module_function :reporting_thread
83 ## one-stop shop for yamliciousness
84 def save_yaml_obj object, fn, safe=false
86 safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}"
87 mode = File.stat(fn) if File.exists? fn
88 File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml }
89 FileUtils.mv safe_fn, fn
91 File.open(fn, "w") { |f| f.puts object.to_yaml }
95 def load_yaml_obj fn, compress=false
98 Zlib::GzipReader.open(fn) { |f| YAML::load f }
106 Redwood::PersonManager.new Redwood::PERSON_FN
107 Redwood::SentManager.new Redwood::SENT_FN
108 Redwood::ContactManager.new Redwood::CONTACT_FN
109 Redwood::LabelManager.new Redwood::LABEL_FN
110 Redwood::AccountManager.new $config[:accounts]
111 Redwood::DraftManager.new Redwood::DRAFT_DIR
112 Redwood::UpdateManager.new
113 Redwood::PollManager.new
114 Redwood::SuicideManager.new Redwood::SUICIDE_FN
115 Redwood::CryptoManager.new
119 Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
120 Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
121 Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
122 Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
125 ## not really a good place for this, so I'll just dump it here.
126 def report_broken_sources opts={}
127 return unless BufferManager.instantiated?
129 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
130 unless broken_sources.empty?
131 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
132 Source error notification
133 -------------------------
135 Hi there. It looks like one or more message sources is reporting
136 errors. Until this is corrected, messages from these sources cannot
137 be viewed, and new messages will not be detected.
139 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join("\n\n")}
144 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
145 unless desynced_sources.empty?
146 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
147 Out-of-sync source notification
148 -------------------------------
150 Hi there. It looks like one or more sources has fallen out of sync
151 with my index. This can happen when you modify these sources with
152 other email clients. (Sorry, I don't play well with others.)
154 Until this is corrected, messages from these sources cannot be viewed,
155 and new messages will not be detected. Luckily, this is easy to correct!
157 #{desynced_sources.map do |s|
158 "Source: " + s.to_s +
159 "\n Error: " + s.error.message.wrap(70).join("\n ") +
160 "\n Fix: sup-sync --changed #{s.to_s}"
167 module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
168 :report_broken_sources
171 ## set up default configuration file
172 if File.exists? Redwood::CONFIG_FN
173 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
177 name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first
178 email = ENV["USER"] + "@" +
180 Socket.gethostbyname(Socket.gethostname).first
191 :sendmail => "/usr/sbin/sendmail -oem -ti",
192 :signature => File.join(ENV["HOME"], ".signature")
195 :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
196 :thread_by_subject => false,
197 :edit_signature => false,
199 :ask_for_bcc => false,
200 :confirm_no_attachments => true,
201 :confirm_top_posting => true,
204 FileUtils.mkdir_p Redwood::BASE_DIR
205 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
206 rescue StandardError => e
207 $stderr.puts "warning: #{e.message}"
214 ## we have to initialize this guy first, because other classes must
215 ## reference it in order to register hooks, and they do that at parse
217 Redwood::HookManager.new Redwood::HOOK_DIR
220 require "sup/suicide"
221 require "sup/message-chunks"
222 require "sup/message"
225 require "sup/maildir"
228 require "sup/account"
231 require "sup/textfield"
235 require "sup/colormap"
237 require "sup/contact"
242 require "sup/modes/scroll-mode"
243 require "sup/modes/text-mode"
244 require "sup/modes/line-cursor-mode"
245 require "sup/modes/help-mode"
246 require "sup/modes/edit-message-mode"
247 require "sup/modes/compose-mode"
248 require "sup/modes/resume-mode"
249 require "sup/modes/forward-mode"
250 require "sup/modes/reply-mode"
251 require "sup/modes/label-list-mode"
252 require "sup/modes/contact-list-mode"
253 require "sup/modes/thread-view-mode"
254 require "sup/modes/thread-index-mode"
255 require "sup/modes/label-search-results-mode"
256 require "sup/modes/search-results-mode"
257 require "sup/modes/person-search-results-mode"
258 require "sup/modes/inbox-mode"
259 require "sup/modes/buffer-list-mode"
260 require "sup/modes/log-mode"
261 require "sup/modes/poll-mode"
262 require "sup/modes/file-browser-mode"
263 require "sup/modes/completion-mode"
268 def log s; Logger.log s; end
273 d = File.join base, "sup/share/modes/"
274 Redwood::Mode.load_all_modes d if File.directory? d