Class: Mail::Encodings::QuotedPrintable
- Inherits:
-
SevenBit
- Object
- TransferEncoding
- Identity
- Binary
- EightBit
- SevenBit
- Mail::Encodings::QuotedPrintable
- Defined in:
- lib/mail/encodings/quoted_printable.rb
Constant Summary collapse
- NAME =
'quoted-printable'
- PRIORITY =
2
Class Method Summary collapse
- .can_encode?(enc) ⇒ Boolean
-
.compatible_input?(str) ⇒ Boolean
QP inserts newlines automatically and cannot violate the SMTP spec.
- .cost(str) ⇒ Object
-
.decode(str) ⇒ Object
Decode the string from Quoted-Printable.
- .encode(str) ⇒ Object
Methods inherited from TransferEncoding
can_transport?, lowest_cost, negotiate, renegotiate, to_s
Class Method Details
.can_encode?(enc) ⇒ Boolean
12 13 14 |
# File 'lib/mail/encodings/quoted_printable.rb', line 12 def self.can_encode?(enc) EightBit.can_encode? enc end |
.compatible_input?(str) ⇒ Boolean
QP inserts newlines automatically and cannot violate the SMTP spec.
36 37 38 |
# File 'lib/mail/encodings/quoted_printable.rb', line 36 def self.compatible_input?(str) true end |
.cost(str) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/mail/encodings/quoted_printable.rb', line 26 def self.cost(str) # These bytes probably do not need encoding c = str.count("\x9\xA\xD\x20-\x3C\x3E-\x7E") # Everything else turns into =XX where XX is a # two digit hex number (taking 3 bytes) total = (str.bytesize - c)*3 + c total.to_f/str.bytesize end |
.decode(str) ⇒ Object
Decode the string from Quoted-Printable. Cope with hard line breaks that were incorrectly encoded as hex instead of literal CRLF.
18 19 20 |
# File 'lib/mail/encodings/quoted_printable.rb', line 18 def self.decode(str) ::Mail::Utilities.to_lf ::Mail::Utilities.to_crlf(str).gsub(/(?:=0D=0A|=0D|=0A)\r\n/, "\r\n").unpack1("M*") end |