From e1bdb3170968fd51d8dbbfc736604c435bf8198b Mon Sep 17 00:00:00 2001 From: Ruy Diaz Date: Wed, 16 Mar 2016 15:50:34 -0700 Subject: [PATCH] Use pretty JSON to reduce risk of going over 1k character per line limit According to https://sendgrid.com/docs/API_Reference/SMTP_API/using_the_smtp_api.html #-Requirements-and-Limitations, all lines in a header must be under 1,000 characters. By using [`JSON.pretty_generate`](http://flori.github.io/json/doc/classes/JSON.html#method-i-pretty_generate), arrays will be wrapped, reducing the likelihood of exceeding this limit, with the exception being if some element in an array is itself over 1k long. --- lib/sendgrid.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sendgrid.rb b/lib/sendgrid.rb index 7c68943..75fc6cc 100644 --- a/lib/sendgrid.rb +++ b/lib/sendgrid.rb @@ -254,7 +254,7 @@ def sendgrid_json_headers(mail) header_opts[:filters] = filters if filters && !filters.empty? end - header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3') + JSON.pretty_generate(header_opts).gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3') end def filters_hash_from_options(enabled_opts, disabled_opts)