lib/sup/message-chunks.rb in sup-0.8.1 vs lib/sup/message-chunks.rb in sup-0.9
- old
+ new
@@ -48,11 +48,12 @@
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
+ content_type: the content-type of the attachment
+ charset: the charset of the attachment, if applicable
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,
the empty array.
Return value:
@@ -83,30 +84,30 @@
## 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
+ @content_type = content_type.downcase
@filename = filename
@quotable = false # changed to true if we can parse it through the
# mime-decode hook, or if it's plain text
@raw_content =
if encoded_content.body
encoded_content.decode
else
"For some bizarre reason, RubyMail was unable to parse this attachment.\n"
end
- text =
- case @content_type
- when /^text\/plain\b/
- 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
+ text = case @content_type
+ when /^text\/plain\b/
+ Iconv.easy_decode $encoding, encoded_content.charset || $encoding, @raw_content
+ else
+ HookManager.run "mime-decode", :content_type => content_type,
+ :filename => lambda { write_to_disk },
+ :charset => encoded_content.charset,
+ :sibling_types => sibling_types
+ end
@lines = nil
if text
@lines = text.gsub("\r\n", "\n").gsub(/\t/, " ").gsub(/\r/, "").split("\n")
@lines = lines.map {|l| l.chomp.wrap WRAP_LEN}.flatten
@@ -129,13 +130,13 @@
def inlineable?; false end
def expandable?; !viewable? end
def initial_state; :open end
def viewable?; @lines.nil? end
def view_default! path
- cmd = "/usr/bin/run-mailcap --action=view '#{@content_type}:#{path}' 2>/dev/null"
- Redwood::log "running: #{cmd.inspect}"
- system cmd
+ cmd = "/usr/bin/run-mailcap --action=view '#{@content_type}:#{path}'"
+ debug "running: #{cmd.inspect}"
+ BufferManager.shell_out(cmd)
$? == 0
end
def view!
path = write_to_disk
@@ -206,27 +207,39 @@
def color; :sig_color end
end
class EnclosedMessage
attr_reader :lines
- def initialize from, body
- @from = from
- @lines = body.split "\n"
- end
+ def initialize from, to, cc, date, subj
+ @from = from ? "unknown sender" : from.full_adress
+ @to = to ? "" : to.map { |p| p.full_address }.join(", ")
+ @cc = cc ? "" : cc.map { |p| p.full_address }.join(", ")
+ if date
+ @date = date.rfc822
+ else
+ @date = ""
+ end
- def from
- @from ? @from.longname : "unknown sender"
+ @subj = subj
+
+ @lines = "\nFrom: #{from}\n"
+ @lines += "To: #{to}\n"
+ if !cc.empty?
+ @lines += "Cc: #{cc}\n"
+ end
+ @lines += "Date: #{date}\n"
+ @lines += "Subject: #{subj}\n\n"
end
def inlineable?; false end
def quotable?; false end
def expandable?; true end
def initial_state; :closed end
def viewable?; false end
def patina_color; :generic_notice_patina_color end
- def patina_text; "Begin enclosed message from #{from} (#{@lines.length} lines)" end
+ def patina_text; "Begin enclosed message sent on #{@date}" end
def color; :quote_color end
end
class CryptoNotice
@@ -238,11 +251,11 @@
@lines = lines
end
def patina_color
case status
- when :valid: :cryptosig_valid_color
- when :invalid: :cryptosig_invalid_color
+ when :valid then :cryptosig_valid_color
+ when :invalid then :cryptosig_invalid_color
else :cryptosig_unknown_color
end
end
def color; patina_color end