lib/sup/message-chunks.rb in sup-0.7 vs lib/sup/message-chunks.rb in sup-0.8
- old
+ new
@@ -43,11 +43,14 @@
module Chunk
WRAP_LEN = 80 # wrap messages and text attachments at this width
class Attachment
HookManager.register "mime-decode", <<EOS
-Executes when decoding a MIME attachment.
+Decodes a MIME attachment into text form. The text will be displayed
+directly in Sup. For attachments that you wish to use a separate program
+to view (e.g. images), you should use the mime-view hook instead.
+
Variables:
content_type: the content-type of the message
filename: the filename of the attachment as saved to disk
sibling_types: if this attachment is part of a multipart MIME attachment,
an array of content-types for all attachments. Otherwise,
@@ -55,17 +58,26 @@
Return value:
The decoded text of the attachment, or nil if not decoded.
EOS
HookManager.register "mime-view", <<EOS
-Executes when viewing a MIME attachment, i.e., launching a separate
-viewer program.
+Views a non-text MIME attachment. This hook allows you to run
+third-party programs for attachments that require such a thing (e.g.
+images). To instead display a text version of the attachment directly in
+Sup, use the mime-decode hook instead.
+
+Note that by default (at least on systems that have a run-mailcap command),
+Sup uses the default mailcap handler for the attachment's MIME type. If
+you want a particular behavior to be global, you may wish to change your
+mailcap instead.
+
Variables:
content_type: the content-type of the attachment
filename: the filename of the attachment as saved to disk
Return value:
- True if the viewing was successful, false otherwise.
+ True if the viewing was successful, false otherwise. If false, calling
+ /usr/bin/run-mailcap will be tried.
EOS
#' stupid ruby-mode
## raw_content is the post-MIME-decode content. this is used for
## saving the attachment to disk.
@@ -85,11 +97,11 @@
end
text =
case @content_type
when /^text\/plain\b/
- Message.convert_from @raw_content, encoded_content.charset
+ Iconv.easy_decode $encoding, encoded_content.charset || $encoding, @raw_content
else
HookManager.run "mime-decode", :content_type => content_type,
:filename => lambda { write_to_disk },
:sibling_types => sibling_types
end
@@ -106,10 +118,10 @@
def patina_color; :attachment_color end
def patina_text
if expandable?
"Attachment: #{filename} (#{lines.length} lines)"
else
- "Attachment: #{filename} (#{content_type})"
+ "Attachment: #{filename} (#{content_type}; #{@raw_content.size.to_human_size})"
end
end
## an attachment is exapndable if we've managed to decode it into
## something we can display inline. otherwise, it's viewable.