Sha256: a8e0cb6122eacefb112f01a3e9ccc99071dca82f2e24aeeb353e7977f558f033
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true module Mail module Jdec module ContentTypeElementPatch def initialize(string) if Jdec.enabled? # Remove extra trailing semicolon string = string.gsub(/;+$/, '') # Remove unnecessary space string = string.gsub(/;\s*charset\s+=\s+/i, '; charset=') # Handles name=test string = string.gsub(/name\s*=\s*([^"]+?)\s*(;|$)/im) { %Q|name="#{$1}"#{$2}| } # Handles name=""test"" string = string.gsub(/name\s*=\s*"+([^"]+?)"+\s*(;|$)/im) { %Q|name="#{$1}"#{$2}| } # Handles text; name=test string = string.gsub(/^\s*([^\/]+)\s*;\s*name\s*=\s*(.+)$/im) { "#{$1}/unknown; name=#{$2}" } # Handles ; name=test string = string.gsub(/^\s*;?\s*name\s*=\s*(.+)$/im) { "application/octet-stream; name=#{$1}" } end super rescue Mail::Field::ParseError => e if Jdec.enabled? @main_type = 'application' @sub_type = 'octet-stream' @parameters = ['name' => Jdec::Decoder.force_utf8(string)] else raise e end end end end end Mail::ContentTypeElement.prepend Mail::Jdec::ContentTypeElementPatch
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mail-jdec-1.2.0 | lib/mail/jdec/elements/content_type_element_patch.rb |