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

后端 未结 4 1219
温柔的废话
温柔的废话 2020-12-28 17:47

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\')


        
相关标签:
4条回答
  • 2020-12-28 17:55

    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
    0 讨论(0)
  • 2020-12-28 17:56

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

    # list all folders
    imap.list '', '%'
    
    0 讨论(0)
  • 2020-12-28 18:06

    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.
    
    0 讨论(0)
  • 2020-12-28 18:16

    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"

    0 讨论(0)
提交回复
热议问题