Pergunta

I am using Gmail gem to connect to user's Gmail account and search emails:

gmail = Gmail.connect('user', 'pass')
results = gmail.inbox.search(:subject => 'insert_keyword_here')

This returns only the items in Inbox (labeled with Inbox), not the ones in "All Mail" (also known as "archived email").

How can I search "All Mail", not just Inbox?

Foi útil?

Solução

Perhaps a bit late to the party, but it could be useful for someone for sure...

If you need to get language-agnostic, you should pick the folder using one of the tags. Here's how to find "all mail" folder:

mailbox_all_mail = imap.list('', '*').find{|mb| mb.attr.include?(:All)}

And then select (or examine) its name:

imap.examine(mailbox_all_mail.name)

That should do the trick.

Outras dicas

With Gmail gem:

gmail = Gmail.connect('user', 'pass')
results = gmail.mailbox('[Gmail]/All Mail').search(:subject => 'insert_keyword_here')

Generic IMAP, without using the Gmail gem:

gmail.login('user','pass')
gmail.select('[Gmail]/All Mail')
results = gmail.search(["SUBJECT", "insert_keyword_here"])

Bonus vote will go to whoever points out a smart practical approach for non-English language locales (since 'All Mail' would be different e.g. 'Todos' in Spanish)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top