Class TMail::Decoder
In: lib/tmail/encode.rb
Parent: Object

MIME B encoding decoder

Methods

decode   header_body   header_line   header_name   kv_pair   lwsp   meta   new   phrase   puts   space   spc   terminate   text   write  

Included Modules

TextUtils

Constants

ENCODED_WORDS = /#{encoded}(?:\s+#{encoded})*/i
OUTPUT_ENCODING = { 'EUC' => 'e', 'SJIS' => 's', }

Public Class methods

[Source]

# File lib/tmail/encode.rb, line 70
    def self.decode(str, encoding = nil)
      encoding ||= (OUTPUT_ENCODING[$KCODE] || 'j')
      opt = '-m' + encoding
      str.gsub(ENCODED_WORDS) {|s| NKF.nkf(opt, s) }
    end

[Source]

# File lib/tmail/encode.rb, line 76
    def initialize(dest, encoding = nil, eol = "\n")
      @f = StrategyInterface.create_dest(dest)
      @encoding = (/\A[ejs]/ =~ encoding) ? encoding[0,1] : nil
      @eol = eol
    end

Public Instance methods

[Source]

# File lib/tmail/encode.rb, line 98
    def header_body(str)
      @f << decode(str)
    end

[Source]

# File lib/tmail/encode.rb, line 90
    def header_line(str)
      @f << decode(str)
    end

[Source]

# File lib/tmail/encode.rb, line 94
    def header_name(nm)
      @f << nm << ': '
    end

[Source]

# File lib/tmail/encode.rb, line 124
    def kv_pair(k, v)
      @f << k << '=' << v
    end

[Source]

# File lib/tmail/encode.rb, line 108
    def lwsp(str)
      @f << str
    end

[Source]

# File lib/tmail/encode.rb, line 112
    def meta(str)
      @f << str
    end

[Source]

# File lib/tmail/encode.rb, line 120
    def phrase(str)
      @f << quote_phrase(decode(str))
    end

[Source]

# File lib/tmail/encode.rb, line 128
    def puts(str = nil)
      @f << str if str
      @f << @eol
    end

[Source]

# File lib/tmail/encode.rb, line 102
    def space
      @f << ' '
    end
spc()

Alias for space

[Source]

# File lib/tmail/encode.rb, line 87
    def terminate
    end

[Source]

# File lib/tmail/encode.rb, line 116
    def text(str)
      @f << decode(str)
    end

[Source]

# File lib/tmail/encode.rb, line 133
    def write(str)
      @f << str
    end

[Validate]