Class: TMail::Decoder

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

Overview

MIME B encoding decoder

Constant Summary collapse

ENCODED_WORDS =
/#{encoded}(?:\s+#{encoded})*/i
SPACER =
"\t"
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, #quote_unquoted_bencode, #quote_unquoted_name, #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.



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

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



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

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



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

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

#header_line(str) ⇒ Object



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

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

#header_name(nm) ⇒ Object



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

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

#kv_pair(k, v) ⇒ Object



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

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

#lwsp(str) ⇒ Object



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

def lwsp( str )
  @f << str
end

#meta(str) ⇒ Object



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

def meta( str )
  @f << str
end

#phrase(str) ⇒ Object



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

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

#puts(str = nil) ⇒ Object



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

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

#puts_meta(str) ⇒ Object



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

def puts_meta( str )
  @f << str
end

#spaceObject Also known as: spc



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

def space
  @f << ' '
end

#terminateObject



140
141
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb', line 140

def terminate
end

#text(str) ⇒ Object



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

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

#write(str) ⇒ Object



191
192
193
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb', line 191

def write( str )
  @f << str
end