diff options
Diffstat (limited to 'actionmailer/lib/action_mailer/part.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb new file mode 100644 index 0000000000..e26742816a --- /dev/null +++ b/actionmailer/lib/action_mailer/part.rb @@ -0,0 +1,84 @@ +require 'action_mailer/adv_attr_accessor' + +module ActionMailer + + class Part #:nodoc: + include ActionMailer::AdvAttrAccessor + + adv_attr_accessor :content_type, :content_disposition, :charset, :body + adv_attr_accessor :filename, :transfer_encoding, :headers + + def initialize(params) + @content_type = params[:content_type] || "text/plain" + @content_disposition = params[:disposition] || "inline" + @charset = params[:charset] + @body = params[:body] + @filename = params[:filename] + @transfer_encoding = params[:transfer_encoding] || "quoted-printable" + @headers = params[:headers] || {} + end + + def to_mail(defaults) + part = TMail::Mail.new + part.set_content_type(content_type, nil, + "charset" => charset || defaults.charset, "name" => filename) + part.set_content_disposition(content_disposition, + "filename" => filename) + + part.content_transfer_encoding = transfer_encoding || "quoted-printable" + case (transfer_encoding || "").downcase + when "base64" then + part.body = TMail::Base64.encode(body) + when "quoted-printable" + part.body = [body].pack("M*") + else + part.body = body + end + + part + end + end + +end +require 'action_mailer/adv_attr_accessor' + +module ActionMailer + + class Part #:nodoc: + include ActionMailer::AdvAttrAccessor + + adv_attr_accessor :content_type, :content_disposition, :charset, :body + adv_attr_accessor :filename, :transfer_encoding, :headers + + def initialize(params) + @content_type = params[:content_type] || "text/plain" + @content_disposition = params[:disposition] || "inline" + @charset = params[:charset] + @body = params[:body] + @filename = params[:filename] + @transfer_encoding = params[:transfer_encoding] || "quoted-printable" + @headers = params[:headers] || {} + end + + def to_mail(defaults) + part = TMail::Mail.new + part.set_content_type(content_type, nil, + "charset" => charset || defaults.charset, "name" => filename) + part.set_content_disposition(content_disposition, + "filename" => filename) + + part.content_transfer_encoding = transfer_encoding || "quoted-printable" + case (transfer_encoding || "").downcase + when "base64" then + part.body = TMail::Base64.encode(body) + when "quoted-printable" + part.body = [body].pack("M*") + else + part.body = body + end + + part + end + end + +end |