]> git.cworth.org Git - sup/commitdiff
make which text is quoted a little more intelligent
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Fri, 23 Nov 2007 22:43:25 +0000 (22:43 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Fri, 23 Nov 2007 22:43:25 +0000 (22:43 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@711 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/message-chunks.rb
lib/sup/message.rb
lib/sup/modes/forward-mode.rb
lib/sup/modes/reply-mode.rb
lib/sup/modes/thread-view-mode.rb

index d243cdaf7d6b07a70925667f9383b76981e6db33..309577dc234260255d598c4f64c253138cd1d8b3 100644 (file)
 ## :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.
+##
+## Independent of all that, a chunk can be quotable, in which case it's
+## included as quoted text during a reply. Text, Quotes, and mime-parsed
+## attachments are quotable; Signatures are not.
 
 module Redwood
 module Chunk
@@ -45,10 +49,12 @@ EOS
     ## raw_content is the post-MIME-decode content. this is used for
     ## saving the attachment to disk.
     attr_reader :content_type, :filename, :lines, :raw_content
+    bool_reader :quotable
 
     def initialize content_type, filename, encoded_content, sibling_types
       @content_type = content_type
       @filename = filename
+      @quotable = false # only quotable if we can parse it through the mime-decode hook
       @raw_content =
         if encoded_content.body
           encoded_content.decode
@@ -64,7 +70,10 @@ EOS
           text = HookManager.run "mime-decode", :content_type => content_type,
                                  :filename => lambda { write_to_disk },
                                  :sibling_types => sibling_types
-          text.split("\n") if text
+          if text
+            @quotable = true
+            text.split("\n")
+          end
         end
     end
 
@@ -115,6 +124,7 @@ EOS
     end
 
     def inlineable?; true end
+    def quotable?; true end
     def expandable?; false end
     def viewable?; false end
     def color; :none end
@@ -127,6 +137,7 @@ EOS
     end
     
     def inlineable?; @lines.length == 1 end
+    def quotable?; true end
     def expandable?; !inlineable? end
     def viewable?; false end
 
@@ -142,6 +153,7 @@ EOS
     end
 
     def inlineable?; @lines.length == 1 end
+    def quotable?; false end
     def expandable?; !inlineable? end
     def viewable?; false end
 
@@ -162,6 +174,7 @@ EOS
     end
 
     def inlineable?; false end
+    def quotable?; false end
     def expandable?; true end
     def initial_state; :open end
     def viewable?; false end
@@ -191,6 +204,7 @@ EOS
     def color; patina_color end
 
     def inlineable?; false end
+    def quotable?; false end
     def expandable?; !@lines.empty? end
     def viewable?; false end
   end
index ca7efad4cd0d4d25d734978abe61d6414decca80..0ef1a615438a0fce9fa0f4bb2721af13917566b2 100644 (file)
@@ -228,11 +228,11 @@ EOS
     ].flatten.compact.join " "
   end
 
-  def basic_body_lines
-    chunks.find_all { |c| c.is_a?(Chunk::Text) || c.is_a?(Chunk::Quote) }.map { |c| c.lines }.flatten
+  def quotable_body_lines
+    chunks.find_all { |c| c.quotable? }.map { |c| c.lines }.flatten
   end
 
-  def basic_header_lines
+  def quotable_header_lines
     ["From: #{@from.full_address}"] +
       (@to.empty? ? [] : ["To: " + @to.map { |p| p.full_address }.join(", ")]) +
       (@cc.empty? ? [] : ["Cc: " + @cc.map { |p| p.full_address }.join(", ")]) +
index c513d3ed7c6392d30f3b92c31748f1ae4675e3eb..6a94877e787d950fbdcb158ecc9f0448638d70cd 100644 (file)
@@ -32,7 +32,7 @@ protected
 
   def forward_body_lines m
     ["--- Begin forwarded message from #{m.from.mediumname} ---"] + 
-      m.basic_header_lines + [""] + m.basic_body_lines +
+      m.quotable_header_lines + [""] + m.quotable_body_lines +
       ["--- End forwarded message ---"]
   end
 end
index 48bf66acd476cbe8641532f51b71256aeb9c8757..4f1c3344c3be270bfa7c2db8d1e8dcc8a13ca78f 100644 (file)
@@ -110,8 +110,7 @@ class ReplyMode < EditMessageMode
 protected
 
   def reply_body_lines m
-    lines = ["Excerpts from #{@m.from.name}'s message of #{@m.date}:"] + 
-      m.basic_body_lines.map { |l| "> #{l}" }
+    lines = ["Excerpts from #{@m.from.name}'s message of #{@m.date}:"] + m.quotable_body_lines.map { |l| "> #{l}" }
     lines.pop while lines.last =~ /^\s*$/
     lines
   end
index 88c512529f148bb9a2b9e5c4e3635cc587b997e1..59671483c5ee7005f45a2d95b5ba664363c0ff8c 100644 (file)
@@ -212,7 +212,7 @@ class ThreadViewMode < LineCursorMode
 
   def edit_as_new
     m = @message_lines[curpos] or return
-    mode = ComposeMode.new(:body => m.basic_body_lines, :to => m.to, :cc => m.cc, :subj => m.subj, :bcc => m.bcc)
+    mode = ComposeMode.new(:body => m.quotable_body_lines, :to => m.to, :cc => m.cc, :subj => m.subj, :bcc => m.bcc)
     BufferManager.spawn "edit as new", mode
     mode.edit_message
   end