Class: CMS::FormsMailer

Inherits:
Object
  • Object
show all
Defined in:
app/mailers/cms/forms_mailer.rb

Instance Method Summary collapse

Instance Method Details

#fix_mixed_attachmentsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/mailers/cms/forms_mailer.rb', line 28

def fix_mixed_attachments
  # do nothing if we have no actual attachments
  return if @_message.parts.select { |p| p.attachment? && !p.inline? }.none?

  mail = Mail.new

  related = Mail::Part.new
  related.content_type = @_message.content_type
  @_message.parts.select { |p| !p.attachment? || p.inline? }.each { |p| related.add_part(p) }
  mail.add_part related

  mail.header       = @_message.header.to_s
  mail.bcc          = @_message.header[:bcc].value # copy bcc manually because it is omitted in header.to_s
  mail.content_type = nil
  @_message.parts.select { |p| p.attachment? && !p.inline? }.each { |p| mail.add_part(p) }

  @_message = mail
  wrap_delivery_behavior!(delivery_method.to_sym)
end

#send_email(form) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/mailers/cms/forms_mailer.rb', line 3

def send_email(form)
  options = {
    from: form.send_from,
    to: form.send_to,
    bcc: Setting[:cms_mail_bcc],
    subject: form.subject,
    template_name: form.form_name,
  }

  if form.has_attachments?
    options[:content_type] = 'multipart/form-data'
    form.attachments.each do |name|
      attachment = form.send(name)
      next unless attachment.exists?
      attachments[attachment.original_filename] = File.read(attachment.path)
    end
  end

  @form = form
  mail options

  # https://github.com/rails/rails/issues/2686
  fix_mixed_attachments
end