Sha256: 9f4c95a0ef662776b56a3e1c56c223b383e98c792ed8e2b0c61faa6b385c436b

Contents?: true

Size: 1.67 KB

Versions: 111

Compression:

Stored size: 1.67 KB

Contents

module ActionMailer
  # 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
    attr_reader :parts

    # Add a part to a multipart message, with the given content-type. The
    # part itself is yielded to the block so that other properties (charset,
    # 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

    private
    
      def parse_content_type(defaults=nil)
        return [defaults && defaults.content_type, {}] if content_type.blank?
        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

  end
end

Version data entries

111 entries across 110 versions & 9 rubygems

Version Path
radiant-0.7.2 vendor/rails/actionmailer/lib/action_mailer/part_container.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionmailer/pkg/actionmailer-2.2.2/lib/action_mailer/part_container.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/part_container.rb
actionmailer-2.2.3 lib/action_mailer/part_container.rb
actionmailer-1.2.4 lib/action_mailer/part_container.rb
actionmailer-1.2.1 lib/action_mailer/part_container.rb
actionmailer-1.2.0 lib/action_mailer/part_container.rb
actionmailer-1.2.3 lib/action_mailer/part_container.rb
actionmailer-1.2.2 lib/action_mailer/part_container.rb
actionmailer-2.0.4 lib/action_mailer/part_container.rb