Want to read xxx chats

So far, I've been able to create a label through the UI with import imaplib import getpass import atexit from imapclient import imap_utf7 def find_messages(sock, label): mailbox = imap_utf7.encode(label) label = imap_utf7.encode(label.encode('utf-8')) try: # process regular mailbox sock.select(mailbox) except sock.error: pass else: resp, data = sock.uid('SEARCH', None, '(ALL)') assert resp == 'OK' for uid in data[0].split(): # because we do select, this uid will be valid.yield uid try: # now process chats with that label sock.select("[Gmail]/Chats", True) except sock.error: # access to chats via IMAP is disabled most likely pass else: # resp, data = sock.uid('SEARCH', 'X-GM-RAW', 'label:%s' % label) sock.literal = label resp, data = sock.uid('SEARCH', 'CHARSET', 'UTF-8', 'X-GM-LABELS') assert resp == 'OK' for uid in data[0].split(): # because we do select, this uid will be valid.

As a mum who has given birth early with both dds I do understand that you are concerned.In your example, the second isn't set to resp, data, so those are still the old variables from your normal search, so that could explain false positives.If I search for "label:foo is:chat" in Gmail I get a match, but doing a select("[Gmail]/Chats") followed by uid("SEARCH", "X-GM-RAW", "label:foo") returns no results.Other projects already do most of the work for gmail, e.g.Ba Go Ma (backup google mail) which ships with imap-utf7 support.

Leave a Reply