class Redwood::Chunk::Attachment

Attributes

content_type[R]

#raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.

filename[R]

#raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.

lines[R]

#raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.

raw_content[R]

#raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.

Public Class Methods

new(content_type, filename, encoded_content, sibling_types) click to toggle source
# File lib/sup/message-chunks.rb, line 86
def initialize content_type, filename, encoded_content, sibling_types
  @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 %r^text\/plain\b/
    @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
    text = text.transcode(encoded_content.charset || $encoding)
    @lines = text.gsub("\r\n", "\n").gsub(%r\t/, "        ").gsub(%r\r/, "").split("\n")
    @quotable = true
  end
end

Public Instance Methods

color() click to toggle source
# File lib/sup/message-chunks.rb, line 116
def color; :none end
expandable?() click to toggle source
# File lib/sup/message-chunks.rb, line 129
def expandable?; !viewable? end
initial_state() click to toggle source
# File lib/sup/message-chunks.rb, line 130
def initial_state; :open end
inlineable?() click to toggle source

an attachment is exapndable if we've managed to decode it into something we can display inline. otherwise, it's viewable.

# File lib/sup/message-chunks.rb, line 128
def inlineable?; false end
patina_color() click to toggle source
# File lib/sup/message-chunks.rb, line 117
def patina_color; :attachment_color end
patina_text() click to toggle source
# File lib/sup/message-chunks.rb, line 118
def patina_text
  if expandable?
    "Attachment: #{filename} (#{lines.length} lines)"
  else
    "Attachment: #{filename} (#{content_type}; #{@raw_content.size.to_human_size})"
  end
end
to_s() click to toggle source

used when viewing the attachment as text

# File lib/sup/message-chunks.rb, line 159
def to_s
  @lines || @raw_content
end
view!() click to toggle source
# File lib/sup/message-chunks.rb, line 144
def view!
  path = write_to_disk
  ret = HookManager.run "mime-view", :content_type => @content_type,
                                     :filename => path
  ret || view_default!(path)
end
view_default!(path) click to toggle source
# File lib/sup/message-chunks.rb, line 132
def view_default! path
  case Config::CONFIG['arch']
    when %rdarwin/
      cmd = "open '#{path}'"
    else
      cmd = "/usr/bin/run-mailcap --action=view '#{@content_type}:#{path}'"
  end
  debug "running: #{cmd.inspect}"
  BufferManager.shell_out(cmd)
  $? == 0
end
viewable?() click to toggle source
# File lib/sup/message-chunks.rb, line 131
def viewable?; @lines.nil? end
write_to_disk() click to toggle source
# File lib/sup/message-chunks.rb, line 151
def write_to_disk
  file = Tempfile.new(@filename || "sup-attachment")
  file.print @raw_content
  file.close
  file.path
end