]> git.cworth.org Git - sup/blobdiff - lib/sup/message.rb
warnings bugfix (thanks Magnus)
[sup] / lib / sup / message.rb
index 812d743dfca7d675ac7e2d8b1ab2b502ffc35257..744485a6aa7dfb08edf9eb48f101d66496ccc8da 100644 (file)
@@ -53,15 +53,18 @@ EOS
       @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
@@ -72,6 +75,11 @@ EOS
       $? == 0
     end
     
+    ## used when viewing the attachment as text
+    def to_s
+      @lines || @raw_content
+    end
+
   private
 
     def write_to_disk
@@ -259,22 +267,26 @@ The error message was:
 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
@@ -352,7 +364,7 @@ private
 
       ## 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