### Home Classes Methods

### In Files

- lib/tmail/utils.rb

### Methods

- #atom_safe?
- #join_domain
- #quote_atom
- #quote_phrase
- #quote_token
- #timezone_string_to_unixtime
- #token_safe?
- #unquote

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

Text Utils provides a namespace to define TOKENs, ATOMs, PHRASEs and CONTROL characters that are OK per RFC 2822.

It also provides methods you can call to determine if a string is safe

### Constants

ATOM_UNSAFE
CONTROL_CHAR
PHRASE_UNSAFE
TOKEN_UNSAFE

### Public Instance Methods

atom_safe?( str ) click to toggle source

Returns true if the string supplied is free from characters not allowed as an ATOM

    # File lib/tmail/utils.rb, line 123
    def atom_safe?( str )
      not ATOM_UNSAFE === str
    end

join_domain( arr ) click to toggle source

Provides a method to join a domain name by it's parts and also makes it ATOM safe by quoting it as needed

    # File lib/tmail/utils.rb, line 169
    def join_domain( arr )
      arr.map {|i|
          if /\A\[.*\]\z/ === i
            i
          else
            quote_atom(i)
          end
      }.join('.')
    end

quote_atom( str ) click to toggle source

If the string supplied has ATOM unsafe characters in it, will return the string quoted in double quotes, otherwise returns the string unmodified

    # File lib/tmail/utils.rb, line 129
    def quote_atom( str )
      (ATOM_UNSAFE === str) ? dquote(str) : str
    end

quote_phrase( str ) click to toggle source

If the string supplied has PHRASE unsafe characters in it, will return the string quoted in double quotes, otherwise returns the string unmodified

    # File lib/tmail/utils.rb, line 135
    def quote_phrase( str )
      (PHRASE_UNSAFE === str) ? dquote(str) : str
    end

quote_token( str ) click to toggle source

If the string supplied has TOKEN unsafe characters in it, will return the string quoted in double quotes, otherwise returns the string unmodified

    # File lib/tmail/utils.rb, line 146
    def quote_token( str )
      (TOKEN_UNSAFE === str) ? dquote(str) : str
    end

timezone_string_to_unixtime( str ) click to toggle source

Takes a time zone string from an EMail and converts it to Unix Time (seconds)

    # File lib/tmail/utils.rb, line 228
    def timezone_string_to_unixtime( str )
      if m = /([\+\-])(\d\d?)(\d\d)/.match(str)
        sec = (m[2].to_i * 60 + m[3].to_i) * 60
        m[1] == '-' ? -sec : sec
      else
        min = ZONESTR_TABLE[str.downcase] or
                raise SyntaxError, "wrong timezone format '#{str}'"
        min * 60
      end
    end

token_safe?( str ) click to toggle source

Returns true if the string supplied is free from characters not allowed as a TOKEN

    # File lib/tmail/utils.rb, line 140
    def token_safe?( str )
      not TOKEN_UNSAFE === str
    end

unquote( str ) click to toggle source

Unwraps supplied string from inside double quotes Returns unquoted string

    # File lib/tmail/utils.rb, line 163
    def unquote( str )
      str =~ /^"(.*?)"$/ ? $1 : str
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.