lib/sup/message-chunks.rb in sup-0.2 vs lib/sup/message-chunks.rb in sup-0.3
- old
+ new
@@ -18,14 +18,18 @@
## 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.
+##
+## 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
class Attachment
HookManager.register "mime-decode", <<EOS
@@ -43,14 +47,16 @@
#' stupid ruby-mode
## 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
else
"For some bizarre reason, RubyMail was unable to parse this attachment.\n"
@@ -62,11 +68,14 @@
Message.convert_from(@raw_content, encoded_content.charset).split("\n")
else
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
def color; :none end
def patina_color; :attachment_color end
@@ -84,11 +93,11 @@
def expandable?; !viewable? end
def initial_state; :open end
def viewable?; @lines.nil? end
def view!
path = write_to_disk
- system "/usr/bin/run-mailcap --action=view #{@content_type}:#{path} >& /dev/null"
+ system "/usr/bin/run-mailcap --action=view #{@content_type}:#{path} > /dev/null 2> /dev/null"
$? == 0
end
def write_to_disk
file = Tempfile.new "redwood.attachment"
@@ -109,14 +118,15 @@
attr_reader :lines
def initialize lines
@lines = lines.map { |l| l.chomp.wrap WRAP_LEN }.flatten # wrap
## trim off all empty lines except one
- lines.pop while lines.last =~ /^\s*$/
+ @lines.pop while @lines.length > 1 && @lines[-1] =~ /^\s*$/ && @lines[-2] =~ /^\s*$/
end
def inlineable?; true end
+ def quotable?; true end
def expandable?; false end
def viewable?; false end
def color; :none end
end
@@ -125,10 +135,11 @@
def initialize lines
@lines = lines
end
def inlineable?; @lines.length == 1 end
+ def quotable?; true end
def expandable?; !inlineable? end
def viewable?; false end
def patina_color; :quote_patina_color end
def patina_text; "(#{lines.length} quoted lines)" end
@@ -140,10 +151,11 @@
def initialize lines
@lines = lines
end
def inlineable?; @lines.length == 1 end
+ def quotable?; false end
def expandable?; !inlineable? end
def viewable?; false end
def patina_color; :sig_patina_color end
def patina_text; "(#{lines.length}-line signature)" end
@@ -160,10 +172,11 @@
def from
@from ? @from.longname : "unknown sender"
end
def inlineable?; false end
+ def quotable?; false end
def expandable?; true end
def initial_state; :open end
def viewable?; false end
def patina_color; :generic_notice_patina_color end
@@ -189,9 +202,10 @@
end
end
def color; patina_color end
def inlineable?; false end
+ def quotable?; false end
def expandable?; !@lines.empty? end
def viewable?; false end
end
end
end