Class: MailDude::AttachmentScrubber

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_dude/attachment_scrubber.rb

Constant Summary collapse

RAW_SOURCE_OMITTED =
"MailDude omitted raw message source because attachment capture is disabled.\n"

Instance Method Summary collapse

Constructor Details

#initialize(mail) ⇒ AttachmentScrubber

Returns a new instance of AttachmentScrubber.



7
8
9
# File 'lib/mail_dude/attachment_scrubber.rb', line 7

def initialize(mail)
  @mail = mail
end

Instance Method Details

#raw_sourceObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/mail_dude/attachment_scrubber.rb', line 11

def raw_source
  source = mail&.to_s
  return RAW_SOURCE_OMITTED if source.blank?

  sanitized = Mail.read_from_string(source)
  remove_attachments!(sanitized)
  sanitized.to_s
rescue StandardError
  RAW_SOURCE_OMITTED
end