ParameterHash is an intelligent Hash that allows you to add parameter values including the MIME extension paramaters that have the name*0=“blah”, name*1=“bleh” keys, and will just return a single key called name=“blahbleh” and do any required un-encoding to make that happen Parameters are defined in RFC2045, split keys are in RFC2231
# File lib/mail/fields/common/parameter_hash.rb, line 15 15: def [](key_name) 16: pairs = select { |k,v| k =~ /^#{key_name}\*/ } 17: pairs = pairs.to_a if RUBY_VERSION >= '1.9' 18: if pairs.empty? # Just dealing with a single value pair 19: super(key_name) 20: else # Dealing with a multiple value pair or a single encoded value pair 21: string = pairs.sort { |a,b| a.first <=> b.first }.map { |v| v.last }.join('') 22: if mt = string.match(/([\w\d\-]+)'(\w\w)'(.*)/) 23: string = mt[3] 24: encoding = mt[1] 25: else 26: encoding = nil 27: end 28: Mail::Encodings.param_decode(string, encoding) 29: end 30: end
# File lib/mail/fields/common/parameter_hash.rb, line 42 42: def decoded 43: map.sort { |a,b| a.first <=> b.first }.map do |key_name, value| 44: %{#{key_name}=#{quote_token(value)}} 45: end.join("; ") 46: end
# File lib/mail/fields/common/parameter_hash.rb, line 32 32: def encoded 33: map.sort { |a,b| a.first <=> b.first }.map do |key_name, value| 34: unless value.ascii_only? 35: value = Mail::Encodings.param_encode(value) 36: key_name = "#{key_name}*" 37: end 38: %{#{key_name}=#{quote_token(value)}} 39: end.join(";\r\n\s") 40: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.