Sha256: 4b745369ec90ec479fc0659ebbc0568f81095d70d7c5c776b35e5d6aa6fb305c

Contents?: true

Size: 753 Bytes

Versions: 2

Compression:

Stored size: 753 Bytes

Contents

module Mail
  module Jdec
    module MessagePatch
      def decoded
        decoded = super

        if Jdec.enabled? && (!has_content_type? || (!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

2 entries across 2 versions & 1 rubygems

Version Path
mail-jdec-1.0.1 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.0 lib/mail/jdec/message_patch.rb