Skip to content

Mail::Message#to does not always return the same type of object #997

Open
@kjg

Description

@kjg

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions