From 17169b3037037103a54317c1f03b86f1359ed1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 3 Nov 2016 02:26:12 +0100 Subject: [PATCH] FIX: issues with 'X-MSYS-API' custom header --- lib/email/sender.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/email/sender.rb b/lib/email/sender.rb index 6e58a704348..8cad0c8067f 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -203,11 +203,16 @@ module Email end def merge_json_x_header(name, value) - mc_metadata = JSON.parse(@message.header[name].to_s) rescue nil - mc_metadata ||= {} - mc_metadata.merge!(value) + data = JSON.parse(@message.header[name].to_s) rescue nil + data ||= {} + data.merge!(value) + # /!\ @message.header is not a standard ruby hash. + # It can have multiple values attached to the same key... + # In order to remove all the previous keys, we have to "nil" it. + # But for "nil" to work, there must already be a key... + @message.header[name] = "" @message.header[name] = nil - @message.header[name] = mc_metadata.to_json + @message.header[name] = data.to_json end end