]> git.cworth.org Git - sup/commitdiff
minor code style tweaks and whitespace removals
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 3 Aug 2009 16:27:14 +0000 (12:27 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 17 Aug 2009 18:46:30 +0000 (14:46 -0400)
14 files changed:
bin/sup
bin/sup-sync
bin/sup-sync-back
bin/sup-tweak-labels
lib/sup.rb
lib/sup/buffer.rb
lib/sup/crypto.rb
lib/sup/mbox/loader.rb
lib/sup/modes/scroll-mode.rb
lib/sup/modes/text-mode.rb
lib/sup/poll.rb
lib/sup/source.rb
lib/sup/thread.rb
lib/sup/util.rb

diff --git a/bin/sup b/bin/sup
index 1febefdd5bc0e06e033f6da7a86d1f5bdf2e710f..786fba2dadf6f0257b595a51c8a4e9c1d7c249e6 100755 (executable)
--- a/bin/sup
+++ b/bin/sup
@@ -200,7 +200,7 @@ begin
       end
     end
   end unless $opts[:no_initial_poll]
-  
+
   imode.load_threads :num => ibuf.content_height, :when_done => lambda { |num| reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] }
 
   if $opts[:compose]
index a8cb768094e920009ae5c3bc3112d43307e1f613..d445bd806f16b6254cbb38fce4a662191514b5a0 100755 (executable)
@@ -9,9 +9,7 @@ PROGRESS_UPDATE_INTERVAL = 15 # seconds
 
 class Float
   def to_s; sprintf '%.2f', self; end
-   def to_time_s
-     infinite? ? "unknown" : super
-   end
+  def to_time_s; infinite? ? "unknown" : super end
 end
 
 class Numeric
index adadcb34f03e19e5718ed5c8b8f07583549dc16f..7635274a90c759fecd2e3a1eb86e9f0c2a035938 100755 (executable)
@@ -108,7 +108,7 @@ EOS
 
     source.reset!
     num_dropped = num_moved = num_scanned = 0
-    
+
     out_fp = Tempfile.new "sup-sync-back-#{source.id}"
     Redwood::PollManager.each_message_from source do |m|
       num_scanned += 1
index b2c6b1d7c6b33c4163d40c53a836bfc4055b20e0..c9ad8e82d4c945381678a8e2ab1ebb3524cb7356 100755 (executable)
@@ -38,8 +38,8 @@ be seen by running "sup-add --help".
 
 Options:
 EOS
-  opt :add, "One or more labels (comma-separated) to add to every message from the specified sources", :type => String
-  opt :remove, "One or more labels (comma-separated) to remove from every message from the specified sources, if those labels are present", :type => String
+  opt :add, "One or more labels (comma-separated) to add to every message from the specified sources", :default => ""
+  opt :remove, "One or more labels (comma-separated) to remove from every message from the specified sources, if those labels are present", :default => ""
   opt :query, "A Sup search query", :type => String
 
   text <<EOS
@@ -64,13 +64,12 @@ begin
   index = Redwood::Index.new
   index.load
 
-  source_ids = 
-    if opts[:all_sources]
-      Redwood::SourceManager.sources
-    else
-      ARGV.map do |uri|
-        Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
-      end
+  source_ids = if opts[:all_sources]
+    Redwood::SourceManager.sources
+  else
+    ARGV.map do |uri|
+      Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
+    end
   end.map { |s| s.id }
   Trollop::die "nothing to do: no sources" if source_ids.empty?
 
index 54de73f5597f1e2f752f07a00694d39de547880b..710dca1522e2f6651fd4fe2ad0014f72fdbc46a9 100644 (file)
@@ -24,7 +24,7 @@ class Module
     vars = props.map { |p| "@#{p}" }
     klass = self
     path = klass.name.gsub(/::/, "/")
-    
+
     klass.instance_eval do
       define_method(:to_yaml_properties) { vars }
       define_method(:to_yaml_type) { "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" }
index 3266473a5c1b0e3bd1a14d5dbebf45244814ac35..3bd3fe8e96a1563ff3ae4fa748b80203a1320cb8 100644 (file)
@@ -468,7 +468,7 @@ EOS
     end
 
     if answer
-      answer = 
+      answer =
         if answer.empty?
           spawn_modal "file browser", FileBrowserMode.new
         elsif File.directory?(answer)
