如何在Ruby中解码RFC 2047编码的电子邮件标头? [英] How to decode an RFC 2047 encoded email header in Ruby?

查看:94
本文介绍了如何在Ruby中解码RFC 2047编码的电子邮件标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下标头:

From: =?iso-8859-1?Q?Marta_Falc=E3o?= <marta.falcao@example.com.br>

我可以很容易地在< ,这给我留下了

I can easily split out the stuff before the <, which leaves me with

"=?iso-8859-1?Q?Marta_Falc=E3o?="

我可以用来将其转换为 MartaFalcão

What can I use to turn this into "Marta Falcão"?

推荐答案

感谢 Roland Illig 的评论,使我有两个选择:

Thanks to Roland Illig for his comment, which led me to two options:


  1. install rfc2047-ruby 并调用 Rfc2047.decode(header)

  2. 安装 TMail 并致电 TMail :: Unquoter .unquote_and_convert_to(header,'utf-8')或更好的 TMail :: Address.parse(header).friendly ,后者删除<电子邮件地址> 部分

  1. install rfc2047-ruby and call Rfc2047.decode(header)
  2. install TMail and call TMail::Unquoter.unquote_and_convert_to(header, 'utf-8') or better yet TMail::Address.parse(header).friendly, the latter of which strips out the <email address> part

这篇关于如何在Ruby中解码RFC 2047编码的电子邮件标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