Class: SendGridActionMailerAdapter::Converters::Attachments

Inherits:
Object
  • Object
show all
Defined in:
lib/sendgrid_actionmailer_adapter/converters/attachments.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(sendgrid_mail, value) ⇒ Object



26
27
28
29
30
# File 'lib/sendgrid_actionmailer_adapter/converters/attachments.rb', line 26

def assign_attributes(sendgrid_mail, value)
  Array(value).each do |attachment|
    sendgrid_mail.add_attachment(attachment)
  end
end

#convert(mail) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sendgrid_actionmailer_adapter/converters/attachments.rb', line 13

def convert(mail)
  mail.attachments.map do |attachment|
    ::SendGrid::Attachment.new.tap do |sendgrid_attachment|
      sendgrid_attachment.type = attachment.mime_type
      sendgrid_attachment.content = ::Base64.strict_encode64(attachment.body.raw_source)
      sendgrid_attachment.filename = ::Mail::Encodings.decode_encode(
        attachment.content_type_parameters['filename'], :decode
      )
      sendgrid_attachment.content_id = attachment.cid
    end
  end
end

#validate(_mail) ⇒ Object



10
11
# File 'lib/sendgrid_actionmailer_adapter/converters/attachments.rb', line 10

def validate(_mail)
end