commit d41b344820efa9194dd8cb31164eb7d1e386dfe6
parent e3d1f3c323a9a0618c6ce3dcb7e956271d173cfb
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Fri, 23 Nov 2007 22:43:25 +0000
make which text is quoted a little more intelligent
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@711 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
5 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -20,10 +20,14 @@
## :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
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -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(", ")]) +
diff --git a/lib/sup/modes/forward-mode.rb b/lib/sup/modes/forward-mode.rb
@@ -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
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
@@ -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
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -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