选择邮箱“发送邮件”或“所有邮件”在Ruby Net :: IMAP中 [英] Select mailbox "sent mail" or "all mail" in Ruby Net::IMAP
问题描述
我试图在Ruby中使用Net :: IMAP来搜索我发送的所有邮件,但我在选择除了INBOX以外的任何其他东西时遇到问题。
imap.select('INBOX')
正常,但
imap.select('Mail / sent-mail')
显示在Net :: IMAP文档中给我提供了未知邮箱。
顺便说一句,这是用于Gmail。
我也尝试在我的imap.search()中添加in,anywhere,但没有解析。
目前的代码:
imap.select('INBOX')
now = Time.now.localtime - 1209600 #two weeks
since = now.day.to_s()+ - + Date :: MONTHNAMES [now.month] + - + now。 year.to_s()
putssince
puts自
begin
mail_ids = imap.search([FROM,me,SINCE,since])
mail_ids.each do | id |
text = imap.fetch(id,'BODY [HEADER.FIELDS(SUBJECT)]')。to_s.split({)。second.chop
放置文本
end
end
从提供者到提供者。 Gmail的发送邮件文件夹名为 [Gmail] /发送邮件
。
imap.select('[Gmail] / Sent Mail')
仅供参考,Gmail的系统文件夹如下所示:
-
INBOX
-
[Gmail] / All Mail
-
[Gmail] /草稿
-
[Gmail] /发送邮件
-
[Gmail] /垃圾邮件
-
[Gmail] /加星标
-
[Gmail] / Trash
I'm trying to use Net::IMAP in Ruby to search all mail sent by me, but I'm having trouble selecting anything other than INBOX.
imap.select('INBOX')
works fine, but
imap.select('Mail/sent-mail')
as shown on the Net::IMAP documentation gives me "Unknown Mailbox".
Incidentally, this is to be used with gmail.
I also tried adding "in", "anywhere" to my imap.search(), but that didn't parse.
Current code:
imap.select('INBOX')
now = Time.now.localtime - 1209600 #two weeks
since = now.day.to_s() + "-" + Date::MONTHNAMES[now.month] + "-" + now.year.to_s()
puts "since"
puts since
begin
mail_ids = imap.search(["FROM", "me", "SINCE", since])
mail_ids.each do |id|
text = imap.fetch(id, 'BODY[HEADER.FIELDS (SUBJECT)]').to_s.split("{").second.chop
puts text
end
end
The "sent mail" folder will differ from provider to provider. Gmail's "sent mail" folder is named "[Gmail]/Sent Mail
". Select that instead and it'll work.
imap.select('[Gmail]/Sent Mail')
FYI, Gmail's system folders are the following:
INBOX
[Gmail]/All Mail
[Gmail]/Drafts
[Gmail]/Sent Mail
[Gmail]/Spam
[Gmail]/Starred
[Gmail]/Trash
这篇关于选择邮箱“发送邮件”或“所有邮件”在Ruby Net :: IMAP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!