charlierguo / gmail

A Pythonic interface for Google Mail
MIT License
1.77k stars 386 forks source link

AttributeError: 'int' object has no attribute 'add_label' when trying to add label #69

Open sekurilabs opened 8 years ago

sekurilabs commented 8 years ago

Problem occurs when I get multiple emails and then loop through them and try to add the a label to each email.

example:

mails = g.inbox().mail(sender=sender, prefetch=True)
for m in mails:
   m.add_label("Label")

This returns: AttributeError: 'int' object has no attribute 'add_label'

mhyst commented 8 years ago

Did you login before? Can you paste more complete code? What is happening there is that "m" is an integer instead of a Message object. Integers don't have add_label method. Make sure you are logged in before doing anything else.

mhyst commented 8 years ago

try adding m.fetch() in the loop before add_label is called. Perhaps just the prefetch has failed.

sekurilabs commented 8 years ago

I have logged in before the loop of course. The problem occurs when I do some other things in for loop before I add the label to the emails. For example I'm pulling some data from the headers and some text search in the body of the email. When that is done I want to add the label and remove it from inbox but got the before mentioned error.

I resolved it in ugly way by adding a new loop under the first one with only add_label in it. I know, ugly but it's the only thing that worked.

I will try with m.fetch method and see if it will work.

Thanks!