Represents a subpart of an email message. It shares many similar attributes of ActionMailer::Base. Although you can create parts manually and add them to the parts list of the mailer, it is easier to use the helper methods in ActionMailer::PartContainer.
Methods
Included Modules
- ActionMailer::AdvAttrAccessor
- ActionMailer::PartContainer
Public Class methods
Create a new part from the given params hash. The valid params keys correspond to the accessors.
[ show source ]
# File lib/action_mailer/part.rb, line 43
43: def initialize(params)
44: @content_type = params[:content_type]
45: @content_disposition = params[:disposition] || "inline"
46: @charset = params[:charset]
47: @body = params[:body]
48: @filename = params[:filename]
49: @transfer_encoding = params[:transfer_encoding] || "quoted-printable"
50: @headers = params[:headers] || {}
51: @parts = []
52: end
Public Instance methods
Convert the part to a mail object which can be included in the parts list of another mail object.
[ show source ]
# File lib/action_mailer/part.rb, line 56
56: def to_mail(defaults)
57: part = TMail::Mail.new
58:
59: real_content_type, ctype_attrs = parse_content_type(defaults)
60:
61: if @parts.empty?
62: part.content_transfer_encoding = transfer_encoding || "quoted-printable"
63: case (transfer_encoding || "").downcase
64: when "base64" then
65: part.body = TMail::Base64.folding_encode(body)
66: when "quoted-printable"
67: part.body = [Utils.normalize_new_lines(body)].pack("M*")
68: else
69: part.body = body
70: end
71:
72: # Always set the content_type after setting the body and or parts!
73: # Also don't set filename and name when there is none (like in
74: # non-attachment parts)
75: if content_disposition == "attachment"
76: ctype_attrs.delete "charset"
77: part.set_content_type(real_content_type, nil,
78: squish("name" => filename).merge(ctype_attrs))
79: part.set_content_disposition(content_disposition,
80: squish("filename" => filename).merge(ctype_attrs))
81: else
82: part.set_content_type(real_content_type, nil, ctype_attrs)
83: part.set_content_disposition(content_disposition)
84: end
85: else
86: if String === body
87: part = TMail::Mail.new
88: part.body = body
89: part.set_content_type(real_content_type, nil, ctype_attrs)
90: part.set_content_disposition "inline"
91: m.parts << part
92: end
93:
94: @parts.each do |p|
95: prt = (TMail::Mail === p ? p : p.to_mail(defaults))
96: part.parts << prt
97: end
98:
99: part.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/
100: end
101:
102: headers.each { |k,v| part[k] = v }
103:
104: part
105: end
Private Instance methods
[ show source ]
# File lib/action_mailer/part.rb, line 109
109: def squish(values={})
110: values.delete_if { |k,v| v.nil? }
111: end