Description
Ultimately Mail::Message#to
delegates to calling #default on the field object of the To: header.
If the To header's field is a Mail::ToField
, Mail::Message#to
returns a Mail::AddressList
due to the way default is defined in Mail::CommonAddress
However, if for some reason the To field encountered an error in parsing the hear's field is now an Mail::UnstructuredField
which returns a string of the decoded value when calling default
I run into issues when I assume Mail::Message#to
is going to return an enumerable Mail::AddressList
, but instead get a string. Any thoughts on what we might be able to change to make this behaviour more expected?
I understand the simplicity of having a default
method on each field and why the header's field is an Unstructured field when the content is not parseable.
Would it make sense to add extra logic in Mail::Message#to
to check the return value of #default
and wrap it in a enumerable or something if it is not an AddressList? Or any other suggestions?
Thanks