From 67ab55412f1fad8f6ab9e457f6d81b68d6a47b8c Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 16:25:49 +0000 Subject: Patch the parameter hash used in Mail to handle nil values. --- lib/mail_handler/backends/mail_extensions.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/mail_handler/backends/mail_extensions.rb') diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index d9106948d..f756abd1a 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -1,3 +1,5 @@ +require 'mail/message' +require 'mail/fields/common/parameter_hash' module Mail class Message attr_accessor :url_part_number @@ -45,4 +47,21 @@ module Mail self end end + + # A patched version of the parameter hash that handles nil values without throwing + # an error. + class ParameterHash < IndifferentHash + + def encoded + map.sort { |a,b| a.first.to_s <=> b.first.to_s }.map do |key_name, value| + # The replacement of this commented out line is the change + # unless value.ascii_only? + unless value.nil? || value.ascii_only? + value = Mail::Encodings.param_encode(value) + key_name = "#{key_name}*" + end + %Q{#{key_name}=#{quote_token(value)}} + end.join(";\r\n\s") + end + end end \ No newline at end of file -- cgit v1.2.3