diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-12-06 16:25:49 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-12-06 16:35:10 +0000 |
commit | 67ab55412f1fad8f6ab9e457f6d81b68d6a47b8c (patch) | |
tree | b7a79f7b28830046ddb57c93f4be0239626092e5 | |
parent | ac1c1329eeebefec8c9952cbae372fe8c4255307 (diff) |
Patch the parameter hash used in Mail to handle nil values.
-rw-r--r-- | lib/mail_handler/backends/mail_extensions.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 |