Class: Mail::ContentTypeField

### Home Classes Methods

### In Files

- lib/mail/fields/content_type_field.rb

### Parent

StructuredField

### Methods

- ::generate_boundary
- ::new
- ::with_boundary
- #attempt_to_clean
- #content_type
- #decoded
- #default
- #element
- #encoded
- #filename
- #main_type
- #parameters
- #parse
- #string
- #stringify
- #sub_type
- #value

### Files

- TODO.rdoc

### Class/Module Index

Quicksearch

- Mail
- Mail::Address
- Mail::AddressContainer
- Mail::AttachmentsList
- Mail::BccField
- Mail::Body
- Mail::CcField
- Mail::CheckDeliveryParams
- Mail::CommentsField
- Mail::Constants
- Mail::ContentDescriptionField
- Mail::ContentDispositionField
- Mail::ContentIdField
- Mail::ContentLocationField
- Mail::ContentTransferEncodingElement
- Mail::ContentTransferEncodingField
- Mail::ContentTypeField
- Mail::DateField
- Mail::Encodings
- Mail::Encodings::Base64
- Mail::Encodings::Binary
- Mail::Encodings::EightBit
- Mail::Encodings::QuotedPrintable
- Mail::Encodings::SevenBit
- Mail::Encodings::TransferEncoding
- Mail::Encodings::UnixToUnix
- Mail::Envelope
- Mail::EnvelopeFromElement
- Mail::Exim
- Mail::Field
- Mail::Field::FieldError
- Mail::FieldList
- Mail::FileDelivery
- Mail::FromField
- Mail::Header
- Mail::IMAP
- Mail::InReplyToField
- Mail::IndifferentHash
- Mail::KeywordsField
- Mail::Matchers
- Mail::Matchers::HasSentEmailMatcher
- Mail::MessageIdField
- Mail::MessageIdsElement
- Mail::MimeVersionElement
- Mail::MimeVersionField
- Mail::Multibyte
- Mail::Multibyte::EncodingError
- Mail::OptionalField
- Mail::POP3
- Mail::ParameterHash
- Mail::Parsers
- Mail::Parsers::AddressListsParser
- Mail::Parsers::ContentDispositionParser
- Mail::Parsers::ContentLocationParser
- Mail::Parsers::ContentTransferEncodingParser
- Mail::Parsers::ContentTypeParser
- Mail::Parsers::DateTimeParser
- Mail::Parsers::EnvelopeFromParser
- Mail::Parsers::MessageIdsParser
- Mail::Parsers::MimeVersionParser
- Mail::Parsers::PhraseListsParser
- Mail::Parsers::Ragel
- Mail::Parsers::Ragel::AddressListsMachine
- Mail::Parsers::Ragel::ContentDispositionMachine
- Mail::Parsers::Ragel::ContentLocationMachine
- Mail::Parsers::Ragel::ContentTransferEncodingMachine
- Mail::Parsers::Ragel::ContentTypeMachine
- Mail::Parsers::Ragel::DateTimeMachine
- Mail::Parsers::Ragel::EnvelopeFromMachine
- Mail::Parsers::Ragel::MessageIdsMachine
- Mail::Parsers::Ragel::MimeVersionMachine
- Mail::Parsers::Ragel::PhraseListsMachine
- Mail::Parsers::Ragel::ReceivedMachine
- Mail::Parsers::Ragel::Ruby
- Mail::Parsers::ReceivedParser
- Mail::Part
- Mail::PartsList
- Mail::PhraseList
- Mail::ReceivedElement
- Mail::ReceivedField
- Mail::ReferencesField
- Mail::ReplyToField
- Mail::ResentBccField
- Mail::ResentCcField
- Mail::ResentDateField
- Mail::ResentFromField
- Mail::ResentMessageIdField
- Mail::ResentSenderField
- Mail::ResentToField
- Mail::Retriever
- Mail::ReturnPathField
- Mail::Ruby18
- Mail::Ruby19
- Mail::Ruby19::BestEffortCharsetEncoder
- Mail::Ruby19::StrictCharsetEncoder
- Mail::SMTP
- Mail::SMTPConnection
- Mail::SenderField
- Mail::Sendmail
- Mail::StructuredField
- Mail::SubjectField
- Mail::TestMailer
- Mail::TestRetriever
- Mail::ToField
- Mail::UnstructuredField
- Mail::Utilities
- Mail::VERSION
- Net
- Net::SMTP
- Object
- String

No matching classes.

# Mail::ContentTypeField

### Constants

CAPITALIZED_FIELD
FIELD_NAME

### Public Class Methods

generate_boundary() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 81
    def ContentTypeField.generate_boundary
      "--==_mimepart_#{Mail.random_tag}"
    end

new(value = nil, charset = 'utf-8') click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 9
    def initialize(value = nil, charset = 'utf-8')
      self.charset = charset
      if value.class == Array
        @main_type = value[0]
        @sub_type = value[1]
        @parameters = ParameterHash.new.merge!(value.last)
      else
        @main_type = nil
        @sub_type = nil
        @parameters = nil
        value = strip_field(FIELD_NAME, value)
      end
      ensure_filename_quoted(value)
      super(CAPITALIZED_FIELD, value, charset)
      self.parse
      self
    end

with_boundary(type) click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 77
    def ContentTypeField.with_boundary(type)
      new("#{type}; boundary=#{generate_boundary}")
    end

### Public Instance Methods

attempt_to_clean() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 43
    def attempt_to_clean
      # Sanitize the value, handle special cases
      @element ||= Mail::ContentTypeElement.new(sanatize(value))
    rescue
      # All else fails, just get the MIME media type
      @element ||= Mail::ContentTypeElement.new(get_mime_type(value))
    end

content_type() click to toggle source
Alias for: string
decoded() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 119
    def decoded
      if parameters.length > 0
        p = "; #{parameters.decoded}"
      else
        p = ""
      end
      "#{content_type}" + p
    end

default() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 63
    def default
      decoded
    end

element() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 35
    def element
      begin
        @element ||= Mail::ContentTypeElement.new(value)
      rescue
        attempt_to_clean
      end
    end

encoded() click to toggle source

TODO: Fix this up

    # File lib/mail/fields/content_type_field.rb, line 110
    def encoded
      if parameters.length > 0
        p = ";\r\n\s#{parameters.encoded}"
      else
        p = ""
      end
      "#{CAPITALIZED_FIELD}: #{content_type}#{p}\r\n"
    end

filename() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 97
    def filename
      case
      when parameters['filename']
        @filename = parameters['filename']
      when parameters['name']
        @filename = parameters['name']
      else
        @filename = nil
      end
      @filename
    end

main_type() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 51
    def main_type
      @main_type ||= element.main_type
    end

parameters() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 69
    def parameters
      unless @parameters
        @parameters = ParameterHash.new
        element.parameters.each { |p| @parameters.merge!(p) }
      end
      @parameters
    end

parse(val = value) click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 27
    def parse(val = value)
      unless val.blank?
        self.value = val
        @element = nil
        element
      end
    end

string() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 59
    def string
      "#{main_type}/#{sub_type}"
    end

Also aliased as: content_type
stringify(params) click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 93
    def stringify(params)
      params.map { |k,v| "#{k}=#{Encodings.param_encode(v)}" }.join("; ")
    end

sub_type() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 55
    def sub_type
      @sub_type ||= element.sub_type
    end

value() click to toggle source

    # File lib/mail/fields/content_type_field.rb, line 85
    def value
      if @value.class == Array
        "#{@main_type}/#{@sub_type}; #{stringify(parameters)}"
      else
        @value
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.