Sha256: 1a6bf05aa3d46b903c945995a3b87bcee18e7569a1b60631391d97aa9350a625

Contents?: true

Size: 1.09 KB

Versions: 49

Compression:

Stored size: 1.09 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?(enc)
        EightBit.can_encode? enc
      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
      end

      def self.encode(str)
        [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

49 entries across 35 versions & 9 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/encodings/quoted_printable.rb