Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tentative attachment support

  • Loading branch information...
commit 0197070ddd9630afab95871a99fd535f30414363 1 parent 5772e55
David Cornu authored
Showing with 21 additions and 0 deletions.
  1. +9 −0 lib/letter_opener/message.html.erb
  2. +12 −0 lib/letter_opener/message.rb
9 lib/letter_opener/message.html.erb
View
@@ -68,6 +68,15 @@
<dt>To:</dt>
<dd><%= mail.to.join(", ") %></dd>
+
+ <% if @attachments.size > 0 %>
+ <dt>Attachments:</dt>
+ <dd>
+ <% @attachments.each do |filename, path| %>
+ <a href="<%= path %>"><%= filename %></a>
+ <% end %>
+ </dd>
+ <% end %>
</dl>
<% if mail.multipart? %>
12 lib/letter_opener/message.rb
View
@@ -6,10 +6,22 @@ def initialize(location, mail, part = nil)
@location = location
@mail = mail
@part = part
+ @attachments = []
end
def render
FileUtils.mkdir_p(@location)
+
+ if mail.attachments
+ attachments_dir = File.join(@location,'attachments')
+ FileUtils.mkdir_p(attachments_dir)
+ mail.attachments.each do |attachment|
+ path = File.join(attachments_dir, attachment.filename)
+ File.open(path, 'wb') { |f| f.write(attachment.body.raw_source) }
+ @attachments << [attachment.filename, "attachments/#{URI.escape(attachment.filename)}"]
+ end
+ end
+
File.open(filepath, 'w') do |f|
f.write ERB.new(template).result(binding)
end
Please sign in to comment.
Something went wrong with that request. Please try again.