class EmailSpec::EmailViewer
Public Class Methods
open_in_browser(filename)
click to toggle source
# File lib/email_spec/email_viewer.rb, line 83 def self.open_in_browser(filename) Launchy.open(URI.parse("file://#{File.expand_path(filename)}")) end
open_in_text_editor(filename)
click to toggle source
# File lib/email_spec/email_viewer.rb, line 79 def self.open_in_text_editor(filename) Launchy.open(URI.parse("file://#{File.expand_path(filename)}"), :application => :editor) end
save_and_open_all_html_emails()
click to toggle source
# File lib/email_spec/email_viewer.rb, line 18 def self.save_and_open_all_html_emails all_emails.each_with_index do |m, index| if m.multipart? && m.parts.detect{ |p| p.content_type.include?('text/html') } filename = tmp_email_filename("-#{index}.html") File.open(filename, "w") do |f| f.write m.parts[1].body end open_in_browser(filename) end end end
save_and_open_all_raw_emails()
click to toggle source
# File lib/email_spec/email_viewer.rb, line 5 def self.save_and_open_all_raw_emails filename = tmp_email_filename File.open(filename, "w") do |f| all_emails.each do |m| f.write m.to_s f.write "\n" + '='*80 + "\n" end end open_in_text_editor(filename) end
save_and_open_all_text_emails()
click to toggle source
# File lib/email_spec/email_viewer.rb, line 30 def self.save_and_open_all_text_emails filename = tmp_email_filename File.open(filename, "w") do |f| all_emails.each do |m| if m.multipart? && text_part = m.parts.detect{ |p| p.content_type.include?('text/plain') } if m.respond_to?(:ordered_each) # Rails 2 / TMail m.ordered_each{|k,v| f.write "#{k}: #{v}\n" } else # Rails 4 / Mail f.write(text_part.header.to_s + "\n") end f.write text_part.body else f.write m.to_s end f.write "\n" + '='*80 + "\n" end end open_in_text_editor(filename) end
save_and_open_email(mail)
click to toggle source
# File lib/email_spec/email_viewer.rb, line 53 def self.save_and_open_email(mail) filename = tmp_email_filename File.open(filename, "w") do |f| f.write mail.to_s end open_in_text_editor(filename) end
save_and_open_email_attachments_list(mail)
click to toggle source
# File lib/email_spec/email_viewer.rb, line 63 def self.save_and_open_email_attachments_list(mail) filename = tmp_email_filename File.open(filename, "w") do |f| mail.attachments.each_with_index do |attachment, index| info = "#{index + 1}:" info += "\n\tfilename: #{attachment.original_filename}" info += "\n\tcontent type: #{attachment.content_type}" info += "\n\tsize: #{attachment.size}" f.write info + "\n" end end open_in_text_editor(filename) end
tmp_email_filename(extension = '.txt')
click to toggle source
# File lib/email_spec/email_viewer.rb, line 87 def self.tmp_email_filename(extension = '.txt') "#{Rails.root}/tmp/email-#{Time.now.to_i}#{extension}" end