Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tentative attachment support

  • Loading branch information...
commit 0197070ddd9630afab95871a99fd535f30414363 1 parent 5772e55
David Cornu authored
9 lib/letter_opener/message.html.erb
@@ -68,6 +68,15 @@
68 68
69 69 <dt>To:</dt>
70 70 <dd><%= mail.to.join(", ") %></dd>
  71 +
  72 + <% if @attachments.size > 0 %>
  73 + <dt>Attachments:</dt>
  74 + <dd>
  75 + <% @attachments.each do |filename, path| %>
  76 + <a href="<%= path %>"><%= filename %></a>
  77 + <% end %>
  78 + </dd>
  79 + <% end %>
71 80 </dl>
72 81
73 82 <% if mail.multipart? %>
12 lib/letter_opener/message.rb
@@ -6,10 +6,22 @@ def initialize(location, mail, part = nil)
6 6 @location = location
7 7 @mail = mail
8 8 @part = part
  9 + @attachments = []
9 10 end
10 11
11 12 def render
12 13 FileUtils.mkdir_p(@location)
  14 +
  15 + if mail.attachments
  16 + attachments_dir = File.join(@location,'attachments')
  17 + FileUtils.mkdir_p(attachments_dir)
  18 + mail.attachments.each do |attachment|
  19 + path = File.join(attachments_dir, attachment.filename)
  20 + File.open(path, 'wb') { |f| f.write(attachment.body.raw_source) }
  21 + @attachments << [attachment.filename, "attachments/#{URI.escape(attachment.filename)}"]
  22 + end
  23 + end
  24 +
13 25 File.open(filepath, 'w') do |f|
14 26 f.write ERB.new(template).result(binding)
15 27 end

0 comments on commit 0197070

Please sign in to comment.
Something went wrong with that request. Please try again.