Module: Redwood
- Defined in:
- lib/sup.rb,
lib/sup/hook.rb,
lib/sup/idle.rb,
lib/sup/mbox.rb,
lib/sup/mode.rb,
lib/sup/poll.rb,
lib/sup/sent.rb,
lib/sup/undo.rb,
lib/sup/draft.rb,
lib/sup/index.rb,
lib/sup/label.rb,
lib/sup/buffer.rb,
lib/sup/client.rb,
lib/sup/crypto.rb,
lib/sup/keymap.rb,
lib/sup/logger.rb,
lib/sup/person.rb,
lib/sup/search.rb,
lib/sup/server.rb,
lib/sup/source.rb,
lib/sup/tagger.rb,
lib/sup/thread.rb,
lib/sup/update.rb,
lib/sup/account.rb,
lib/sup/contact.rb,
lib/sup/maildir.rb,
lib/sup/message.rb,
lib/sup/colormap.rb,
lib/sup/textfield.rb,
lib/sup/message-chunks.rb,
lib/sup/modes/log-mode.rb,
lib/sup/modes/help-mode.rb,
lib/sup/modes/poll-mode.rb,
lib/sup/modes/text-mode.rb,
lib/sup/interactive-lock.rb,
lib/sup/modes/inbox-mode.rb,
lib/sup/modes/reply-mode.rb,
lib/sup/modes/resume-mode.rb,
lib/sup/modes/scroll-mode.rb,
lib/sup/modes/compose-mode.rb,
lib/sup/modes/console-mode.rb,
lib/sup/modes/forward-mode.rb,
lib/sup/horizontal-selector.rb,
lib/sup/modes/completion-mode.rb,
lib/sup/modes/label-list-mode.rb,
lib/sup/modes/buffer-list-mode.rb,
lib/sup/modes/line-cursor-mode.rb,
lib/sup/modes/search-list-mode.rb,
lib/sup/modes/thread-view-mode.rb,
lib/sup/modes/contact-list-mode.rb,
lib/sup/modes/edit-message-mode.rb,
lib/sup/modes/file-browser-mode.rb,
lib/sup/modes/thread-index-mode.rb,
lib/sup/modes/search-results-mode.rb,
lib/sup/modes/label-search-results-mode.rb,
lib/sup/modes/person-search-results-mode.rb
Defined Under Namespace
Modules: CanAliasContacts, Chunk, InteractiveLock, LogsStuff, SerializeLabelsNicely Classes: Account, AccountManager, Buffer, BufferListMode, BufferManager, Client, Colormap, CompletionMode, ComposeMode, Console, ConsoleMode, ContactListMode, ContactManager, Container, CryptoManager, DraftLoader, DraftManager, EditMessageMode, FatalSourceError, FileBrowserMode, ForwardMode, HelpMode, HookManager, HorizontalSelector, IdleManager, InboxMode, Index, InputSequenceAborted, Keymap, LabelListMode, LabelManager, LabelSearchResultsMode, LineCursorMode, Location, LogMode, Logger, MBox, Maildir, Message, Mode, OutOfSyncSourceError, Person, PersonSearchResultsMode, PollManager, PollMode, ReplyMode, ResumeMode, ScrollMode, SearchListMode, SearchManager, SearchResultsMode, SendmailCommandFailed, SentLoader, SentManager, Server, Source, SourceError, SourceManager, Tagger, TextField, TextMode, Thread, ThreadIndexMode, ThreadSet, ThreadViewMode, UndoManager, UpdateManager
Constant Summary collapse
- VERSION =
"0.12.1"
- BASE_DIR =
ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
- CONFIG_FN =
File.join(BASE_DIR, "config.yaml")
- COLOR_FN =
File.join(BASE_DIR, "colors.yaml")
- SOURCE_FN =
File.join(BASE_DIR, "sources.yaml")
- LABEL_FN =
File.join(BASE_DIR, "labels.txt")
- CONTACT_FN =
File.join(BASE_DIR, "contacts.txt")
- DRAFT_DIR =
File.join(BASE_DIR, "drafts")
- SENT_FN =
File.join(BASE_DIR, "sent.mbox")
- LOCK_FN =
File.join(BASE_DIR, "lock")
- SUICIDE_FN =
File.join(BASE_DIR, "please-kill-yourself")
- HOOK_DIR =
File.join(BASE_DIR, "hooks")
- SEARCH_FN =
File.join(BASE_DIR, "searches.txt")
- LOG_FN =
File.join(BASE_DIR, "log")
- YAML_DOMAIN =
"masanjin.net"
- YAML_DATE =
"2006-10-01"
Class Method Summary collapse
-
.check_library_version_against(v) ⇒ Object
to be called by entry points in bin/, to ensure that their versions match up against the library versions.
-
.exceptions ⇒ Object
Returns the value of attribute exceptions.
- .finish ⇒ Object
-
.load_config(filename) ⇒ Object
set up default configuration file.
- .load_yaml_obj(fn, compress = false) ⇒ Object
- .managers ⇒ Object
- .record_exception(e, name) ⇒ Object
-
.report_broken_sources(opts = {}) ⇒ Object
not really a good place for this, so I’ll just dump it here.
- .reporting_thread(name) ⇒ Object
-
.save_yaml_obj(o, fn, safe = false, backup = false) ⇒ Object
one-stop shop for yamliciousness.
- .start ⇒ Object
Class Method Details
.check_library_version_against(v) ⇒ Object
to be called by entry points in bin/, to ensure that their versions match up against the library versions.
this is a perennial source of bug reports from people who both use git and have a gem version installed.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/sup.rb', line 238 def check_library_version_against v unless Redwood::VERSION == v $stderr.puts <<EOS Error: version mismatch! The sup executable is at version #{v.inspect}. The sup libraries are at version #{Redwood::VERSION.inspect}. Your development environment may be picking up code from a rubygems installation of sup. If you're running from git with a commandline like ruby -Ilib #{$0} try this instead: RUBY_INVOCATION="ruby -Ilib" ruby -Ilib #{$0} You can also try `gem uninstall sup` and removing all Sup rubygems. EOS abort end end |
.exceptions ⇒ Object
Returns the value of attribute exceptions.
64 65 66 |
# File 'lib/sup.rb', line 64 def exceptions @exceptions end |
.finish ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/sup.rb', line 171 def finish Redwood::LabelManager.save if Redwood::LabelManager.instantiated? Redwood::ContactManager.save if Redwood::ContactManager.instantiated? Redwood::SearchManager.save if Redwood::SearchManager.instantiated? Redwood::Logger.remove_sink @log_io managers.each { |x| x.deinstantiate! if x.instantiated? } @log_io.close @log_io = nil $config = nil end |
.load_config(filename) ⇒ Object
set up default configuration file
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/sup.rb', line 264 def load_config filename if File.exists? filename config = Redwood::load_yaml_obj filename abort "#{filename} is not a valid configuration file (it's a #{config.class}, not a hash)" unless config.is_a?(Hash) config else require 'etc' require 'socket' name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first rescue nil name ||= ENV["USER"] email = ENV["USER"] + "@" + begin Socket.gethostbyname(Socket.gethostname).first rescue SocketError Socket.gethostname end config = { :accounts => { :default => { :name => name, :email => email, :alternates => [], :sendmail => "/usr/sbin/sendmail -oem -ti", :signature => File.join(ENV["HOME"], ".signature"), :gpgkey => "" } }, :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'", :thread_by_subject => false, :edit_signature => false, :ask_for_from => false, :ask_for_to => true, :ask_for_cc => true, :ask_for_bcc => false, :ask_for_subject => true, :confirm_no_attachments => true, :confirm_top_posting => true, :jump_to_open_message => true, :discard_snippets_from_encrypted_messages => false, :default_attachment_save_dir => "", :sent_source => "sup://sent", :poll_interval => 300, :wrap_width => 0, :slip_rows => 0 } begin Redwood::save_yaml_obj config, filename, false, true rescue StandardError => e $stderr.puts "warning: #{e.}" end config end end |
.load_yaml_obj(fn, compress = false) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/sup.rb', line 131 def load_yaml_obj fn, compress=false o = if File.exists? fn if compress Zlib::GzipReader.open(fn) { |f| YAML::load f } else YAML::load_file fn end end if o.is_a?(Array) o.each { |x| x.after_unmarshal! if x.respond_to?(:after_unmarshal!) } else o.after_unmarshal! if o.respond_to?(:after_unmarshal!) end o end |
.managers ⇒ Object
147 148 149 150 151 |
# File 'lib/sup.rb', line 147 def managers %w(HookManager SentManager ContactManager LabelManager AccountManager DraftManager UpdateManager PollManager CryptoManager UndoManager SourceManager SearchManager IdleManager).map { |x| Redwood.const_get x.to_sym } end |
.record_exception(e, name) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/sup.rb', line 65 def record_exception e, name @exception_mutex.synchronize do @exceptions ||= [] @exceptions << [e, name] end end |
.report_broken_sources(opts = {}) ⇒ Object
not really a good place for this, so I’ll just dump it here.
a source error is either a FatalSourceError or an OutOfSyncSourceError. the superclass SourceError is just a generic.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/sup.rb', line 188 def report_broken_sources opts={} return unless BufferManager.instantiated? broken_sources = SourceManager.sources.select { |s| s.error.is_a? FatalSourceError } unless broken_sources.empty? BufferManager.spawn_unless_exists("Broken source notification for #{broken_sources.join(',')}", opts) do TextMode.new(<<EOM) Source error notification ------------------------- Hi there. It looks like one or more message sources is reporting errors. Until this is corrected, messages from these sources cannot be viewed, and new messages will not be detected. #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error..wrap(70).join("\n ")}.join("\n\n")} EOM #' stupid ruby-mode end end desynced_sources = SourceManager.sources.select { |s| s.error.is_a? OutOfSyncSourceError } unless desynced_sources.empty? BufferManager.spawn_unless_exists("Out-of-sync source notification for #{broken_sources.join(',')}", opts) do TextMode.new(<<EOM) Out-of-sync source notification ------------------------------- Hi there. It looks like one or more sources has fallen out of sync with my index. This can happen when you modify these sources with other email clients. (Sorry, I don't play well with others.) Until this is corrected, messages from these sources cannot be viewed, and new messages will not be detected. Luckily, this is easy to correct! #{desynced_sources.map do |s| "Source: " + s.to_s + "\n Error: " + s.error..wrap(70).join("\n ") + "\n Fix: sup-sync --changed #{s.to_s}" end} EOM #' stupid ruby-mode end end end |
.reporting_thread(name) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sup.rb', line 72 def reporting_thread name if $opts[:no_threads] yield else ::Thread.new do begin yield rescue Exception => e record_exception e, name end end end end |
.save_yaml_obj(o, fn, safe = false, backup = false) ⇒ Object
one-stop shop for yamliciousness
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/sup.rb', line 89 def save_yaml_obj o, fn, safe=false, backup=false o = if o.is_a?(Array) o.map { |x| (x.respond_to?(:before_marshal) && x.before_marshal) || x } elsif o.respond_to? :before_marshal o.before_marshal else o end mode = if File.exists? fn File.stat(fn).mode else 0600 end if backup backup_fn = fn + '.bak' if File.exists?(fn) && File.size(fn) > 0 File.open(backup_fn, "w", mode) do |f| File.open(fn, "r") { |old_f| FileUtils.copy_stream old_f, f } f.fsync end end File.open(fn, "w") do |f| f.puts o.to_yaml f.fsync end elsif safe safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}" File.open(safe_fn, "w", mode) do |f| f.puts o.to_yaml f.fsync end FileUtils.mv safe_fn, fn else File.open(fn, "w", mode) do |f| f.puts o.to_yaml f.fsync end end end |
.start ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/sup.rb', line 153 def start managers.each { |x| fail "#{x} already instantiated" if x.instantiated? } FileUtils.mkdir_p Redwood::BASE_DIR $config = load_config Redwood::CONFIG_FN @log_io = File.open(Redwood::LOG_FN, 'a') Redwood::Logger.add_sink @log_io Redwood::HookManager.init Redwood::HOOK_DIR Redwood::SentManager.init $config[:sent_source] || 'sup://sent' Redwood::ContactManager.init Redwood::CONTACT_FN Redwood::LabelManager.init Redwood::LABEL_FN Redwood::AccountManager.init $config[:accounts] Redwood::DraftManager.init Redwood::DRAFT_DIR Redwood::SearchManager.init Redwood::SEARCH_FN managers.each { |x| x.init unless x.instantiated? } end |