Sha256: 11a2ebc2ec18526d7e745f1af9c10cb11fac9b3eeee53d7d78f520ae351f31d4

Contents?: true

Size: 762 Bytes

Versions: 3

Compression:

Stored size: 762 Bytes

Contents

module Mail
  module Jdec
    module MessagePatch
      def decoded
        decoded = super

        if Jdec.enabled? && (!has_content_type? || (text? && !has_charset? && !attachment? && !multipart?))
          detected = Detector.detect(decoded)
          if detected && detected[:type] == :text
            charset = detected[:encoding].downcase
            decoded = Mail::Encodings.transcode_charset(decoded.dup.force_encoding(charset), charset)
            header[:content_type] = 'text/plain'
            header[:content_type].parameters[:charset] = charset
          end
        end

        decoded
      end
    end
  end
end

unless Mail::Message.included_modules.include?(Mail::Jdec::MessagePatch)
  Mail::Message.prepend Mail::Jdec::MessagePatch
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mail-jdec-1.0.4 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.3 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.2 lib/mail/jdec/message_patch.rb