Class: TMail::Decoder

Inherits:
Object show all
Includes:
TextUtils
Defined in:
lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb

Overview

MIME B encoding decoder

Constant Summary collapse

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

Constants included from TextUtils

TextUtils::ATOM_UNSAFE, TextUtils::CONTROL_CHAR, TextUtils::MESSAGE_ID, TextUtils::MIME_ENCODED, TextUtils::MONTH, TextUtils::NKF_FLAGS, TextUtils::PHRASE_UNSAFE, TextUtils::RFC2231_ENCODED, TextUtils::TOKEN_UNSAFE, TextUtils::WDAY, TextUtils::ZONESTR_TABLE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TextUtils

#atom_safe?, #decode_RFC2231, #decode_params, #join_domain, #message_id?, #mime_encoded?, #quote_atom, #quote_boundary, #quote_phrase, #quote_token, #time2str, #timezone_string_to_unixtime, #to_kcode, #token_safe?, #unquote

Constructor Details

#initialize(dest, encoding = nil, eol = "\n") ⇒ Decoder

Returns a new instance of Decoder.



128
129
130
131
132
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 128

def initialize( dest, encoding = nil, eol = "\n" )
  @f = StrategyInterface.create_dest(dest)
  @encoding = (/\A[ejs]/ === encoding) ? encoding[0,1] : nil
  @eol = eol
end

Class Method Details

.decode(str, encoding = nil) ⇒ Object



122
123
124
125
126
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 122

def self.decode( str, encoding = nil )
  encoding ||= (OUTPUT_ENCODING[TMail.KCODE] || 'j')
  opt = '-mS' + encoding
  str.gsub(ENCODED_WORDS) {|s| NKF.nkf(opt, s) }
end

Instance Method Details

#header_body(str) ⇒ Object



150
151
152
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 150

def header_body( str )
  @f << decode(str)
end

#header_line(str) ⇒ Object



142
143
144
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 142

def header_line( str )
  @f << decode(str)
end

#header_name(nm) ⇒ Object



146
147
148
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 146

def header_name( nm )
  @f << nm << ': '
end

#kv_pair(k, v) ⇒ Object



176
177
178
179
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 176

def kv_pair( k, v )
  v = dquote(v) unless token_safe?(v)
  @f << k << '=' << v
end

#lwsp(str) ⇒ Object



160
161
162
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 160

def lwsp( str )
  @f << str
end

#meta(str) ⇒ Object



164
165
166
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 164

def meta( str )
  @f << str
end

#phrase(str) ⇒ Object



172
173
174
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 172

def phrase( str )
  @f << quote_phrase(decode(str))
end

#puts(str = nil) ⇒ Object



181
182
183
184
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 181

def puts( str = nil )
  @f << str if str
  @f << @eol
end

#spaceObject Also known as: spc



154
155
156
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 154

def space
  @f << ' '
end

#terminateObject



139
140
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 139

def terminate
end

#text(str) ⇒ Object



168
169
170
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 168

def text( str )
  @f << decode(str)
end

#write(str) ⇒ Object



186
187
188
# File 'lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb', line 186

def write( str )
  @f << str
end