Class: OutboundMailbox::OutboundEmail

Inherits:
Record
  • Object
show all
Defined in:
app/models/outbound_mailbox/outbound_email.rb

Overview

Persists the raw RFC822 source in Active Storage (metadata is a checksum only; outbound mail does not need RFC Message-ID for deduplication).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_mail!(mail) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/models/outbound_mailbox/outbound_email.rb', line 13

def create_from_mail!(mail)
  source = mail.encoded
  checksum = OpenSSL::Digest::SHA1.hexdigest(source)
  create!(
    raw_email: create_and_upload_raw_blob!(source),
    message_checksum: checksum
  )
end

Instance Method Details

#incinerateObject



43
44
45
46
47
48
# File 'app/models/outbound_mailbox/outbound_email.rb', line 43

def incinerate
  transaction do
    raw_email.purge if raw_email.attached?
    destroy!
  end
end

#mailObject



35
36
37
# File 'app/models/outbound_mailbox/outbound_email.rb', line 35

def mail
  @mail ||= OutboundMailbox.mail_message_from_raw_source(source)
end

#sourceObject



39
40
41
# File 'app/models/outbound_mailbox/outbound_email.rb', line 39

def source
  @source ||= raw_email.download
end