Guest User

Untitled

a guest
Oct 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. ActionMailer::Base.class_eval do
  2. class << self
  3. protected
  4.  
  5. # Override the version from the actionmailer gem in order to not log attachments.
  6. #
  7. def set_payload_for_mail(payload, mail) #:nodoc:
  8. payload[:mailer] = name
  9. payload[:message_id] = mail.message_id
  10. payload[:subject] = mail.subject
  11. payload[:to] = mail.to
  12. payload[:from] = mail.from
  13. payload[:bcc] = mail.bcc if mail.bcc.present?
  14. payload[:cc] = mail.cc if mail.cc.present?
  15. payload[:date] = mail.date
  16.  
  17. # Don't include attachments in what is logged because it causes the log file to grow too
  18. # quickly and is unreadable by a human reading the log file. Really the main things that
  19. # would be useful to a developer looking back at the logs to debug a problem or to confirm
  20. # that things went out as expected are: 1. The headers. 2. The message body (text and HTML).
  21. # 3. Which files were attached (file name and type should be sufficient).
  22. # If you want to see the attachments themselves, just add a mail interceptor that bcc's
  23. # outgoing mail to your inbox.
  24.  
  25. # Copy the mail by re-parsing; self.dup does not create copies of the parts, so deleting attachments
  26. # would also delete them from the original mail object.
  27. mail = Mail.new(mail.encoded)
  28. # mail = mail.dup
  29.  
  30. mail.without_attachments!
  31. divider_line = '-' * 80 + "\n"
  32.  
  33. payload[:mail] = mail.header.encoded + "\n\n"
  34.  
  35. # Add a searchable, human-readable version of the body parts. Since the encoded version uses
  36. # fixed line length, it may break a line at any point, even the middle of a word. So if you
  37. # later go and grep for the word, you may not find it if all you have is the encoded version,
  38. # even if the word is present! Calling mail.decoded gives an error, so we have to loop
  39. # through the parts individually.
  40. payload[:mail] +=
  41. divider_line +
  42. "Decoded parts:\n" +
  43. mail.parts.to_enum(:recursive_each).map do |part|
  44. next if part.parts.any?
  45.  
  46. divider_line +
  47. part.inspect + "\n" +
  48. part.decoded.force_encoding('utf-8')
  49. end.join("\n") +
  50. '-' * 80 + "\n\n" rescue $!.inspect
  51. end
  52. end
  53. end
Add Comment
Please, Sign In to add comment