instance method to_mail

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

to_mail(defaults)

Convert the part to a mail object which can be included in the parts list of another mail object.

Parameters

defaults req
Source
# File actionmailer/lib/action_mailer/part.rb, line 51
    def to_mail(defaults)
      part = TMail::Mail.new

      real_content_type, ctype_attrs = parse_content_type(defaults)

      if @parts.empty?
        part.content_transfer_encoding = transfer_encoding || "quoted-printable"
        case (transfer_encoding || "").downcase
          when "base64" then
            part.body = TMail::Base64.folding_encode(body)
          when "quoted-printable"
            part.body = [normalize_new_lines(body)].pack("M*")
          else
            part.body = body
        end

        # Always set the content_type after setting the body and or parts!
        # Also don't set filename and name when there is none (like in
        # non-attachment parts)
        if content_disposition == "attachment"
          ctype_attrs.delete "charset"
          part.set_content_type(real_content_type, nil,
            squish("name" => filename).merge(ctype_attrs))
          part.set_content_disposition(content_disposition,
            squish("filename" => filename).merge(ctype_attrs))
        else
          part.set_content_type(real_content_type, nil, ctype_attrs)
          part.set_content_disposition(content_disposition) 
        end        
      else
        if String === body
          @parts.unshift Part.new(:charset => charset, :body => @body, :content_type => 'text/plain')
          @body = nil
        end
          
        @parts.each do |p|
          prt = (TMail::Mail === p ? p : p.to_mail(defaults))
          part.parts << prt
        end
        
        if real_content_type =~ /multipart/
          ctype_attrs.delete 'charset'
          part.set_content_type(real_content_type, nil, ctype_attrs)
        end
      end

      headers.each { |k,v| part[k] = v }

      part
    end

Defined in actionmailer/lib/action_mailer/part.rb line 51 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionMailer::Part

Type at least 2 characters to search.

↑↓ navigate · open · esc close