Sha256: 0102c95daf780835abcf951684689ad6a1d843a0bb64cec874766ef93043c96b

Contents?: true

Size: 979 Bytes

Versions: 19

Compression:

Stored size: 979 Bytes

Contents

# encoding: utf-8
require 'mail/encodings/7bit'

module Mail
  module Encodings
    class QuotedPrintable < SevenBit
      NAME='quoted-printable'
   
      PRIORITY = 2

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

      # Decode the string from Quoted-Printable. Cope with hard line breaks
      # that were incorrectly encoded as hex instead of literal CRLF.
      def self.decode(str)
        str.gsub(/(?:=0D=0A|=0D|=0A)\r\n/, "\r\n").unpack("M*").first.to_lf
      end

      def self.encode(str)
        [str.to_lf].pack("M").to_crlf
      end

      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
        
      private

      Encodings.register(NAME, self)
    end
  end
end

Version data entries

19 entries across 18 versions & 9 rubygems

Version Path
mail-2.5.5 lib/mail/encodings/quoted_printable.rb
mail-2.5.5.rc1 lib/mail/encodings/quoted_printable.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/quoted_printable.rb
mail-2.6.3 lib/mail/encodings/quoted_printable.rb
mail-portertech-2.6.2.edge lib/mail/encodings/quoted_printable.rb
mail-2.6.1 lib/mail/encodings/quoted_printable.rb
mail-2.6.0 lib/mail/encodings/quoted_printable.rb
challah-1.0.0 vendor/bundle/gems/mail-2.5.4/lib/mail/encodings/quoted_printable.rb
swipe-rails-0.0.5 vendor/bundle/gems/mail-2.5.4/lib/mail/encodings/quoted_printable.rb
mail-2.5.4 lib/mail/encodings/quoted_printable.rb