Sha256: 5f5def98530ab355c95fdc38b18649337f5c95120aa9e9385664d7f8302cc214

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

# encoding: utf-8
# frozen_string_literal: true
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)
        ::Mail::Utilities.to_lf str.gsub(/(?:=0D=0A|=0D|=0A)\r\n/, "\r\n").unpack("M*").first
      end

      def self.encode(str)
        ::Mail::Utilities.to_crlf([::Mail::Utilities.to_lf(str)].pack("M"))
      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

      # QP inserts newlines automatically and cannot violate the SMTP spec.
      def self.compatible_input?(str)
        true
      end

      private

      Encodings.register(NAME, self)
    end
  end
end

Version data entries

23 entries across 21 versions & 6 rubygems

Version Path
tdiary-5.0.6 vendor/bundle/gems/mail-2.6.6/lib/mail/encodings/quoted_printable.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.6/lib/mail/encodings/quoted_printable.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
mail-2.6.6 lib/mail/encodings/quoted_printable.rb
mail-2.7.0.rc1 lib/mail/encodings/quoted_printable.rb
mail-2.6.6.rc1 lib/mail/encodings/quoted_printable.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/mail-2.6.5/lib/mail/encodings/quoted_printable.rb
mail-2.6.5 lib/mail/encodings/quoted_printable.rb
mail-2.6.5.rc1 lib/mail/encodings/quoted_printable.rb
tdiary-5.0.4 vendor/bundle/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
abaci-0.3.0 vendor/bundle/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb
tdiary-5.0.2 vendor/bundle/gems/mail-2.6.4/lib/mail/encodings/quoted_printable.rb