Permalink
Browse files

Don't recreate files if already present

  • Loading branch information...
1 parent 4eceead commit 3973b99b8372e788c4cc3ed6031915fc9ab605c8 @davidcornu committed May 10, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/letter_opener/message.rb
@@ -17,7 +17,9 @@ def render
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) }
+ unless File.exists?(path) # true if other parts have already been rendered
+ File.open(path, 'wb') { |f| f.write(attachment.body.raw_source) }
+ end
@attachments << [attachment.filename, "attachments/#{URI.escape(attachment.filename)}"]
end
end

0 comments on commit 3973b99

Please sign in to comment.