Method: Mail::Body#encoded
- Defined in:
- lib/mail/body.rb
#encoded(transfer_encoding = '8bit') ⇒ Object
Returns a body encoded using transfer_encoding. Multipart always uses an identiy encoding (i.e. no encoding). Calling this directly is not a good idea, but supported for compatibility TODO: Validate that preamble and epilogue are valid for requested encoding
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/mail/body.rb', line 150 def encoded(transfer_encoding = '8bit') if multipart? self.sort_parts! encoded_parts = parts.map { |p| p.encoded } ([preamble] + encoded_parts).join(crlf_boundary) + end_boundary + epilogue.to_s else be = get_best_encoding(transfer_encoding) dec = Mail::Encodings::get_encoding(encoding) enc = Mail::Encodings::get_encoding(be) if transfer_encoding == encoding and dec.nil? # Cannot decode, so skip normalization raw_source else # Decode then encode to normalize and allow transforming # from base64 to Q-P and vice versa decoded = dec.decode(raw_source) if defined?(Encoding) && charset && charset != "US-ASCII" decoded.encode!(charset) decoded.force_encoding('BINARY') unless Encoding.find(charset).ascii_compatible? end enc.encode(decoded) end end end |