Class: Postpeek::Decoders::QuotedPrintable
- Defined in:
- lib/postpeek/decoders/quoted_printable.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.handles ⇒ Object
6 7 8 |
# File 'lib/postpeek/decoders/quoted_printable.rb', line 6 def self.handles ["quoted-printable"].freeze end |
Instance Method Details
#decode(content) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/postpeek/decoders/quoted_printable.rb', line 10 def decode(content) # unpack1("M") returns an ASCII-8BIT string; force UTF-8 interpretation # before transcoding so multi-byte sequences are preserved. decoded = content.unpack1("M").force_encoding("UTF-8") if decoded.valid_encoding? decoded else decoded.encode("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "") end rescue ArgumentError => e raise DecodeError.new("quoted-printable", e) end |