### Home Classes Methods

### In Files

- lib/tmail/header.rb

### Parent

Object

### Methods

- ::internal_new
- ::new
- ::new
- ::new_from_port
- ::newobj
- #accept
- #body
- #body=
- #empty?
- #illegal?
- #inspect

### Included Modules

- TMail::TextUtils
- StrategyInterface

### Files

- CHANGES
- LICENSE
- NOTES
- README
- Rakefile
- MANIFEST
- Makefile
- depend
- Makefile
- COPYING
- README

### Class/Module Index

Quicksearch

- TMail
- TMail::Address
- TMail::AddressGroup
- TMail::AddressHeader
- TMail::Attachment
- TMail::ContentDispositionHeader
- TMail::ContentTransferEncodingHeader
- TMail::ContentTypeHeader
- TMail::DateTimeHeader
- TMail::EncryptedHeader
- TMail::FilePort
- TMail::HeaderField
- TMail::KeywordsHeader
- TMail::Mail
- TMail::MailFlags
- TMail::Maildir
- TMail::MaildirLoader
- TMail::MaildirPort
- TMail::MboxLoader
- TMail::MessageIdHeader
- TMail::MhLoader
- TMail::MhMailbox
- TMail::MhPort
- TMail::MimeVersionHeader
- TMail::Parser
- TMail::Port
- TMail::ReceivedHeader
- TMail::ReferencesHeader
- TMail::ReturnPathHeader
- TMail::SingleAddressHeader
- TMail::StringPort
- TMail::StructuredHeader
- TMail::SyntaxError
- TMail::TMailScanner
- TMail::TextUtils
- TMail::UNIXMbox
- TMail::UnstructuredHeader
- CharDet
- CharDet::Big5DistributionAnalysis
- CharDet::Big5Prober
- CharDet::CharDistributionAnalysis
- CharDet::CharSetGroupProber
- CharDet::CharSetProber
- CharDet::CodingStateMachine
- CharDet::EUCJPContextAnalysis
- CharDet::EUCJPDistributionAnalysis
- CharDet::EUCJPProber
- CharDet::EUCKRDistributionAnalysis
- CharDet::EUCKRProber
- CharDet::EUCTWDistributionAnalysis
- CharDet::EUCTWProber
- CharDet::EscCharSetProber
- CharDet::GB2312DistributionAnalysis
- CharDet::GB2312Prober
- CharDet::HebrewProber
- CharDet::JapaneseContextAnalysis
- CharDet::Latin1Prober
- CharDet::MBCSGroupProber
- CharDet::MultiByteCharSetProber
- CharDet::SBCSGroupProber
- CharDet::SJISContextAnalysis
- CharDet::SJISDistributionAnalysis
- CharDet::SJISProber
- CharDet::SingleByteCharSetProber
- CharDet::UTF8Prober
- CharDet::UniversalDetector

No matching classes.

# TMail::HeaderField

Provides methods to handle and manipulate headers in the email

### Constants

FNAME_TO_CLASS

### Public Class Methods

internal_new( name, conf ) click to toggle source

    # File lib/tmail/header.rb, line 97
    def internal_new( name, conf )
      FNAME_TO_CLASS[name].newobj('', conf, true)
    end

new( name, body, conf = DEFAULT_CONFIG ) click to toggle source

    # File lib/tmail/header.rb, line 45
    def new( name, body, conf = DEFAULT_CONFIG )
      klass = FNAME_TO_CLASS[name.downcase] || UnstructuredHeader
      klass.newobj body, conf
    end

Also aliased as: newobj
new( body, conf, intern = false ) click to toggle source

    # File lib/tmail/header.rb, line 103
    def initialize( body, conf, intern = false )
      @body = body
      @config = conf

      @illegal = false
      @parsed = false

      if intern
        @parsed = true
        parse_init
      end
    end

new_from_port( port, name, conf = DEFAULT_CONFIG ) click to toggle source

Returns a HeaderField object matching the header you specify in the "name" param. Requires an initialized TMail::Port to be passed in.

The method searches the header of the Port you pass into it to find a match on the header line you pass. Once a match is found, it will unwrap the matching line as needed to return an initialized HeaderField object.

If you want to get the Envelope sender of the email object, pass in "EnvelopeSender", if you want the From address of the email itself, pass in 'From'.

This is because a mailbox doesn't have the : after the From that designates the beginning of the envelope sender (which can be different to the from address of the email)

Other fields can be passed as normal, "Reply-To", "Received" etc.

Note: Change of behaviour in 1.2.1 => returns nil if it does not find the specified header field, otherwise returns an instantiated object of the correct header class

For example:

    port = TMail::FilePort.new("/test/fixtures/raw_email_simple")
    h = TMail::HeaderField.new_from_port(port, "From")
    h.addrs.to_s #=> "Mikel Lindsaar <mikel@nowhere.com>"
    h = TMail::HeaderField.new_from_port(port, "EvelopeSender")
    h.addrs.to_s #=> "mike@anotherplace.com.au"
    h = TMail::HeaderField.new_from_port(port, "SomeWeirdHeaderField")
    h #=> nil

    # File lib/tmail/header.rb, line 77
    def new_from_port( port, name, conf = DEFAULT_CONFIG )
      if name == "EnvelopeSender"
        name = "From"
        re = Regexp.new('\A(From) ', 'i')
      else
        re = Regexp.new('\A(' + Regexp.quote(name) + '):', 'i')
      end
      str = nil
      port.ropen {|f|
          f.each do |line|
            if m = re.match(line)            then str = m.post_match.strip
            elsif str and /\A[\t ]/ === line then str << ' ' << line.strip
            elsif /\A-*\s*\z/ === line       then break
            elsif str                        then break
            end
          end
      }
      new(name, str, Config.to_config(conf)) if str
    end

newobj( name, body, conf = DEFAULT_CONFIG ) click to toggle source
Alias for: new

### Public Instance Methods

accept( strategy ) click to toggle source

    # File lib/tmail/header.rb, line 163
    def accept( strategy )
      ensure_parsed
      do_accept strategy
      strategy.terminate
    end

body() click to toggle source

    # File lib/tmail/header.rb, line 148
    def body
      ensure_parsed
      v = Decoder.new(s = '')
      do_accept v
      v.terminate
      s
    end

body=( str ) click to toggle source

    # File lib/tmail/header.rb, line 156
    def body=( str )
      @body = str
      clear_parse_status
    end

empty?() click to toggle source

    # File lib/tmail/header.rb, line 124
    def empty?
      ensure_parsed
      return true if @illegal
      isempty?
    end

illegal?() click to toggle source

    # File lib/tmail/header.rb, line 120
    def illegal?
      @illegal
    end

inspect() click to toggle source

    # File lib/tmail/header.rb, line 116
    def inspect
      "#<#{self.class} #{@body.inspect}>"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.