2 # Accessors and helpers that ActionMailer::Base and ActionMailer::Part have
3 # in common. Using these helpers you can easily add subparts or attachments
6 # def my_mail_message(...)
8 # part "text/plain" do |p|
9 # p.body "hello, world"
10 # p.transfer_encoding "base64"
13 # attachment "image/jpg" do |a|
14 # a.body = File.read("hello.jpg")
15 # a.filename = "hello.jpg"
19 # The list of subparts of this container
22 # Add a part to a multipart message, with the given content-type. The
23 # part itself is yielded to the block so that other properties (charset,
24 # body, headers, etc.) can be set on it.
26 params
= {:content_type => params
} if String
=== params
27 part
= Part
.new(params
)
28 yield part
if block_given
?
32 # Add an attachment to a multipart message. This is simply a part with the
33 # content-disposition set to "attachment".
34 def attachment(params
, &block
)
35 params
= { :content_type => params
} if String
=== params
36 params
= { :disposition => "attachment",
37 :transfer_encoding => "base64" }.merge(params
)
43 def parse_content_type(defaults
=nil)
44 return [defaults
&& defaults
.content_type
, {}] if content_type
.blank
?
45 ctype
, *attrs
= content_type
.split(/;\s*/)
46 attrs
= attrs
.inject({}) { |h
,s
| k
,v
= s
.split(/=/, 2); h
[k
] = v
; h
}
47 [ctype
, {"charset" => charset
|| defaults
&& defaults
.charset
}.merge(attrs
)]