]> git.cworth.org Git - sup/commitdiff
Merge branch 'ncurses-fixes' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 6 Aug 2009 18:30:12 +0000 (14:30 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 6 Aug 2009 18:30:12 +0000 (14:30 -0400)
Conflicts:
bin/sup
lib/sup/buffer.rb

bin/sup
lib/sup/buffer.rb
lib/sup/ferret_index.rb
lib/sup/hook.rb
lib/sup/message-chunks.rb
lib/sup/message.rb

diff --git a/bin/sup b/bin/sup
index 2d5de6733fcdf76f1a58caa3d64aadce0c02c143..0e2260c210fd609feb1584f85a8300e0889b3952 100755 (executable)
--- a/bin/sup
+++ b/bin/sup
@@ -245,15 +245,16 @@ begin
 
     bm.erase_flash
 
-    action = begin
-      if bm.handle_input c
+    action =
+      begin
+        if bm.handle_input c
+          :nothing
+        else
+          bm.resolve_input_with_keymap c, global_keymap
+        end
+      rescue InputSequenceAborted
         :nothing
-      else
-        bm.resolve_input_with_keymap c, global_keymap
       end
-    rescue InputSequenceAborted
-      :nothing
-    end
     case action
     when :quit_now
       break if bm.kill_all_buffers_safely
index 5881febcf7e68c12df715d61baea7d05393232a9..b3a256fdfb79262bb98295a4c7366ccb4dd531e6 100644 (file)
@@ -25,6 +25,8 @@ module Ncurses
   def mutex; @mutex ||= Mutex.new; end
   def sync &b; mutex.synchronize(&b); end
 
+  ## magically, this stuff seems to work now. i could swear it didn't
+  ## before. hm.
   def nonblocking_getch
     ## INSANTIY
     ## it is NECESSARY to wrap Ncurses.getch in a select() otherwise all
@@ -70,7 +72,7 @@ class Buffer
   def content_height; @height - 1; end
   def content_width; @width; end
 
-  def resize rows, cols
+  def resize rows, cols 
     return if cols == @width && rows == @height
     @width = cols
     @height = rows
index f3d414770212e090d0ce03ff9b58a5a07df45233..98ea9b571806167cd5d3db69ad169714405278a0 100644 (file)
@@ -4,6 +4,16 @@ module Redwood
 
 class FerretIndex < BaseIndex
 
+  HookManager.register "custom-search", <<EOS
+Executes before a string search is applied to the index,
+returning a new search string.
+Variables:
+  subs: The string being searched. Be careful about shadowing:
+    this variable is actually a method, so use a temporary variable
+    or explicitly call self.subs; the substitutions in index.rb
+    don't actually work.
+EOS
+
   def initialize dir=BASE_DIR
     super
 
@@ -327,7 +337,9 @@ class FerretIndex < BaseIndex
   def parse_query s
     query = {}
 
-    subs = s.gsub(/\b(to|from):(\S+)\b/) do
+    subs = HookManager.run("custom-search", :subs => s) || s
+
+    subs = subs.gsub(/\b(to|from):(\S+)\b/) do
       field, name = $1, $2
       if(p = ContactManager.contact_for(name))
         [field, p.email]
index 0a0a2f672fca775e4bb792896537d2ec2535fac3..33a97b26063bffceb9f3d600962918b46106aa34 100644 (file)
@@ -19,6 +19,11 @@ class HookManager
 
     attr_writer :__locals
 
+    ## an annoying gotcha here is that if you try something
+    ## like var = var.foo(), var will magically get allocated
+    ## to Nil and method_missing will never get called.  You
+    ## can work around this by calling self.var or simply
+    ## not assigning it to itself.
     def method_missing m, *a
       case @__locals[m]
       when Proc
index 0d742d99e746a9ce96a4c11eddcd57506fcae22f..a9f1a77c5b5e5e3a1bd6435abcb3bb5965f4de6c 100644 (file)
@@ -208,13 +208,25 @@ EOS
 
   class EnclosedMessage
     attr_reader :lines
-    def initialize from, body
-      @from = from
-      @lines = body.split "\n"
-    end
+    def initialize from, to, cc, date, subj
+      @from = from ? "unknown sender" : from.full_adress
+      @to = to ? "" : to.map { |p| p.full_address }.join(", ")
+      @cc = cc ? "" : cc.map { |p| p.full_address }.join(", ")
+      if date
+        @date = date.rfc822
+      else
+        @date = ""
+      end
 
-    def from
-      @from ? @from.longname : "unknown sender"
+      @subj = subj
+
+      @lines = "\nFrom: #{from}\n"
+      @lines += "To: #{to}\n"
+      if !cc.empty?
+        @lines += "Cc: #{cc}\n"
+      end
+      @lines += "Date: #{date}\n"
+      @lines += "Subject: #{subj}\n\n"
     end
 
     def inlineable?; false end
@@ -224,7 +236,7 @@ EOS
     def viewable?; false end
 
     def patina_color; :generic_notice_patina_color end
-    def patina_text; "Begin enclosed message from #{from} (#{@lines.length} lines)" end
+    def patina_text; "Begin enclosed message sent on #{@date}" end
 
     def color; :quote_color end
   end
index 7c6374651e379ea0947caf7072390bba6d981eb3..29999863ebbfa8bf73eb2ce1e26a6a7e838ce99d 100644 (file)
@@ -404,10 +404,19 @@ private
       chunks
     elsif m.header.content_type == "message/rfc822"
       payload = RMail::Parser.read(m.body)
-      from = payload.header.from.first
-      from_person = from ? Person.from_address(from.format) : nil
-      [Chunk::EnclosedMessage.new(from_person, payload.to_s)] +
-        message_to_chunks(payload, encrypted)
+      from = payload.header.from.first ? payload.header.from.first.format : ""
+      to = payload.header.to.map { |p| p.format }.join(", ")
+      cc = payload.header.cc.map { |p| p.format }.join(", ")
+      subj = payload.header.subject
+      subj = subj ? Message.normalize_subj(payload.header.subject.gsub(/\s+/, " ").gsub(/\s+$/, "")) : subj
+      if Rfc2047.is_encoded? subj
+        subj = Rfc2047.decode_to $encoding, subj
+      end
+      msgdate = payload.header.date
+      from_person = from ? Person.from_address(from) : nil
+      to_people = to ? Person.from_address_list(to) : nil
+      cc_people = cc ? Person.from_address_list(cc) : nil
+      [Chunk::EnclosedMessage.new(from_person, to_people, cc_people, msgdate, subj)] + message_to_chunks(payload, encrypted)
     else
       filename =
         ## first, paw through the headers looking for a filename