Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ignore nil in addresses so things do not blow up when e.g. a user had no email #451

Merged
merged 1 commit into from

3 participants

@grosser

or one of the emails passed was nil

@radar

Could you please explain the usecase for this?

@grosser

e.g. UserMailer.deliver(User.all.map(&:email)) -> will blow up when 1 user has no email, there are ways around this like compact etc, but that means watching every input to cc/to/bcc all the time and always calling compact/ bcc = xxx if xxx
or risking not sending an email, so rather err on the side of ignoring -> in an error case the cc/bcc without an email address does not get an email

@radar

Ok, that sounds legitimate. I agree that they shouldn't blow up at all when there is a nil email address. Thanks for providing steps to reproduce! :)

@radar

@mikel: This patch is good to merge.

@mikel
Owner

Thanks @grosser

@mikel mikel merged commit ab2c6fd into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2012
  1. @grosser

    ignore nil in addresses so things do not blow up when e.g. a user had…

    grosser authored
    … no email or one of the emails passed was nil
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 2 deletions.
  1. +2 −2 lib/mail/encodings.rb
  2. +7 −0 spec/mail/encodings_spec.rb
View
4 lib/mail/encodings.rb
@@ -178,10 +178,10 @@ def Encodings.unquote_and_convert_to(str, to_encoding)
def Encodings.address_encode(address, charset = 'utf-8')
if address.is_a?(Array)
# loop back through for each element
- address.map { |a| Encodings.address_encode(a, charset) }.join(", ")
+ address.compact.map { |a| Encodings.address_encode(a, charset) }.join(", ")
else
# find any word boundary that is not ascii and encode it
- encode_non_usascii(address, charset)
+ encode_non_usascii(address, charset) if address
end
end
View
7 spec/mail/encodings_spec.rb
@@ -757,6 +757,13 @@
Mail::Encodings.address_encode(raw, 'utf-8').should eq encoded
end
+ it "should ignore single nil" do
+ Mail::Encodings.address_encode(nil, 'utf-8').should eq nil
+ end
+
+ it "should ignore nil in arrays" do
+ Mail::Encodings.address_encode(["aa@bb.com", nil], 'utf-8').should eq "aa@bb.com"
+ end
end
end
Something went wrong with that request. Please try again.