@@ -508,7 +508,7 @@ EOS
   def ask_for_contacts domain, question, default_contacts=[]
     default = default_contacts.map { |s| s.to_s }.join(" ")
     default += " " unless default.empty?
-    
+
     recent = Index.load_contacts(AccountManager.user_emails, :num => 10).map { |c| [c.full_address, c.email] }
     contacts = ContactManager.contacts.map { |c| [ContactManager.alias_for(c), c.full_address, c.email] }
 
index 8ec277b862603fb23d94a60d3fa19fd60ee0fd0f..f68009d91bd7b5e42ce6216e4a3bad12335d03f6 100644 (file)
@@ -116,21 +116,19 @@ class CryptoManager
     output = run_gpg "--decrypt #{payload_fn.path}"
 
     if $?.success?
-      decrypted_payload, sig_lines =
-        if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
-          [$1, $2]
+      decrypted_payload, sig_lines = if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
+        [$1, $2]
+      else
+        [output, nil]
+      end
+
+      sig = if sig_lines # encrypted & signed
+        if sig_lines =~ /^gpg: (Good signature from .*$)/
+          Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
         else
-          [output, nil]
-        end
-      
-      sig = 
-        if sig_lines # encrypted & signed
-          if sig_lines =~ /^gpg: (Good signature from .*$)/
-            Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
-          else
-            Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
-          end
+          Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
         end
+      end
 
       notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
       [RMail::Parser.read(decrypted_payload), sig, notice]
@@ -145,7 +143,7 @@ private
   def unknown_status lines=[]
     Chunk::CryptoNotice.new :unknown, "Unable to determine validity of cryptographic signature", lines
   end
-  
+
   def cant_find_binary
     ["Can't find gpg binary in path."]
   end
index f35c7df8f37b489fb38ebb8827e2d9e50a1985de..26177f76bb12041c7cbfee16414f656a6dd15afc 100644 (file)
@@ -47,7 +47,7 @@ class Loader < Source
       raise OutOfSyncSourceError, "mbox file is smaller than last recorded message offset. Messages have probably been deleted by another client."
     end
   end
-    
+
   def start_offset; 0; end
   def end_offset; File.size @f; end
 
index 63b48ec00edd6e7b7cc50bd82b51d8b00c7c7ed9..c13142599e9aed1aaad9bde0c1a029b2331fa72e 100644 (file)
@@ -3,7 +3,7 @@ module Redwood
 class ScrollMode < Mode
   ## we define topline and botline as the top and bottom lines of any
   ## content in the currentview.
-  
+
   ## we left leftcol and rightcol as the left and right columns of any
   ## content in the current view. but since we're operating in a
   ## line-centric fashion, rightcol is always leftcol + the buffer
@@ -223,7 +223,7 @@ protected
       raise "nil text for color '#{color}'" if text.nil? # good for debugging
       l = text.display_length
       no_fill = i != a.size - 1
-      
+
       if xpos + l < @leftcol
         buffer.write ln - @topline, 0, "", :color => color,
                      :highlight => opts[:highlight]
index 273c02850f9cbc331d51dfb62a00ca05fbe9703d..7c9e7d87c0c1c6da3bf4e0b3634138ce6880aedd 100644 (file)
@@ -14,7 +14,7 @@ class TextMode < ScrollMode
     buffer.mark_dirty if buffer
     super()
   end
-  
+
   def save_to_disk
     fn = BufferManager.ask_for_filename :filename, "Save to file: ", @filename
     save_to_file(fn) { |f| f.puts text } if fn
@@ -50,7 +50,7 @@ class TextMode < ScrollMode
     @lines << @text.length
     if buffer
       ensure_mode_validity
-      buffer.mark_dirty 
+      buffer.mark_dirty
     end
   end
 
index 0c8f51d3f6feb3319f591f1617369c84132152ef..4374242cefe39af7682b1db80f34f9ac0a06dedf 100644 (file)
@@ -35,7 +35,7 @@ EOS
     @thread = nil
     @last_poll = nil
     @polling = false
-    
+
     self.class.i_am_the_instance self
   end
 
index 1bb77973f0d609d6441c726ada6c7b2236a28d03..fb9089fc37dab718eaead5d0aaab65c0a4b3d41d 100644 (file)
@@ -34,12 +34,12 @@ class Source
   ## To write a new source, subclass this class, and implement:
   ##
   ## - start_offset
