2005-07-01 09:17:44 -04:00
|
|
|
module ActionMailer
|
2005-10-16 11:00:27 -04:00
|
|
|
# Accessors and helpers that ActionMailer::Base and ActionMailer::Part have
|
|
|
|
# in common. Using these helpers you can easily add subparts or attachments
|
|
|
|
# to your message:
|
|
|
|
#
|
|
|
|
# def my_mail_message(...)
|
|
|
|
# ...
|
|
|
|
# part "text/plain" do |p|
|
|
|
|
# p.body "hello, world"
|
|
|
|
# p.transfer_encoding "base64"
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# attachment "image/jpg" do |a|
|
|
|
|
# a.body = File.read("hello.jpg")
|
|
|
|
# a.filename = "hello.jpg"
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
module PartContainer
|
|
|
|
# The list of subparts of this container
|
2005-07-01 09:17:44 -04:00
|
|
|
attr_reader :parts
|
|
|
|
|
|
|
|
# Add a part to a multipart message, with the given content-type. The
|
2005-10-26 09:04:20 -04:00
|
|
|
# part itself is yielded to the block so that other properties (charset,
|
2005-07-01 09:17:44 -04:00
|
|
|
# body, headers, etc.) can be set on it.
|
|
|
|
def part(params)
|
|
|
|
params = {:content_type => params} if String === params
|
|
|
|
part = Part.new(params)
|
|
|
|
yield part if block_given?
|
|
|
|
@parts << part
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add an attachment to a multipart message. This is simply a part with the
|
|
|
|
# content-disposition set to "attachment".
|
|
|
|
def attachment(params, &block)
|
|
|
|
params = { :content_type => params } if String === params
|
|
|
|
params = { :disposition => "attachment",
|
|
|
|
:transfer_encoding => "base64" }.merge(params)
|
|
|
|
part(params, &block)
|
|
|
|
end
|
|
|
|
|
2006-03-18 18:53:07 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def parse_content_type(defaults=nil)
|
2008-11-15 05:05:44 -05:00
|
|
|
if content_type.blank?
|
|
|
|
return defaults ?
|
|
|
|
[ defaults.content_type, { 'charset' => defaults.charset } ] :
|
|
|
|
[ nil, {} ]
|
|
|
|
end
|
2006-03-18 18:53:07 -05:00
|
|
|
ctype, *attrs = content_type.split(/;\s*/)
|
|
|
|
attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h }
|
|
|
|
[ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)]
|
|
|
|
end
|
|
|
|
|
2005-07-01 09:17:44 -04:00
|
|
|
end
|
|
|
|
end
|