Module: DcidevMailer

Defined in:
lib/dcidev_mailer.rb,
lib/dcidev_mailer/mandrill.rb,
lib/dcidev_mailer/rails_mailer.rb,
lib/dcidev_mailer/mandrill_template.rb,
lib/dcidev_mailer/errors/invalid_body.rb,
lib/dcidev_mailer/errors/invalid_template.rb,
lib/dcidev_mailer/errors/invalid_recipients.rb

Defined Under Namespace

Modules: Errors Classes: Mandrill, MandrillTemplate, RailsMailer

Class Method Summary collapse

Class Method Details

.format_attachments(attachments) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dcidev_mailer.rb', line 27

def format_attachments(attachments)
    formatted = []
    attachments.each do |a|
        filetype = MimeMagic.by_magic(a[:file]).type.to_s
        content = a[:file].read
        name = "#{a[:filename]}.#{filetype.split("/")[1]}"
        att = {
            content: content,
            name: name,
        }
        
        att[:type] = filetype if ENV["USE_MANDRILL_MAILER"].to_i == 0
        formatted << att
    end
    formatted
end


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dcidev_mailer.rb', line 44

def format_header_footer(header_url: "", footer_url: "", locals: {}, images: {})
    [{ name: "header", url: header_url }, { name: "footer", url: footer_url }].each do |i|
        next if i[:url].nil?
        begin
            extension, encoded, _ = DcidevUtility.file_url_to_base64(i[:url])
            locals[i[:name].to_sym] = "cid:#{i[:name]}"
            images.push({ content: encoded, encoded_content: encoded, type: extension, name: i[:name] })
        rescue => _
        
        end
    end
    return [locals, images]
end

.format_image_from_html(html) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dcidev_mailer.rb', line 3

def format_image_from_html(html)
    
    images = []
    body_html = Nokogiri::HTML(html)
    temp = body_html
    if ENV["USE_MANDRILL_MAILER"].to_i == 1
        temp.search("img").each_with_index do |img, i|
            cid = "body_image_#{i}"
            images.push({ content: nil, encoded_content: DcidevUtility.base64_encoded_string(img["src"]), type: DcidevUtility.base64_extension(img["src"]), name: cid })
            body_html.search("img")[i]["src"] = 'cid:' + cid
        end
    end
    [body_html.search("body")[0].children.to_html, images]
end

.format_images(images) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/dcidev_mailer.rb', line 18

def format_images(images)
    formatted = []
    images.each do |i|
        base64 = Base64.encode64(i[:image])
        formatted << {encoded_content: DcidevUtility.base64_encoded_string(base64), type: DcidevUtility.base64_extension(base64), name: i[:name]}
    end
    return formatted
end