Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@diazruy
Copy link

@diazruy diazruy commented Mar 16, 2016

According to [Sendgrid's SMTP API documentation](
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, arrays (e.g. multiple recipients and substitutions) will be wrapped, reducing the likelihood of exceeding this limit, with the exception being if some element in an array is itself over 1,000 characters long.

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.
end

header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
JSON.pretty_generate(header_opts).gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not even need the gsub at all...

2.3.0 :007 > puts ({a: [1,2,3]}).to_json
{"a":[1,2,3]}
 => nil
2.3.0 :008 > puts JSON.pretty_generate(a: [1, 2, 3])
{
  "a": [
    1,
    2,
    3
  ]
}
 => nil

@diazruy
Copy link
Author

diazruy commented Mar 17, 2016

I have now found out that ActionMailer takes care of wrapping lines, which must be why you had the gsub to add the spaces. Still, using pretty_generate could make that a bit clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.