Browse files

Address parsing failed when the "to" (or "cc", or whatever) was an ar…

…ray. It was also too restrictive in the formats of the addresses #1097 [Jamis]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1149 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 6f5fcc4 commit d5cadfc1108728635055d476eff7b34c975705d6 @dhh dhh committed Apr 13, 2005
View
4 actionmailer/lib/action_mailer/base.rb
@@ -166,7 +166,9 @@ def quote_any_if_necessary(charset, *args)
# it needs to be. This allows extended characters to be used in the
# "to", "from", "cc", and "bcc" headers.
def quote_address_if_necessary(address, charset)
- if address =~ /^([^<>\s]+) (<.*>)$/
+ if Array === address
+ address.map { |a| quote_address_if_necessary(a, charset) }
+ elsif address =~ /^(\S.+)\s+(<.*>)$/
address = $2
phrase = quote_if_necessary($1, charset)
"#{phrase} #{address}"
View
18 actionmailer/test/mail_service_test.rb
@@ -289,7 +289,23 @@ def test_utf8_body_is_not_quoted
created = TestMailer.create_utf8_body @recipient
assert_match(/안녕하세요!/, created.encoded)
- end
+ end
+
+ def test_multiple_utf8_recipients
+ @recipient = ["김치통 <kimchi@example.net.kr>", "\"Example Recipient\" <me@example.com>"]
+ expected = new_mail "utf-8"
+ expected.to = TestMailer.quote_address_if_necessary @recipient, "utf-8"
+ expected.subject = "testing utf-8 body"
+ expected.body = "안녕하세요!"
+ expected.from = TestMailer.quote_address_if_necessary @recipient.first, "utf-8"
+ expected.cc = TestMailer.quote_address_if_necessary @recipient, "utf-8"
+ expected.bcc = TestMailer.quote_address_if_necessary @recipient, "utf-8"
+ expected.date = Time.local 2004, 12, 12
+
+ created = TestMailer.create_utf8_body @recipient
+ assert_match(/\nFrom: =\?.*?\?= <kimchi@example.net.kr>\r/, created.encoded)
+ assert_match(/\nTo: =\?.*?\?= <kimchi.*?>, Example Recipient <me/, created.encoded)
+ end
end
View
8 activerecord/lib/active_record/validations.rb
@@ -369,27 +369,27 @@ def validates_length_of(*attrs)
# Declare different validations per option.
case range_options.first
when :within, :in
- raise ArgumentError, ':within must be a Range' unless option_value.is_a?(Range)
+ raise ArgumentError, ':within must be a Range' unless option_value.is_a?(Range) # '
validates_each(attrs, options) do |record, attr|
next if record.send(attr).nil? and options[:allow_nil]
record.errors.add_on_boundary_breaking(attr, option_value, options[:too_long], options[:too_short])
end
when :is
- raise ArgumentError, ':is must be a nonnegative Integer' unless option_value.is_a?(Integer) and option_value >= 0
+ raise ArgumentError, ':is must be a nonnegative Integer' unless option_value.is_a?(Integer) and option_value >= 0 # '
message = options[:message] || options[:wrong_length]
message = (message % option_value) rescue message
validates_each(attrs, options) do |record, attr, value|
record.errors.add(attr, message) if value.nil? or value.size != option_value
end
when :minimum
- raise ArgumentError, ':minimum must be a nonnegative Integer' unless option_value.is_a?(Integer) and option_value >= 0
+ raise ArgumentError, ':minimum must be a nonnegative Integer' unless option_value.is_a?(Integer) and option_value >= 0 # '
message = options[:message] || options[:too_short]
message = (message % option_value) rescue message
validates_each(attrs, options) do |record, attr, value|
record.errors.add(attr, message) if value.nil? or value.size < option_value
end
when :maximum
- raise ArgumentError, ':maximum must be a nonnegative Integer' unless option_value.is_a?(Integer) and option_value >= 0
+ raise ArgumentError, ':maximum must be a nonnegative Integer' unless option_value.is_a?(Integer) and option_value >= 0 # '
message = options[:message] || options[:too_long]
message = (message % option_value) rescue message
validates_each(attrs, options) do |record, attr, value|

0 comments on commit d5cadfc

Please sign in to comment.