Class: TMail::Decoder
- Inherits:
-
Object
- Object
- TMail::Decoder
- Includes:
- TextUtils
- Defined in:
- lib/tmail-pure/encode.rb
Overview
MIME B encoding decoder
Constant Summary collapse
- ENCODED_WORDS =
/#{encoded}(?:\s+#{encoded})*/i
- OUTPUT_ENCODING =
{ 'EUC' => 'e', 'SJIS' => 's', }
Class Method Summary collapse
Instance Method Summary collapse
- #header_body(str) ⇒ Object
- #header_line(str) ⇒ Object
- #header_name(nm) ⇒ Object
-
#initialize(dest, encoding = nil, eol = "\n") ⇒ Decoder
constructor
A new instance of Decoder.
- #kv_pair(k, v) ⇒ Object
- #lwsp(str) ⇒ Object
- #meta(str) ⇒ Object
- #phrase(str) ⇒ Object
- #puts(str = nil) ⇒ Object
- #space ⇒ Object (also: #spc)
- #terminate ⇒ Object
- #text(str) ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(dest, encoding = nil, eol = "\n") ⇒ Decoder
Returns a new instance of Decoder.
76 77 78 79 80 |
# File 'lib/tmail-pure/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 |
Class Method Details
.decode(str, encoding = nil) ⇒ Object
70 71 72 73 74 |
# File 'lib/tmail-pure/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 |
Instance Method Details
#header_body(str) ⇒ Object
98 99 100 |
# File 'lib/tmail-pure/encode.rb', line 98 def header_body(str) @f << decode(str) end |
#header_line(str) ⇒ Object
90 91 92 |
# File 'lib/tmail-pure/encode.rb', line 90 def header_line(str) @f << decode(str) end |
#header_name(nm) ⇒ Object
94 95 96 |
# File 'lib/tmail-pure/encode.rb', line 94 def header_name(nm) @f << nm << ': ' end |
#kv_pair(k, v) ⇒ Object
124 125 126 |
# File 'lib/tmail-pure/encode.rb', line 124 def kv_pair(k, v) @f << k << '=' << v end |
#lwsp(str) ⇒ Object
108 109 110 |
# File 'lib/tmail-pure/encode.rb', line 108 def lwsp(str) @f << str end |
#meta(str) ⇒ Object
112 113 114 |
# File 'lib/tmail-pure/encode.rb', line 112 def (str) @f << str end |
#phrase(str) ⇒ Object
120 121 122 |
# File 'lib/tmail-pure/encode.rb', line 120 def phrase(str) @f << quote_phrase(decode(str)) end |
#puts(str = nil) ⇒ Object
128 129 130 131 |
# File 'lib/tmail-pure/encode.rb', line 128 def puts(str = nil) @f << str if str @f << @eol end |
#space ⇒ Object Also known as: spc
102 103 104 |
# File 'lib/tmail-pure/encode.rb', line 102 def space @f << ' ' end |
#terminate ⇒ Object
87 88 |
# File 'lib/tmail-pure/encode.rb', line 87 def terminate end |
#text(str) ⇒ Object
116 117 118 |
# File 'lib/tmail-pure/encode.rb', line 116 def text(str) @f << decode(str) end |
#write(str) ⇒ Object
133 134 135 |
# File 'lib/tmail-pure/encode.rb', line 133 def write(str) @f << str end |