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}"
18 BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
19 CONFIG_FN = File.join(BASE_DIR, "config.yaml")
20 SOURCE_FN = File.join(BASE_DIR, "sources.yaml")
21 LABEL_FN = File.join(BASE_DIR, "labels.txt")
22 PERSON_FN = File.join(BASE_DIR, "people.txt")
23 CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
24 DRAFT_DIR = File.join(BASE_DIR, "drafts")
25 SENT_FN = File.join(BASE_DIR, "sent.mbox")
27 YAML_DOMAIN = "masanjin.net"
28 YAML_DATE = "2006-10-01"
30 ## record exceptions thrown in threads nicely
40 File.open("sup-exception-log.txt", "w") do |f|
41 f.puts "--- #{e.class.name} at #{Time.now}"
42 f.puts e.message, e.backtrace
50 module_function :reporting_thread
52 ## one-stop shop for yamliciousness
53 def register_yaml klass, props
54 vars = props.map { |p| "@#{p}" }
55 path = klass.name.gsub(/::/, "/")
57 klass.instance_eval do
58 define_method(:to_yaml_properties) { vars }
59 define_method(:to_yaml_type) { "!#{YAML_DOMAIN},#{YAML_DATE}/#{path}" }
62 YAML.add_domain_type("#{YAML_DOMAIN},#{YAML_DATE}", path) do |type, val|
63 klass.new(*props.map { |p| val[p] })
67 def save_yaml_obj object, fn, compress=false
69 Zlib::GzipWriter.open(fn) { |f| f.puts object.to_yaml }
71 File.open(fn, "w") { |f| f.puts object.to_yaml }
75 def load_yaml_obj fn, compress=false
78 Zlib::GzipReader.open(fn) { |f| YAML::load f }
86 Redwood::PersonManager.new Redwood::PERSON_FN
87 Redwood::SentManager.new Redwood::SENT_FN
88 Redwood::ContactManager.new Redwood::CONTACT_FN
89 Redwood::LabelManager.new Redwood::LABEL_FN
90 Redwood::AccountManager.new $config[:accounts]
91 Redwood::DraftManager.new Redwood::DRAFT_DIR
92 Redwood::UpdateManager.new
93 Redwood::PollManager.new
97 Redwood::LabelManager.save
98 Redwood::ContactManager.save
99 Redwood::PersonManager.save
100 Redwood::BufferManager.deinstantiate!
103 ## not really a good place for this, so I'll just dump it here.
104 def report_broken_sources opts={}
105 return unless BufferManager.instantiated?
107 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
108 unless broken_sources.empty?
109 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
110 Source error notification
111 -------------------------
113 Hi there. It looks like one or more message sources is reporting
114 errors. Until this is corrected, messages from these sources cannot
115 be viewed, and new messages will not be detected.
117 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join('\n\n')}
122 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
123 unless desynced_sources.empty?
124 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
125 Out-of-sync source notification
126 -------------------------------
128 Hi there. It looks like one or more sources has fallen out of sync
129 with my index. This can happen when you modify these sources with
130 other email clients. (Sorry, I don't play well with others.)
132 Until this is corrected, messages from these sources cannot be viewed,
133 and new messages will not be detected. Luckily, this is easy to correct!
135 #{desynced_sources.map do |s|
136 "Source: " + s.to_s +
137 "\n Error: " + s.error.message.wrap(70).join("\n ") +
138 "\n Fix: sup-sync --changed #{s.to_s}"
145 module_function :register_yaml, :save_yaml_obj, :load_yaml_obj, :start, :finish, :report_broken_sources
148 ## set up default configuration file
149 if File.exists? Redwood::CONFIG_FN
150 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
155 :name => "Sup Rocks",
156 :email => "sup-rocks@reading-my-emails",
158 :sendmail => "/usr/sbin/sendmail -oem -ti",
159 :signature => File.join(ENV["HOME"], ".signature")
162 :editor => ENV["EDITOR"] || "/usr/bin/vi",
163 :thread_by_subject => false,
166 FileUtils.mkdir_p Redwood::BASE_DIR
167 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
168 rescue StandardError => e
169 $stderr.puts "warning: #{e.message}"
175 require "sup/message"
178 require "sup/maildir"
181 require "sup/account"
184 require "sup/textfield"
188 require "sup/colormap"
190 require "sup/contact"
194 require "sup/modes/scroll-mode"
195 require "sup/modes/text-mode"
196 require "sup/modes/line-cursor-mode"
197 require "sup/modes/help-mode"
198 require "sup/modes/edit-message-mode"
199 require "sup/modes/compose-mode"
200 require "sup/modes/resume-mode"
201 require "sup/modes/forward-mode"
202 require "sup/modes/reply-mode"
203 require "sup/modes/label-list-mode"
204 require "sup/modes/contact-list-mode"
205 require "sup/modes/thread-view-mode"
206 require "sup/modes/thread-index-mode"
207 require "sup/modes/label-search-results-mode"
208 require "sup/modes/search-results-mode"
209 require "sup/modes/person-search-results-mode"
210 require "sup/modes/inbox-mode"
211 require "sup/modes/buffer-list-mode"
212 require "sup/modes/log-mode"
213 require "sup/modes/poll-mode"
218 def log s; Logger.log s; end
223 d = File.join base, "sup/share/modes/"
224 Redwood::Mode.load_all_modes d if File.directory? d