Object
# File lib/letter_opener/message.rb, line 14 def initialize(location, mail, part = nil) @location = location @mail = mail @part = part @attachments = [] end
# File lib/letter_opener/message.rb, line 5 def self.rendered_messages(location, mail) messages = [] messages << new(location, mail, mail.html_part) if mail.html_part messages << new(location, mail, mail.text_part) if mail.text_part messages << new(location, mail) if messages.empty? messages.each(&:render) messages.sort end
# File lib/letter_opener/message.rb, line 97 def <=>(other) order = ]rich plain] order.index(type) <=> order.index(other.type) end
# File lib/letter_opener/message.rb, line 87 def auto_link(text) text.gsub(URI.regexp(]https http])) do "<a href=\"#{$&}\">#{$&}</a>" end end
# File lib/letter_opener/message.rb, line 55 def body @body ||= begin body = (@part && @part.body || @mail.body).to_s mail.attachments.each do |attachment| body.gsub!(attachment.url, "attachments/#{attachment.filename}") end body end end
# File lib/letter_opener/message.rb, line 51 def content_type @part && @part.content_type || @mail.content_type end
# File lib/letter_opener/message.rb, line 83 def encoding body.respond_to?(:encoding) ? body.encoding : "utf-8" end
# File lib/letter_opener/message.rb, line 47 def filepath File.join(@location, "#{type}.html") end
# File lib/letter_opener/message.rb, line 67 def from @from ||= Array(@mail.from).join(", ") end
# File lib/letter_opener/message.rb, line 93 def h(content) CGI.escapeHTML(content) end
# File lib/letter_opener/message.rb, line 21 def render FileUtils.mkdir_p(@location) if mail.attachments.any? attachments_dir = File.join(@location, 'attachments') FileUtils.mkdir_p(attachments_dir) mail.attachments.each do |attachment| path = File.join(attachments_dir, attachment.filename) 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 File.open(filepath, 'w') do |f| f.write ERB.new(template).result(binding) end end
# File lib/letter_opener/message.rb, line 75 def reply_to @reply_to ||= Array(@mail.reply_to).join(", ") end
# File lib/letter_opener/message.rb, line 43 def template File.read(File.expand_path("../message.html.erb", __FILE__)) end
Generated with the Darkfish Rdoc Generator 2.