Sha256: 177fb99d20d22590af12cd9f8b4f711dcbc8f43bab93a73366650455cfb3b762

Contents?: true

Size: 1.81 KB

Versions: 71

Compression:

Stored size: 1.81 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)
        if content_type.blank? 
          return defaults                                                ? 
            [ defaults.content_type, { 'charset' => defaults.charset } ] : 
            [ nil, {} ] 
        end 
        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

71 entries across 70 versions & 14 rubygems

Version Path
actionmailer-2.3.18 lib/action_mailer/part_container.rb
actionmailer_csi-2.3.5.p8 lib/action_mailer/part_container.rb
actionmailer-2.3.17-rack-upgrade-2.3.17 lib/action_mailer/part_container.rb
actionmailer-2.3.17 lib/action_mailer/part_container.rb
actionmailer_csi-2.3.5.p7 lib/action_mailer/part_container.rb
actionmailer_csi-2.3.5.20130130071128 lib/action_mailer/part_container.rb
actionmailer_csi-2.3.5.p6 lib/action_mailer/part_container.rb
actionmailer-2.3.16 lib/action_mailer/part_container.rb
actionmailer-rack-upgrade-2-2.3.16 lib/action_mailer/part_container.rb
actionmailer-rack-upgrade-2-2.3.15 lib/action_mailer/part_container.rb
actionmailer-2.3.15 lib/action_mailer/part_container.rb
actionmailer-rack-upgrade-2.3.17 lib/action_mailer/part_container.rb
actionmailer-rack-upgrade-2.3.16 lib/action_mailer/part_container.rb
actionmailer-rack-upgrade-2.3.15 lib/action_mailer/part_container.rb
actionmailer-rack-upgrade-2.3.14.1 lib/action_mailer/part_container.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/part_container.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/actionmailer-2.3.12/lib/action_mailer/part_container.rb
actionmailer-2.3.14 lib/action_mailer/part_container.rb
kajam-1.0.3.rc2 vendor/rails/actionmailer/lib/action_mailer/part_container.rb
actionmailer-2.3.12 lib/action_mailer/part_container.rb