@content_type = content_type
@filename = filename
@raw_content = encoded_content.decode
- charset = encoded_content.charset
- if @content_type =~ /^text\/plain\b/
- @lines = Message.convert_from(@raw_content, charset).split("\n")
- else
- text = HookManager.run "mime-decode", :content_type => content_type,
- :filename => lambda { write_to_disk }, :sibling_types => sibling_types
- @lines = text.split("\n") if text
- end
+ @lines =
+ case @content_type
+ when /^text\/plain\b/
+ 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
+
+ end
end
def inlineable?; !@lines.nil? end
$? == 0
end
+ ## used when viewing the attachment as text
+ def to_s
+ @lines || @raw_content
+ end
+
private
def write_to_disk
EOS
end
- def raw_header
+ def with_source_errors_handled
begin
- @source.raw_header @source_info
+ yield
rescue SourceError => e
Redwood::log "problem getting messages from #{@source}: #{e.message}"
error_message e.message
end
end
+ def raw_header
+ with_source_errors_handled { @source.raw_header @source_info }
+ end
+
def raw_full_message
- begin
- @source.raw_full_message @source_info
- rescue SourceError => e
- Redwood::log "problem getting messages from #{@source}: #{e.message}"
- error_message(e.message)
- end
+ with_source_errors_handled { @source.raw_full_message @source_info }
+ end
+
+ ## much faster than raw_full_message
+ def each_raw_full_message_line &b
+ with_source_errors_handled { @source.each_raw_full_message_line(@source_info, &b) }
end
def content
## otherwise, it's body text
else
- body = Message.convert_from m.body, m.charset
+ body = Message.convert_from m.decode, m.charset
text_to_chunks body.normalize_whitespace.split("\n")
end
end