Sha256: cebd7e47bb53ed7c22da239cae081bf8b4fc9f7b138242742d627597565b0e60

Contents?: true

Size: 878 Bytes

Versions: 6

Compression:

Stored size: 878 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, 'utf-8')
            header[:content_type] = 'text/plain'
            header[:content_type].parameters[:charset] = charset
          else
            decoded = Mail::Encodings.transcode_charset(decoded, decoded.encoding, 'utf-8')
          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

6 entries across 6 versions & 1 rubygems

Version Path
mail-jdec-1.0.10 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.9 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.8 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.7 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.6 lib/mail/jdec/message_patch.rb
mail-jdec-1.0.5 lib/mail/jdec/message_patch.rb