문제

I'm using imaplib for my project because I need to access gmails accounts. Fact: With gmail's labels each message may be on an arbitrary number of folders/boxes/labels.

The problem is that I would like to get every single label from every single message.

The first solution it cames to my mind is to use "All Mail" folder to get all messages and then, for each message, check if that message is in each one of the available folders.

However, I find this solution heavy and I was wondering if there's a better way to do this.

Thanks!

도움이 되었습니까?

해결책

To get all the labels for a given message within gmail you can do the following

t, d = imapconn.uid('FETCH', uid, '(X-GM-LABELS)')
or
t, d = imapconn.fetch(uid, '(X-GM-LABELS)')

BTW: You can find more on gmail imap extensions at http://code.google.com/apis/gmail/imap/

다른 팁

in imap you don't have labels, gmail 'emulates' them on imap, you can low at the raw source of a message picked from imap an check if it has some custom header with the label

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top