Select mailbox “sent mail” or “all mail” in Ruby Net::IMAP

萝らか妹 提交于 2019-11-30 03:23:31

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

You can find the names of all folders with:

imap.list('*', '*') 

The Gmail folders name's will change depending on the user selected language. So in Spanish for example:

"[Gmail]/All" Mail will be "[Gmail]/Todos"

I found the following to be helpful (ruby 2.0.0-p195)

# list all folders
imap.list '', '%'

Don't use LIST "" *. you many end up with thousands of mailboxes. The way to do is this is like @maček suggested. LIST "" % . And If you are only interested in children/subfolders then you can do something like imap.list '', '%/%' and so on imap.list '', '%/%/%'

dump of the terminal:

==> lists parents only . depth 1

C: RUBY0002 LIST "" "%"
S: * LIST (\HasNoChildren) "/" Calendar
S: * LIST (\HasNoChildren) "/" Contacts
S: * LIST (\HasNoChildren) "/" "Deleted Items"
S: * LIST (\HasNoChildren) "/" Drafts
S: * LIST (\Marked \HasChildren) "/" INBOX
S: * LIST (\HasNoChildren) "/" Journal
S: * LIST (\HasNoChildren) "/" "Junk E-Mail"
S: * LIST (\HasNoChildren) "/" Notes
S: * LIST (\HasNoChildren) "/" Outbox
S: * LIST (\HasNoChildren) "/" "Sent Items"
S: * LIST (\HasNoChildren) "/" Tasks
S: RUBY0002 OK LIST completed.

list children . depth 2.

C: RUBY0003 LIST "" "%/%"
S: * LIST (\HasNoChildren) "/" INBOX/subfolder
S: RUBY0003 OK LIST completed.
C: RUBY0004 SELECT INBOX/subfolder
S: * 2 EXISTS
S: * 0 RECENT
S: * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
S: * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
S: * OK [UIDVALIDITY 37286] UIDVALIDITY value
S: * OK [UIDNEXT 6] The next unique identifier value
S: RUBY0004 OK [READ-WRITE] SELECT completed.

read this helpful HOWTO click-me please

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!