Sha256: 985fc3b5ab61e5e0dbc2bd33f5a5a0143a6a2d97bf95701e5130d6284fc9d3da

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

module Mail
  module Jdec
    module Ruby19Patch
      def pick_encoding(charset)
        if Jdec.enabled?
          Jdec.preferred_charsets.each do |from, to|
            if charset.to_s.downcase == from
              return Encoding.find(to)
            end
          end
        end
        super
      end

      def transcode_charset(str, from_encoding, to_encoding = Encoding::UTF_8)
        if Jdec.enabled?
          case from_encoding.to_s.downcase
          when 'unicode-1-1-utf-7'
            str = Decoder.decode_utf7(str).encode(to_encoding, undef: :replace, invalid: :replace)
          else
            str = super
          end
          if to_encoding.to_s.downcase == 'utf-8'
            str.gsub!(/^\x00+/, '')
            str.gsub!(/\x00+$/, '')
          end
          str
        else
          super
        end
      end
    end
  end
end

unless Mail::Ruby19.singleton_class.included_modules.include?(Mail::Jdec::Ruby19Patch)
  Mail::Ruby19.singleton_class.prepend Mail::Jdec::Ruby19Patch
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mail-jdec-1.0.10 lib/mail/jdec/ruby_1_9_patch.rb
mail-jdec-1.0.9 lib/mail/jdec/ruby_1_9_patch.rb