Class: Redwood::Chunk::Attachment
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
raw_content is the post-MIME-decode content.
-
#filename ⇒ Object
readonly
raw_content is the post-MIME-decode content.
-
#lines ⇒ Object
readonly
raw_content is the post-MIME-decode content.
-
#raw_content ⇒ Object
readonly
raw_content is the post-MIME-decode content.
Instance Method Summary collapse
- #color ⇒ Object
- #expandable? ⇒ Boolean
- #initial_state ⇒ Object
-
#initialize(content_type, filename, encoded_content, sibling_types) ⇒ Attachment
constructor
A new instance of Attachment.
-
#inlineable? ⇒ Boolean
an attachment is exapndable if we’ve managed to decode it into something we can display inline.
- #patina_color ⇒ Object
- #patina_text ⇒ Object
-
#to_s ⇒ Object
used when viewing the attachment as text.
- #view! ⇒ Object
- #view_default!(path) ⇒ Object
- #viewable? ⇒ Boolean
- #write_to_disk ⇒ Object
Constructor Details
#initialize(content_type, filename, encoded_content, sibling_types) ⇒ Attachment
Returns a new instance of Attachment.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sup/message-chunks.rb', line 102 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 /^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(/\t/, " ").gsub(/\r/, "").split("\n") @quotable = true end end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.
99 100 101 |
# File 'lib/sup/message-chunks.rb', line 99 def content_type @content_type end |
#filename ⇒ Object (readonly)
raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.
99 100 101 |
# File 'lib/sup/message-chunks.rb', line 99 def filename @filename end |
#lines ⇒ Object (readonly)
raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.
99 100 101 |
# File 'lib/sup/message-chunks.rb', line 99 def lines @lines end |
#raw_content ⇒ Object (readonly)
raw_content is the post-MIME-decode content. this is used for saving the attachment to disk.
99 100 101 |
# File 'lib/sup/message-chunks.rb', line 99 def raw_content @raw_content end |
Instance Method Details
#color ⇒ Object
132 |
# File 'lib/sup/message-chunks.rb', line 132 def color; :none end |
#expandable? ⇒ Boolean
145 |
# File 'lib/sup/message-chunks.rb', line 145 def ; !viewable? end |
#initial_state ⇒ Object
146 |
# File 'lib/sup/message-chunks.rb', line 146 def initial_state; :open end |
#inlineable? ⇒ Boolean
an attachment is exapndable if we’ve managed to decode it into something we can display inline. otherwise, it’s viewable.
144 |
# File 'lib/sup/message-chunks.rb', line 144 def inlineable?; false end |
#patina_color ⇒ Object
133 |
# File 'lib/sup/message-chunks.rb', line 133 def patina_color; :attachment_color end |
#patina_text ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/sup/message-chunks.rb', line 134 def patina_text if "Attachment: #{filename} (#{lines.length} lines)" else "Attachment: #{filename} (#{content_type}; #{@raw_content.size.to_human_size})" end end |
#to_s ⇒ Object
used when viewing the attachment as text
175 176 177 |
# File 'lib/sup/message-chunks.rb', line 175 def to_s @lines || @raw_content end |
#view! ⇒ Object
160 161 162 163 164 165 |
# File 'lib/sup/message-chunks.rb', line 160 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) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/sup/message-chunks.rb', line 148 def view_default! path case Config::CONFIG['arch'] when /darwin/ 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? ⇒ Boolean
147 |
# File 'lib/sup/message-chunks.rb', line 147 def viewable?; @lines.nil? end |