Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch all nil emails #151

Merged
merged 3 commits into from
Jun 24, 2016
Merged

Conversation

princemaple
Copy link
Contributor

Fix #146

@paulcsmith

I was tempted to swap the order of validate and normailize_addresses, which would reduce a few lines of code, but then I would have to implement Bamboo.Formatter for nil, which doesn't really make sense.

@paulcsmith
Copy link
Contributor

At first glance this looks good. I should have a bit more time to review it more thoroughly later today. Thanks for working on it!

@princemaple
Copy link
Contributor Author

@paulcsmith the current validation logic is designed according to the existing error NilRecipientsError. I'd like to propose that before htting 1.0 we change it to NilRecipientError (notice singular) and raise on any nil recipient seen during the validation.

@princemaple
Copy link
Contributor Author

I was tempted to swap the order of validate and normailize_addresses, which would reduce a few lines of code, but then I would have to implement Bamboo.Formatter for nil, which doesn't really make sense.

On a second thought, it would actually make more sense if we validate after normalizing the email addresses. Because that way, we get to validate everything, instead of letting unknown types go.

Re: nil, we could simply implement it with a raise, just like you did for map, regardless of the tiny bit of awkwardness around implementing the behavior for nil.

If you think it's a good idea, I'll update the PR.

@princemaple
Copy link
Contributor Author

Ping

@paulcsmith
Copy link
Contributor

Thanks for the ping. Yes I think validating after normalizing is a good idea. That way we can raise if email address is nil for stuff that implements the Bamboo.Formatter protocol

Please ping again when ready for re-review :)

@princemaple princemaple force-pushed the po/nil-emails branch 2 times, most recently from 555b92f to 35c7998 Compare May 13, 2016 03:03
@princemaple
Copy link
Contributor Author

princemaple commented May 13, 2016

@paulcsmith so I have this wip commit right now, there is one test failing:
test raises if all receipients are nil (Bamboo.MailerTest) when the email has all to, cc and bcc as nil. Swapping the order of normalization and validation makes one big difference - List.wrap(...) is called beforehand and is turning nil's into []'s.

Hence, I think it's time to ask for clarification. Why did you raise for nil's but not for []'s? Could we simply treat empty lists as the same as nil's so we have a unified case?

end

defp is_nil_recipient?({_, nil}), do: true
defp is_nil_recipient?([]), do: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we simply treat empty lists as the same as nil's so we have a unified case?

meaning flipping this false to true :)

@paulcsmith
Copy link
Contributor

@princemaple I'll have to take a closer look at the code later, but the reason [] does not raise is in this comment: #40 (comment)

Basically, it's that sometimes you send to a list of users and that list of users happens to be an empty list. I think this is a valid case and shouldn't raise, it just shouldn't send the email. The comment should explain the logic a bit better.

Does that make sense?

@princemaple
Copy link
Contributor Author

@paulcsmith I've been busy. I probably don't have time to dig further into this refactor any time soon, so I've deleted the wip commit.

@princemaple
Copy link
Contributor Author

I'm going to leave this PR as pure bug fix / edge case elimination.

@paulcsmith
Copy link
Contributor

paulcsmith commented May 20, 2016

@princemaple This is great. Thanks so much and thanks for letting me know where you're at. I'll take a look at this and merge it in soon. Thanks for all your work on this!

@paulcsmith
Copy link
Contributor

I'm going to try this out one some of our projects on Friday and if all works as expected I'll merge it in :D

@paulcsmith
Copy link
Contributor

@princemaple I gave this a try and it seemed to work great! Thanks so much for tackling this :)

@paulcsmith paulcsmith merged commit 25c9228 into beam-community:master Jun 24, 2016
@princemaple princemaple deleted the po/nil-emails branch June 25, 2016 08:49
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.

None yet

2 participants