Module: Mail::Jenc::AttachmentsListPatch

Defined in:
lib/mail/jenc/attachments_list_patch.rb

Instance Method Summary collapse

Instance Method Details

#[]=(name, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mail/jenc/attachments_list_patch.rb', line 4

def []=(name, value)
  if Jenc.enabled?
    if name && !name.ascii_only? && value.is_a?(Hash) && (charset = value.delete(:header_charset))
      mime_type = set_mime_type(name)
      transcoded = Mail::Encodings.transcode_charset(name, name.encoding, charset)
      if Jenc.rfc2231
        encoded = RFC2231Encoder.encode(transcoded, charset: charset)
        value[:content_disposition] ||= %Q|#{@content_disposition_type}; #{encoded}|
        encoded = Mail::Encodings.b_value_encode(transcoded)
        value[:content_type] ||= %Q|#{mime_type}; name="#{encoded}"|
      else
        encoded = Mail::Encodings.b_value_encode(transcoded)
        value[:content_disposition] ||= %Q|#{@content_disposition_type}; filename="#{encoded}"|
        value[:content_type] ||= %Q|#{mime_type}; name="#{encoded}"|
      end
      value[:transfer_encoding] = 'binary'
    end
  end
  super
end