Using a mailbox (i.e. Rails + ActionMailer), is there a clean way to get the display name of the recipient?
I can get the address with:
mail.to.first
And I can get the formatted display name + address with
mail.header_fields.select{ |f| f.name == "To" }.first.to_s
But how can I get only part of the display name (i.e. before < and > ). I know that someone is going to offer Regex, but this is not what I am looking for, since then I will have to parse some kind of encoding, which probably already makes the mail pearls. I am the author of the popular Mailer library in PHP, and I know about the pitfalls, just assuming the bit before < and > is a human readable heading when 8-bit characters come into play.
I can do it:
mail.header_fields.select{ |f| f.name == "To" }.first.parse.individual_recipients.first.display_name.text_value
But should there be a better way? :)
source share