Class: Mail::Field

### Home Classes Methods

### In Files

- lib/mail/field.rb

### Parent

Object

### Namespace

- CLASS Mail::Field::FieldError

### Methods

- ::new
- #<=>
- #==
- #field
- #field=
- #field_order_id
- #inspect
- #method_missing
- #name
- #responsible_for?
- #same
- #to_s
- #update
- #value
- #value=

### Included Modules

- Mail::Utilities
- Comparable

### 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::Field

Provides a single class to call to create a new structured or unstructured field. Works out per RFC what field of field it is being given and returns the correct field of class back on new.

### Per RFC 2822

    2.2. Header Fields

       Header fields are lines composed of a field name, followed by a colon
       (":"), followed by a field body, and terminated by CRLF.  A field
       name MUST be composed of printable US-ASCII characters (i.e.,
       characters that have values between 33 and 126, inclusive), except
       colon.  A field body may be composed of any US-ASCII characters,
       except for CR and LF.  However, a field body may contain CRLF when
       used in header "folding" and  "unfolding" as described in section
       2.2.3.  All field bodies MUST conform to the syntax described in
       sections 3 and 4 of this standard.

### Constants

FIELDS_MAP
FIELD_NAME_MAP
FIELD_ORDER
FIELD_ORDER_LOOKUP
KNOWN_FIELDS
STRUCTURED_FIELDS

### Public Class Methods

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

Accepts a string:

    Field.new("field-name: field data")

Or name, value pair:

    Field.new("field-name", "value")

Or a name by itself:

    Field.new("field-name")

Note, does not want a terminating carriage return. Returns self appropriately parsed. If value is not a string, then it will be passed through as is, for example, content-type field can accept an array with the type and a hash of parameters:

    Field.new('content-type', ['text', 'plain', {:charset => 'UTF-8'}])

    # File lib/mail/field.rb, line 114
    def initialize(name, value = nil, charset = 'utf-8')
      case
      when name.index(COLON)            # Field.new("field-name: field data")
        @charset = value.blank? ? charset : value
        @name = name[FIELD_PREFIX]
        @raw_value = name
        @value = nil
      when value.blank?                 # Field.new("field-name")
        @name = name
        @value = nil
        @raw_value = nil
        @charset = charset
      else                              # Field.new("field-name", "value")
        @name = name
        @value = value
        @raw_value = nil
        @charset = charset
      end
      @name = FIELD_NAME_MAP[@name.to_s.downcase] || @name
    end

### Public Instance Methods

<=>( other ) click to toggle source

    # File lib/mail/field.rb, line 180
    def <=>( other )
      self.field_order_id <=> other.field_order_id
    end

==( other ) click to toggle source
Alias for: same
field() click to toggle source

    # File lib/mail/field.rb, line 139
    def field
      _, @value = split(@raw_value) if @raw_value && !@value
      @field ||= create_field(@name, @value, @charset)
    end

field=(value) click to toggle source

    # File lib/mail/field.rb, line 135
    def field=(value)
      @field = value
    end

field_order_id() click to toggle source

    # File lib/mail/field.rb, line 184
    def field_order_id
      @field_order_id ||= (FIELD_ORDER_LOOKUP[self.name.to_s.downcase] || 100)
    end

inspect() click to toggle source

    # File lib/mail/field.rb, line 160
    def inspect
      "#<#{self.class.name} 0x#{(object_id * 2).to_s(16)} #{instance_variables.map do |ivar|
        "#{ivar}=#{instance_variable_get(ivar).inspect}"
      end.join(" ")}>"
    end

method_missing(name, *args, &block) click to toggle source

    # File lib/mail/field.rb, line 188
    def method_missing(name, *args, &block)
      field.send(name, *args, &block)
    end

name() click to toggle source

    # File lib/mail/field.rb, line 144
    def name
      @name
    end

responsible_for?( val ) click to toggle source

    # File lib/mail/field.rb, line 174
    def responsible_for?( val )
      name.to_s.casecmp(val.to_s) == 0
    end

same( other ) click to toggle source

    # File lib/mail/field.rb, line 170
    def same( other )
      match_to_s(other.name, self.name)
    end

Also aliased as: ==
to_s() click to toggle source

    # File lib/mail/field.rb, line 156
    def to_s
      field.to_s
    end

update(name, value) click to toggle source

    # File lib/mail/field.rb, line 166
    def update(name, value)
      @field = create_field(name, value, @charset)
    end

value() click to toggle source

    # File lib/mail/field.rb, line 148
    def value
      field.value
    end

value=(val) click to toggle source

    # File lib/mail/field.rb, line 152
    def value=(val)
      @field = create_field(name, val, @charset)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.