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
37 File.open("sup-exception-log.txt", "w") do |f|
38 f.puts "--- #{e.class.name} at #{Time.now}"
39 f.puts e.message, e.backtrace
46 module_function :reporting_thread
48 ## one-stop shop for yamliciousness
49 def register_yaml klass, props
50 vars = props.map { |p| "@#{p}" }
51 path = klass.name.gsub(/::/, "/")
53 klass.instance_eval do
54 define_method(:to_yaml_properties) { vars }
55 define_method(:to_yaml_type) { "!#{YAML_DOMAIN},#{YAML_DATE}/#{path}" }
58 YAML.add_domain_type("#{YAML_DOMAIN},#{YAML_DATE}", path) do |type, val|
59 klass.new(*props.map { |p| val[p] })
63 def save_yaml_obj object, fn, compress=false
65 Zlib::GzipWriter.open(fn) { |f| f.puts object.to_yaml }
67 File.open(fn, "w") { |f| f.puts object.to_yaml }
71 def load_yaml_obj fn, compress=false
74 Zlib::GzipReader.open(fn) { |f| YAML::load f }
82 Redwood::PersonManager.new Redwood::PERSON_FN
83 Redwood::SentManager.new Redwood::SENT_FN
84 Redwood::ContactManager.new Redwood::CONTACT_FN
85 Redwood::LabelManager.new Redwood::LABEL_FN
86 Redwood::AccountManager.new $config[:accounts]
87 Redwood::DraftManager.new Redwood::DRAFT_DIR
88 Redwood::UpdateManager.new
89 Redwood::PollManager.new
93 Redwood::LabelManager.save
94 Redwood::ContactManager.save
95 Redwood::PersonManager.save
96 Redwood::BufferManager.deinstantiate!
99 ## not really a good place for this, so I'll just dump it here.
100 def report_broken_sources opts={}
101 return unless BufferManager.instantiated?
103 broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
104 unless broken_sources.empty?
105 BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
106 Source error notification
107 -------------------------
109 Hi there. It looks like one or more message sources is reporting
110 errors. Until this is corrected, messages from these sources cannot
111 be viewed, and new messages will not be detected.
113 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n ")}.join('\n\n')}
118 desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
119 unless desynced_sources.empty?
120 BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
121 Out-of-sync source notification
122 -------------------------------
124 Hi there. It looks like one or more sources has fallen out of sync
125 with my index. This can happen when you modify these sources with
126 other email clients. (Sorry, I don't play well with others.)
128 Until this is corrected, messages from these sources cannot be viewed,
129 and new messages will not be detected. Luckily, this is easy to correct!
131 #{desynced_sources.map do |s|
132 "Source: " + s.to_s +
133 "\n Error: " + s.error.message.wrap(70).join("\n ") +
134 "\n Fix: sup-sync --changed #{s.to_s}"
141 module_function :register_yaml, :save_yaml_obj, :load_yaml_obj, :start, :finish, :report_broken_sources
144 ## set up default configuration file
145 if File.exists? Redwood::CONFIG_FN
146 $config = Redwood::load_yaml_obj Redwood::CONFIG_FN
151 :name => "Sup Rocks",
152 :email => "sup-rocks@reading-my-emails",
154 :sendmail => "/usr/sbin/sendmail -oem -ti",
155 :signature => File.join(ENV["HOME"], ".signature")
158 :editor => ENV["EDITOR"] || "/usr/bin/vi",
161 FileUtils.mkdir_p Redwood::BASE_DIR
162 Redwood::save_yaml_obj $config, Redwood::CONFIG_FN
163 rescue StandardError => e
164 $stderr.puts "warning: #{e.message}"
170 require "sup/message"
173 require "sup/maildir"
176 require "sup/account"
179 require "sup/textfield"
183 require "sup/colormap"
185 require "sup/contact"
189 require "sup/modes/scroll-mode"
190 require "sup/modes/text-mode"
191 require "sup/modes/line-cursor-mode"
192 require "sup/modes/help-mode"
193 require "sup/modes/edit-message-mode"
194 require "sup/modes/compose-mode"
195 require "sup/modes/resume-mode"
196 require "sup/modes/forward-mode"
197 require "sup/modes/reply-mode"
198 require "sup/modes/label-list-mode"
199 require "sup/modes/contact-list-mode"
200 require "sup/modes/thread-view-mode"
201 require "sup/modes/thread-index-mode"
202 require "sup/modes/label-search-results-mode"
203 require "sup/modes/search-results-mode"
204 require "sup/modes/person-search-results-mode"
205 require "sup/modes/inbox-mode"
206 require "sup/modes/buffer-list-mode"
207 require "sup/modes/log-mode"
208 require "sup/modes/poll-mode"
213 def log s; Logger.log s; end
218 d = File.join base, "sup/share/modes/"
219 Redwood::Mode.load_all_modes d if File.directory? d