]> git.cworth.org Git - sup/commitdiff
Merge branch 'speedy-index' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Fri, 29 Feb 2008 01:21:52 +0000 (17:21 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Fri, 29 Feb 2008 01:21:52 +0000 (17:21 -0800)
15 files changed:
bin/sup
bin/sup-sync-back
doc/FAQ.txt
lib/sup/crypto.rb
lib/sup/hook.rb
lib/sup/index.rb
lib/sup/mbox.rb
lib/sup/mbox/loader.rb
lib/sup/message.rb
lib/sup/modes/inbox-mode.rb
lib/sup/modes/scroll-mode.rb
lib/sup/modes/thread-index-mode.rb
lib/sup/poll.rb
lib/sup/sent.rb
lib/sup/thread.rb

diff --git a/bin/sup b/bin/sup
index 84fd77c5d07df9b2fc4f16b09cfa17dced6cfbec..45db505120c30fb65127df0b3846b03d6bde69fa 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -39,6 +39,12 @@ EOS
   opt :compose, "Compose message to this recipient upon startup", :type => String
 end
 
+Redwood::HookManager.register "startup", <<EOS
+Executes at startup
+No variables.
+No return value.
+EOS
+
 if $opts[:list_hooks]
   Redwood::HookManager.print_hooks
   exit
@@ -128,6 +134,8 @@ begin
     Index.add_source SentManager.new_source
   end
 
+  HookManager.run "startup"
+
   log "starting curses"
   start_cursing
 
@@ -138,6 +146,8 @@ begin
            Ncurses::A_BOLD
     c.add :index_starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK, 
            Ncurses::A_BOLD
+    c.add :index_draft_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
+           Ncurses::A_BOLD
     c.add :labellist_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
     c.add :labellist_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK, 
            Ncurses::A_BOLD
index 57bebbe839d0ad638dd003e35f868a8aeb1458b2..4216cf9e46f5db3c595b72edb8462f15bb0fe966 100644 (file)
@@ -51,7 +51,11 @@ EOS
 end
 
 unless opts[:drop_deleted] || opts[:move_deleted] || opts[:drop_spam] || opts[:move_spam]
-  puts "Nothing to do."
+  puts <<EOS
+Nothing to do. Please specify at least one of --drop-deleted, --move-deleted,
+--drop-spam, or --move-spam.
+EOS
+
   exit
 end
 
index 3b65330feaf44344d4c4e826cbf12859ad3b1a80..5c85d9c55346f37221dd7ad47ccecf0f483d0946 100644 (file)
@@ -111,7 +111,7 @@ S: The current solution is to directly modify RubyMail. Change line 159 of
    multipart.rb to:
      chunk = chunk[0..start]
    This is because RubyMail hasn't been updated since like Ruby 1.8.2.
-   Please bug Matt Lickey.
+   Please bug Matt Armstrong.
 
 P: I see this error:
      /usr/local/lib/ruby/1.8/yaml.rb:133:in `transfer': allocator undefined for Bignum (TypeError)
index 9e16132304ebad107b8cab43c0706de82b6e1a78..ee0695862415939120b262d4d4cec2e1ec2f214e 100644 (file)
@@ -40,7 +40,7 @@ class CryptoManager
     raise Error, (output || "gpg command failed: #{cmd}") unless $?.success?
 
     envelope = RMail::Message.new
-    envelope.header["Content-Type"] = 'multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1'
+    envelope.header["Content-Type"] = 'multipart/signed; protocol=application/pgp-signature; micalg=pgp-sha1'
 
     envelope.add_part payload
     signature = RMail::Message.make_attachment output, "application/pgp-signature", nil, "signature.asc"
index 98fcf57bec51116ea85ba265a8117af868bbd1af..74ecfabefc6e69da993b203bbe2e4f717299ce38 100644 (file)
@@ -86,7 +86,7 @@ class HookManager
       log "error running hook: #{e.message}"
       log e.backtrace.join("\n")
       @hooks[name] = nil # disable it
-      BufferManager.flash "Error running hook: #{e.message}"
+      BufferManager.flash "Error running hook: #{e.message}" if BufferManager.instantiated?
     end
     context.__cleanup
     result
index 47b2bb599e1fdd6a3d9f4f71099ef4d1471a3d56..77bc74061f56408c813f524c8a7a10a92334f70d 100644 (file)
@@ -141,7 +141,7 @@ EOS
     else
       Redwood::log "creating index..."
       field_infos = Ferret::Index::FieldInfos.new :store => :yes
-      field_infos.add_field :message_id
+      field_infos.add_field :message_id, :index => :untokenized
       field_infos.add_field :source_id
       field_infos.add_field :source_info
       field_infos.add_field :date, :index => :untokenized
@@ -429,18 +429,7 @@ protected
   def parse_user_query_string s
     extraopts = {}
 
-    ## this is a little hacky, but it works, at least until ferret changes
-    ## its api. we parse the user query string with ferret twice: the first
-    ## time we just turn the resulting object back into a string, which has
-    ## the next effect of transforming the original string into a nice
-    ## normalized form with + and - instead of AND, OR, etc. then we do some
-    ## string substitutions which depend on this normalized form, re-parse
-    ## the string with Ferret, and return the resulting query object.
-
-    norms = @qparser.parse(s).to_s
-    Redwood::log "normalized #{s.inspect} to #{norms.inspect}" unless s == norms
-
-    subs = norms.gsub(/\b(to|from):(\S+)\b/) do
+    subs = s.gsub(/\b(to|from):(\S+)\b/) do
       field, name = $1, $2
       if(p = ContactManager.contact_for(name))
         [field, p.email]
@@ -510,7 +499,6 @@ protected
       subs = nil if chronic_failure
     end
     
-    Redwood::log "translated #{norms.inspect} to #{subs.inspect}" unless subs == norms
     if subs
       [@qparser.parse(subs), extraopts]
     else
index 0ce52fe24fd9ff8bbba19bea2141dfd8e4d4625d..0abedc099c671d27822e9235842844a94a489ba3 100644 (file)
@@ -20,26 +20,26 @@ module MBox
     ## when scanning over large mbox files.
     while(line = f.gets)
       case line
-      when /^(From):\s+(.*?)\s*$/i,
-        /^(To):\s+(.*?)\s*$/i,
-        /^(Cc):\s+(.*?)\s*$/i,
-        /^(Bcc):\s+(.*?)\s*$/i,
-        /^(Subject):\s+(.*?)\s*$/i,
-        /^(Date):\s+(.*?)\s*$/i,
-        /^(References):\s+(.*?)\s*$/i,
-        /^(In-Reply-To):\s+(.*?)\s*$/i,
-        /^(Reply-To):\s+(.*?)\s*$/i,
-        /^(List-Post):\s+(.*?)\s*$/i,
-        /^(List-Subscribe):\s+(.*?)\s*$/i,
-        /^(List-Unsubscribe):\s+(.*?)\s*$/i,
-        /^(Status):\s+(.*?)\s*$/i: header[last = $1] = $2
-      when /^(Message-Id):\s+(.*?)\s*$/i: header[mid_field = last = $1] = $2
+      when /^(From):\s*(.*?)\s*$/i,
+        /^(To):\s*(.*?)\s*$/i,
+        /^(Cc):\s*(.*?)\s*$/i,
+        /^(Bcc):\s*(.*?)\s*$/i,
+        /^(Subject):\s*(.*?)\s*$/i,
+        /^(Date):\s*(.*?)\s*$/i,
+        /^(References):\s*(.*?)\s*$/i,
+        /^(In-Reply-To):\s*(.*?)\s*$/i,
+        /^(Reply-To):\s*(.*?)\s*$/i,
+        /^(List-Post):\s*(.*?)\s*$/i,
+        /^(List-Subscribe):\s*(.*?)\s*$/i,
+        /^(List-Unsubscribe):\s*(.*?)\s*$/i,
+        /^(Status):\s*(.*?)\s*$/i: header[last = $1] = $2
+      when /^(Message-Id):\s*(.*?)\s*$/i: header[mid_field = last = $1] = $2
 
       ## these next three can occur multiple times, and we want the
       ## first one
-      when /^(Delivered-To):\s+(.*)$/i,
-        /^(X-Original-To):\s+(.*)$/i,
-        /^(Envelope-To):\s+(.*)$/i: header[last = $1] ||= $2
+      when /^(Delivered-To):\s*(.*)$/i,
+        /^(X-Original-To):\s*(.*)$/i,
+        /^(Envelope-To):\s*(.*)$/i: header[last = $1] ||= $2
 
       when /^$/: break
       when /^\S+: /: last = nil # some other header we don't care about
index a66d7b906004f57b612c4888bc3111c674906547..58f4fc7d8fefbf2379edf315e6bc97ad8cc187ea 100644 (file)
@@ -6,6 +6,7 @@ module MBox
 
 class Loader < Source
   yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels
+  attr_accessor :labels
 
   ## uri_or_fp is horrific. need to refactor.
   def initialize uri_or_fp, start_offset=nil, usual=true, archived=false, id=nil, labels=[]
@@ -147,7 +148,7 @@ class Loader < Source
     end
 
     self.cur_offset = next_offset
-    [returned_offset, (@labels + [:unread]).uniq]
+    [returned_offset, (self.labels + [:unread]).uniq]
   end
 end
 
index c06a03fa547a3d6c96dd19945fae0934b907c925..6a2a9c47a021e69003af0cad6a2f076fc9a1dd4a 100644 (file)
@@ -148,7 +148,7 @@ class Message
     @source.fn_for_offset @source_info
   end
 
-  def sanitize_message_id mid; mid.gsub(/\s/, "") end
+  def sanitize_message_id mid; mid.gsub(/\s+/, "")[0..254] end
 
   def save index
     return unless @dirty
index a2de13fc5b6717d36052741bba7341d7d8153525..f156b69fa55fc774619cebcee136a5a575cb5d95 100644 (file)
@@ -9,7 +9,7 @@ class InboxMode < ThreadIndexMode
   end
 
   def initialize
-    super [:inbox, :sent], { :label => :inbox, :skip_killed => true }
+    super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true }
     raise "can't have more than one!" if defined? @@instance
     @@instance = self
   end
index 74783e5a8c1007ed71cd08c8aca8db58416bdbe8..922bf92b46169f4d5e0dde916312c10588e0d2ec 100644 (file)
@@ -64,14 +64,14 @@ class ScrollMode < Mode
     end
 
     start = @search_line || search_start_line
-    line = find_text @search_query, start
+    line, col = find_text @search_query, start
     if line.nil? && (start > 0)
-      line = find_text @search_query, 0
+      line, col = find_text @search_query, 0
       BufferManager.flash "Search wrapped to top!" if line
     end
     if line
       @search_line = line + 1
-      search_goto_line line
+      search_goto_pos line, col, col + @search_query.length
       buffer.mark_dirty
     else
       BufferManager.flash "Not found!"
@@ -86,7 +86,13 @@ class ScrollMode < Mode
   end
 
   ## subclasses can override these two!
-  def search_goto_line line; jump_to_line line end
+  def search_goto_pos line, leftcol, rightcol
+    jump_to_line line
+
+    if rightcol > self.rightcol # if it's occluded...
+      jump_to_col [rightcol - buffer.content_width + 1, 0].max # move right
+    end
+  end
   def search_start_line; @topline end
 
   def col_left
@@ -144,9 +150,18 @@ protected
     (start_line ... lines).each do |i|
       case(s = self[i])
       when String
-        return i if s =~ regex
+        match = s =~ regex
+        return [i, match] if match
       when Array
-        return i if s.any? { |color, string| string =~ regex }
+        offset = 0
+        s.each do |color, string|
+          match = string =~ regex
+          if match
+            return [i, offset + match]
+          else
+            offset += string.length
+          end
+        end
       end
     end
     nil
index e24d7e0398b01601faca320bd3dde650f130f773..7a0b8150c455cc4df19cdb581e3ae9144cacd1e0 100644 (file)
@@ -655,7 +655,6 @@ protected
 
     date = t.date.to_nice_s
 
-    new = t.has_label?(:unread)
     starred = t.has_label?(:starred)
 
     ## format the from column
@@ -692,7 +691,9 @@ protected
     p = dp || t.participants.any? { |p| AccountManager.is_account? p }
 
     subj_color =
-      if new
+      if t.has_label?(:draft)
+        :index_draft_color
+      elsif t.has_label?(:unread)
         :index_new_color
       elsif starred
         :index_starred_color
index 2dd915011c26c8310a0290f5499c0f18b80e9d94..d32c893e76771873832595ec95c67fac0780a208 100644 (file)
@@ -156,7 +156,7 @@ EOS
 
           docid, entry = Index.load_entry_for_id m.id
           HookManager.run "before-add-message", :message => m
-          m = yield(m, offset, entry) or next
+          m = yield(m, offset, entry) or next if block_given?
           Index.sync_message m, docid, entry
           UpdateManager.relay self, :added, m unless entry
         rescue MessageFormatError => e
index 9c802d9673a4247cff3f0a999b262cfc8edc495e..ee843c7dc54837acbcc39daab851509037692bb0 100644 (file)
@@ -22,10 +22,9 @@ class SentManager
       yield f
     end
 
-    @source.each do |offset, labels|
-      m = Message.new :source => @source, :source_info => offset, :labels => @source.labels
-      Index.sync_message m
-      UpdateManager.relay self, :added, m
+    PollManager.add_messages_from(@source) do |m, o, e|
+      m.remove_label :unread
+      m
     end
   end
 end
index 09fbfbbab81d5f6d6814a3e96e166e73370b4bd3..f7fb39ed9b22c96dbf7999e82ef3ebf575360968 100644 (file)
@@ -259,7 +259,7 @@ class ThreadSet
     @thread_by_subj = thread_by_subj
   end
 
-  def thread_for_id mid; (c = @messages[mid]) && c.root.thread end
+  def thread_for_id mid; @messages.member?(mid) && @messages[mid].root.thread end
   def contains_id? id; @messages.member?(id) && !@messages[id].empty? end
   def thread_for m; thread_for_id m.id end
   def contains? m; contains_id? m.id end