-  ## - end_offset (exclusive!)
+  ## - end_offset (exclusive!) (or, #done?)
   ## - load_header offset
   ## - load_message offset
   ## - raw_header offset
   ## - raw_message offset
-  ## - check
+  ## - check (optional)
   ## - next (or each, if you prefer): should return a message and an
   ##   array of labels.
   ##
@@ -78,6 +78,7 @@ class Source
     @dirty = false
   end
 
+  ## overwrite me if you have a disk incarnation (currently used only for sup-sync-back)
   def file_path; nil end
 
   def to_s; @uri.to_s; end
@@ -92,20 +93,23 @@ class Source
   ## to proactively notify the user of any source problems.
   def check; end
 
+  ## yields successive offsets and labels, starting at #cur_offset.
+  ##
+  ## when implementing a source, you can overwrite either #each or #next. the
+  ## default #each just calls next over and over.
   def each
     self.cur_offset ||= start_offset
     until done?
-      n, labels = self.next
-      raise "no message" unless n
-      yield n, labels
+      offset, labels = self.next
+      yield offset, labels
     end
   end
 
-  ## read a raw email header from a filehandle (or anything that responds to
-  ## #gets), and turn it into a hash of key-value pairs.
+  ## utility method to read a raw email header from an IO stream and turn it
+  ## into a hash of key-value pairs. minor special semantics for certain headers.
   ##
-  ## WARNING! THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have
-  ## significant effect on Sup's processing speed of email from ALL sources.
+  ## THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have a
+  ## significant effect on Sup's processing speed of email from ALL sources.
   ## Little things like string interpolation, regexp interpolation, += vs <<,
   ## all have DRAMATIC effects. BE CAREFUL WHAT YOU DO!
   def self.parse_raw_email_header f
@@ -116,9 +120,11 @@ class Source
       case line
       ## these three can occur multiple times, and we want the first one
       when /^(Delivered-To|X-Original-To|Envelope-To):\s*(.*?)\s*$/i; header[last = $1.downcase] ||= $2
-      ## mark this guy specially. not sure why i care.
+      ## regular header: overwrite (not that we should see more than one)
+      ## TODO: figure out whether just using the first occurrence changes
+      ## anything (which would simplify the logic slightly)
       when /^([^:\s]+):\s*(.*?)\s*$/i; header[last = $1.downcase] = $2
-      when /^\r*$/; break
+      when /^\r*$/; break # blank line signifies end of header
       else
         if last
           header[last] << " " unless header[last].empty?
@@ -144,7 +150,7 @@ protected
 
   ## convenience function
   def parse_raw_email_header f; self.class.parse_raw_email_header f end
-  
+
   def Source.expand_filesystem_uri uri
     uri.gsub "~", File.expand_path("~")
   end
index 81ce7e8c81e68553c9e415aa51949a898c1f98c5..ca3f30d08cffabdab36225ac68e274fd5092184c 100644 (file)
@@ -103,15 +103,14 @@ class Thread
   def toggle_label label
     if has_label? label
       remove_label label
-      return false
+      false
     else
       apply_label label
-      return true
+      true
     end
   end
 
   def set_labels l; each { |m, *o| m && m.labels = l }; end
-  
   def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end
   def save_state index; each { |m, *o| m && m.save_state(index) }; end
 
@@ -132,7 +131,7 @@ class Thread
   end
 
   def latest_message
-    inject(nil) do |a, b| 
+    inject(nil) do |a, b|
       b = b.first
       if a.nil?
         b
@@ -163,7 +162,7 @@ class Container
     @id = id
     @message, @parent, @thread = nil, nil, nil
     @children = []
-  end      
+  end
 
   def each_with_stuff parent=nil
     yield self, 0, parent
index c3cc4b223b059aa5854d2161526423dbfd315d5b..5776d7e384d1749e6e6af8c5cd9ed7e10d985763 100644 (file)
@@ -216,8 +216,8 @@ class String
       newpos = case state
         when :escaped_instring, :escaped_outstring then pos
         else index(/[,"\\]/, pos)
-      end 
-      
+      end
+
       if newpos
         char = self[newpos]
       else
@@ -542,7 +542,7 @@ class Recoverable
   def has_errors?; !@error.nil?; end
 
   def method_missing m, *a, &b; __pass m, *a, &b end
-  
+
   def id; __pass :id; end
   def to_s; __pass :to_s; end
   def to_yaml x; __pass :to_yaml, x; end