Ruby IMAP 库无法解码邮件主题
我的 Gmail 帐户中收到了包含以下主题的邮件:
“400,значение,значение”
这是我用来抓取邮件的代码:
imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false)
imap.login(LOGIN, PASSWORD)
imap.select("INBOX")
messages = imap.search(['ALL']).map do |message_id|
msg =imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
result = {:mailbox => msg.from[0].mailbox, :host => msg.from[0].host, :subject => msg.subject, :created_at => msg.date}
imap.store(message_id, "+FLAGS", [:Deleted])
result
end
imap.expunge()
imap.logout
在 msg.subject 中,我得到以下值“=?KOI8-R?B?MTAwLCDixc7ayc4sIDMwMDAgzMnU0s /X?=
看来IMAP还没有解码它。我应该手动执行还是 IMAP 库可以为我执行?
I have got mail message with following subject in my Gmail accout:
"400, значение, значение"
Here is the code I use to grab mail:
imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false)
imap.login(LOGIN, PASSWORD)
imap.select("INBOX")
messages = imap.search(['ALL']).map do |message_id|
msg =imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
result = {:mailbox => msg.from[0].mailbox, :host => msg.from[0].host, :subject => msg.subject, :created_at => msg.date}
imap.store(message_id, "+FLAGS", [:Deleted])
result
end
imap.expunge()
imap.logout
In msg.subject i've got following value "=?KOI8-R?B?MTAwLCDixc7ayc4sIDMwMDAgzMnU0s/X?="
It seems that IMAP haven't decoded it. Should I do I manually or IMAP library could it for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Mail::Encodings 在这里真的很有帮助:
返回
Mail::Encodings is really helpful here:
returns
使用NKF怎么样?
-mw 表示 MIME 解码和 utf-8 输出
How about using NKF?
-mw means MIME decode and utf-8 output