Class: TMail::Encoder
- Inherits:
-
Object
show all
- Includes:
- TextUtils
- Defined in:
- lib/action_mailer/vendor/tmail/encode.rb
Overview
FIXME: This class can handle only (euc-jp/shift_jis -> iso-2022-jp).
Constant Summary
collapse
- BENCODE_DEBUG =
false
- SPACER =
"\t"
- MAX_LINE_LEN =
70
- OPTIONS =
{
'EUC' => '-Ej -m0',
'SJIS' => '-Sj -m0',
'UTF8' => nil, 'NONE' => nil
}
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_phrase, #quote_token, #time2str, #timezone_string_to_unixtime, #to_kcode, #token_safe?
Constructor Details
#initialize(dest = nil, encoding = nil, eol = "\r\n", limit = nil) ⇒ Encoder
Returns a new instance of Encoder.
189
190
191
192
193
194
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 189
def initialize( dest = nil, encoding = nil, eol = "\r\n", limit = nil )
@f = StrategyInterface.create_dest(dest)
@opt = OPTIONS[$KCODE]
@eol = eol
reset
end
|
Class Method Details
.encode(str) ⇒ Object
172
173
174
175
176
177
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 172
def Encoder.encode( str )
e = new()
e.header_body str
e.terminate
e.dest.string
end
|
Instance Method Details
#dest ⇒ Object
214
215
216
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 214
def dest
@f
end
|
#encode_value(str) ⇒ Object
288
289
290
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 288
def encode_value( str )
str.gsub(TOKEN_UNSAFE) {|s| '%%%02x' % s[0] }
end
|
#header_body(str) ⇒ Object
241
242
243
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 241
def header_body( str )
scanadd normalize_encoding(str)
end
|
231
232
233
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 231
def ( line )
scanadd line
end
|
235
236
237
238
239
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 235
def ( name )
add_text name.split(/-/).map {|i| i.capitalize }.join('-')
add_text ':'
add_lwsp ' '
end
|
#kv_pair(k, v) ⇒ Object
FIXME: implement line folding
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 274
def kv_pair( k, v )
return if v.nil?
v = normalize_encoding(v)
if token_safe?(v)
add_text k + '=' + v
elsif not CONTROL_CHAR === v
add_text k + '=' + quote_token(v)
else
kv = k + '*=' + "iso-2022-jp'ja'" + encode_value(v)
add_text kv
end
end
|
#lwsp(str) ⇒ Object
251
252
253
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 251
def lwsp( str )
add_lwsp str.sub(/[\r\n]+[^\r\n]*\z/, '')
end
|
255
256
257
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 255
def meta( str )
add_text str
end
|
#normalize_encoding(str) ⇒ Object
196
197
198
199
200
201
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 196
def normalize_encoding( str )
if @opt
then NKF.nkf(@opt, str)
else str
end
end
|
#phrase(str) ⇒ Object
263
264
265
266
267
268
269
270
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 263
def phrase( str )
str = normalize_encoding(str)
if CONTROL_CHAR === str
scanadd str
else
add_text quote_phrase(str)
end
end
|
#puts(str = nil) ⇒ Object
218
219
220
221
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 218
def puts( str = nil )
@f << str if str
@f << @eol
end
|
#reset ⇒ Object
203
204
205
206
207
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 203
def reset
@text = ''
@lwsp = ''
@curlen = 0
end
|
#space ⇒ Object
Also known as:
spc
245
246
247
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 245
def space
add_lwsp ' '
end
|
#terminate ⇒ Object
209
210
211
212
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 209
def terminate
add_lwsp ''
reset
end
|
#text(str) ⇒ Object
259
260
261
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 259
def text( str )
scanadd normalize_encoding(str)
end
|
#write(str) ⇒ Object
223
224
225
|
# File 'lib/action_mailer/vendor/tmail/encode.rb', line 223
def write( str )
@f << str
end
|