]> git.cworth.org Git - sup/blobdiff - lib/sup/message-chunks.rb
for message/rfc822 attachments, handle the case of no From: address (weird...)
[sup] / lib / sup / message-chunks.rb
index e96dab408240ebf331c263e829e6fd24dfaebd3b..6da21aac4629fa1da44cdd4873e7a30b40d8e510 100644 (file)
@@ -5,7 +5,7 @@
 ## notices like "this message was decrypted" or "this message contains
 ## a valid signature"---basically, anything we want to differentiate
 ## at display time.
-
+##
 ## A chunk can be inlineable, expandable, or viewable. If it's
 ## inlineable, #color and #lines are called and the output is treated
 ## as part of the message text. This is how Text and one-line Quotes
 ## #patina_text are called to generate a "patina" (a one-line widget,
 ## basically), and the user can press enter to toggle the display of
 ## the chunk content, which is generated from #color and #lines as
-## above. This is how Quote, Signature, and most widgets work.
+## above. This is how Quote, Signature, and most widgets
+## work. Exandable chunks can additionally define #initial_state to be
+## :open if they want to start expanded (default is to start collapsed).
 ##
 ## If it's not expandable but is viewable, a patina is displayed using
-## #patina_color and #patina_text, but no toggling is allowed. Instead,
-## if #view! is defined, pressing enter on the widget calls view! and
-## (if that returns false) #to_s. Otherwise, enter does nothing. This
-## is how non-inlineable attachments work.
+###patina_color and #patina_text, but no toggling is allowed. Instead,
+##if #view! is defined, pressing enter on the widget calls view! and
+##(if that returns false) #to_s. Otherwise, enter does nothing. This
+##is how non-inlineable attachments work.
 
 module Redwood
 module Chunk
@@ -75,6 +77,7 @@ EOS
     ## something we can display inline. otherwise, it's viewable.
     def inlineable?; false end
     def expandable?; !viewable? end
+    def initial_state; :open end
     def viewable?; @lines.nil? end
     def view!
       path = write_to_disk
@@ -106,8 +109,10 @@ EOS
       lines.pop while lines.last =~ /^\s*$/ 
     end
 
-    def color; :none end
     def inlineable?; true end
+    def expandable?; false end
+    def viewable?; false end
+    def color; :none end
   end
 
   class Quote
@@ -118,6 +123,8 @@ EOS
     
     def inlineable?; @lines.length == 1 end
     def expandable?; !inlineable? end
+    def viewable?; false end
+
     def patina_color; :quote_patina_color end
     def patina_text; "(#{lines.length} quoted lines)" end
     def color; :quote_color end
@@ -131,23 +138,31 @@ EOS
 
     def inlineable?; @lines.length == 1 end
     def expandable?; !inlineable? end
+    def viewable?; false end
+
     def patina_color; :sig_patina_color end
     def patina_text; "(#{lines.length}-line signature)" end
     def color; :sig_color end
   end
 
-  class EnclosedMessageNotice
-    attr_reader :from, :lines
+  class EnclosedMessage
+    attr_reader :lines
     def initialize from, body
       @from = from
       @lines = body.split "\n"
     end
 
+    def from
+      @from ? @from.longname : "unknown sender"
+    end
+
     def inlineable?; false end
     def expandable?; true end
+    def initial_state; :open end
+    def viewable?; false end
 
     def patina_color; :generic_notice_patina_color end
-    def patina_text; "Begin enclosed message from #{@from.longname} (#{@lines.length} lines)" end
+    def patina_text; "Begin enclosed message from #{from} (#{@lines.length} lines)" end
 
     def color; :quote_color end
   end