Class: Mail::Encodings::QuotedPrintable

Inherits:
SevenBit show all
Defined in:
lib/mail/encodings/quoted_printable.rb

Constant Summary collapse

NAME =
'quoted-printable'
PRIORITY =
2

Class Method Summary collapse

Methods inherited from TransferEncoding

can_transport?, get_best_compatible, to_s, #to_s

Class Method Details

.can_encode?(str) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mail/encodings/quoted_printable.rb', line 11

def self.can_encode?(str)
  EightBit.can_encode? str
end

.cost(str) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/mail/encodings/quoted_printable.rb', line 24

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



16
17
18
# File 'lib/mail/encodings/quoted_printable.rb', line 16

def self.decode(str)
  str.unpack("M*").first
end

.encode(str) ⇒ Object



20
21
22
# File 'lib/mail/encodings/quoted_printable.rb', line 20

def self.encode(str)
  [str].pack("M").gsub(/\n/, "\r\n")
end