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\')
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
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. Use LIST "" %
. If you are only interested in children/subfolders
, you can do something like imap.list '', '%/%'
and so on imap.list '', '%/%/%'
lists parent(s) folder 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.
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"