instance method set_content_type

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

set_content_type( str, sub = nil, param = nil )

Destructively sets the “Content-Type:” header field of this mail object

Allows you to set the main type, sub type as well as parameters to the field. The main type and sub type need to be a string.

The optional params hash can be passed with keys as symbols and values as a string, or strings as keys and values.

Example:

mail = TMail::Mail.new
mail.set_content_type("text", "plain")
mail.to_s #=> "Content-Type: text/plain\n\n"

mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"})
mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n"

mail.set_content_type("text", "plain", {"charset" => "EUC-KR", "format" => "flowed"})
mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n"

Parameters

str req
sub opt = nil
param opt = nil
Source
# File actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb, line 792
    def set_content_type( str, sub = nil, param = nil )
      if sub
        main, sub = str, sub
      else
        main, sub = str.split(%r</>, 2)
        raise ArgumentError, "sub type missing: #{str.inspect}" unless sub
      end
      if h = @header['content-type']
        h.main_type = main
        h.sub_type  = sub
        h.params.clear
      else
        store 'Content-Type', "#{main}/#{sub}"
      end
      @header['content-type'].params.replace param if param
      str
    end

Defined in actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb line 792 · View on GitHub · Improve this page · Find usages on GitHub

Defined in TMail::Mail

Type at least 2 characters to search.

↑↓ navigate · open · esc close