Module: Mail::Jenc::UnstructuredFieldPatch

Defined in:
lib/mail/jenc/fields/unstructured_field_patch.rb

Instance Method Summary collapse

Instance Method Details

#initialize(name, value, charset = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mail/jenc/fields/unstructured_field_patch.rb', line 6

def initialize(name, value, charset = nil)
  if Jenc.enabled?
    if value.is_a?(String) && value.encoding == Encoding::UTF_8 && charset && charset.downcase != 'utf-8'
      if !value.ascii_only?
        value = BEncoder.encode(value, charset)
      elsif value !~ Mail::Encodings::ENCODED_VALUE
        charset = 'us-ascii'
      end
    end
  end
  super
end