Commit 010846ae9ae30408ec62ef99756be8afbcf85185:
    display inline images

Branch: refs/heads/secmail
Author: Sam Ruby <[email protected]>
Committer: Sam Ruby <[email protected]>
Pusher: rubys <[email protected]>

------------------------------------------------------------
www/secmail/helpers.rb                                       | +++++++++++++++ 
www/secmail/models/message.rb                                | ++ --
www/secmail/views/body.html.rb                               | +++ -
------------------------------------------------------------
23 changes: 20 additions, 3 deletions.
------------------------------------------------------------


diff --git a/www/secmail/helpers.rb b/www/secmail/helpers.rb
index 9987346..52048c0 100644
--- a/www/secmail/helpers.rb
+++ b/www/secmail/helpers.rb
@@ -8,4 +8,19 @@ def svn_reset(repos)
     File.unlink *out.scan(/^\?\s+(.*)/).flatten.map(&:untaint)
     out, err, rc = Open3.capture3 'svn', 'update', path
   end
+
+  # replace inline images (cid:) with references to attachments
+  def fixup_images(node)
+    if Wunderbar::Node === node
+      if node.name == 'img'
+        if node.attrs['src'] and node.attrs['src'].to_s.start_with? 'cid:'
+          node.attrs['src'].value = node.attrs['src'].to_s.sub('cid:', '')
+        end
+      else
+        fixup_images(node.search('img'))
+      end
+    elsif Array === node
+      node.each {|child| fixup_images(child)}
+    end
+  end
 end
diff --git a/www/secmail/models/message.rb b/www/secmail/models/message.rb
index aa4ab4c..0b951bb 100644
--- a/www/secmail/models/message.rb
+++ b/www/secmail/models/message.rb
@@ -11,11 +11,11 @@ def initialize(mailbox, hash, headers, email)
   # find an attachment
   def find(name)
     headers = @headers[:attachments].find do |attach|
-      attach[:name] == name
+      attach[:name] == name or attach['Content-ID'].to_s == '<' + name + '>'
     end
 
     part = mail.attachments.find do |attach| 
-      attach.filename == name or attach['Content-ID'].to_s == name
+      attach.filename == name or attach['Content-ID'].to_s == '<' + name + '>'
     end
 
     if headers
diff --git a/www/secmail/views/body.html.rb b/www/secmail/views/body.html.rb
index 8b3e66b..b39d56f 100644
--- a/www/secmail/views/body.html.rb
+++ b/www/secmail/views/body.html.rb
@@ -43,7 +43,9 @@
         body.force_encoding(@message.html_part.charset)
       end
 
-      _{body.encode('utf-8', invalid: :replace, undef: :replace)}
+      nodes = _{body.encode('utf-8', invalid: :replace, undef: :replace)}
+
+      fixup_images(nodes)
     end
   elsif @message.text_part
     body = @message.text_part.body.to_s

Reply via email to