mikel/mail — Issue #299: Mail::Message.new fails to parse UTF8 name in the :to field
Author: leonelgalan
Created: 2011-11-08 14:53:57+00:00
State: open

Error and backtrace when calling 'deliver' on a Message object that failed to parse a UTF8 name in the :to key in the initializer.

```
NoMethodError: undefined method 'encoding' for ["\"á\" "]:Array

[GEM_ROOT]/gems/mail-2.2.19/lib/mail/fields/unstructured_field.rb:75:in 'do_decode'
[GEM_ROOT]/gems/mail-2.2.19/lib/mail/fields/unstructured_field.rb:56:in 'decoded'
[GEM_ROOT]/gems/mail-2.2.19/lib/mail/fields/unstructured_field.rb:60:in 'default'
[GEM_ROOT]/gems/mail-2.2.19/lib/mail/field.rb:123:in 'method_missing'
[GEM_ROOT]/gems/mail-2.2.19/lib/mail/message.rb:1107:in 'default'
[GEM_ROOT]/gems/mail-2.2.19/lib/mail/message.rb:1081:in 'to'
[GEM_ROOT]/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:440:in 'set_payload_for_mail'
[GEM_ROOT]/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:425:in 'block in deliver_mail'
[GEM_ROOT]/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in 'block in instrument'
[GEM_ROOT]/gems/activesupport-3.0.10/lib/active_support/notifications/instrumenter.rb:21:in 'instrument'
[GEM_ROOT]/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in 'instrument'
[GEM_ROOT]/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:424:in 'deliver_mail'
[GEM_ROOT]/gems/mail-2.2.19/lib/mail/message.rb:230:in 'deliver'
```

Sample Code

```ruby
m1 = Mail::Message.new(to: '"á" ')
m1.header[:to].field.class
#=> Mail::UnstructuredField

m2 = Mail::Message.new
m2[:to] = '"á" '
m2.header[:to].field.class
#=> Mail::ToField
```