to_mail(defaults)
public
Convert the part to a mail object which can be included in the parts list
of another mail object.
Show source
def to_mail(defaults)
part = TMail::Mail.new
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 = [Utils.normalize_new_lines(body)].pack("M*")
else
part.body = body
end
if content_disposition == "attachment"
part.set_content_type(content_type || defaults.content_type, nil,
squish("charset" => nil, "name" => filename))
part.set_content_disposition(content_disposition,
squish("filename" => filename))
else
part.set_content_type(content_type || defaults.content_type, nil,
"charset" => (charset || defaults.charset))
part.set_content_disposition(content_disposition)
end
else
if String === body
part = TMail::Mail.new
part.body = body
part.set_content_type content_type, nil, { "charset" => charset }
part.set_content_disposition "inline"
m.parts << part
end
@parts.each do |p|
prt = (TMail::Mail === p ? p : p.to_mail(defaults))
part.parts << prt
end
part.set_content_type(content_type, nil, { "charset" => charset }) if content_type =~ /multipart/
end
part
end