Class | TMail::Encoder |
In: |
lib/tmail/encode.rb
|
Parent: | Object |
FIXME: This class can handle only (euc-jp/shift_jis -> iso-2022-jp).
BENCODE_DEBUG | = | false unless defined?(BENCODE_DEBUG) |
SPACER | = | "\t" |
MAX_LINE_LEN | = | 70 |
OPTIONS | = | { 'EUC' => '-Ej -m0', 'SJIS' => '-Sj -m0', 'UTF8' => nil, # FIXME 'NONE' => nil |
METHOD_ID | = | { ?j => :extract_J, ?e => :extract_E, ?a => :extract_A, ?s => :extract_S |
# File lib/tmail/encode.rb, line 153 def Encoder.encode(str) e = new() e.header_body str e.terminate e.dest.string end
# File lib/tmail/encode.rb, line 170 def initialize(dest = nil, encoding = nil, eol = "\r\n", limit = nil) @f = StrategyInterface.create_dest(dest) @opt = OPTIONS[$KCODE] @eol = eol reset end
# File lib/tmail/encode.rb, line 268 def encode_value(str) str.gsub(RFC2231_UNSAFE) {|s| '%%%02X' % s[0] } end
# File lib/tmail/encode.rb, line 216 def header_name(name) add_text name.split(/-/).map {|i| i.capitalize }.join('-') add_text ':' add_lwsp ' ' end
FIXME: implement line folding
# File lib/tmail/encode.rb, line 255 def kv_pair(k, v) v = normalize_encoding(v) if token_safe?(v) add_text k + '=' + v elsif not CONTROL_CHAR =~ v add_text k + '=' + quote_token(v) else # apply RFC2231 encoding kv = k + '*=' + "iso-2022-jp'ja'" + encode_value(v) add_text kv end end
# File lib/tmail/encode.rb, line 177 def normalize_encoding(str) if @opt then NKF.nkf(@opt, str) else str end end
# File lib/tmail/encode.rb, line 244 def phrase(str) str = normalize_encoding(str) if CONTROL_CHAR =~ str scanadd str else add_text quote_phrase(str) end end