* teja, on 15.06.2010 09:03:
Hi,

I have a requirement that I want to log-in into a gmail account read
all unread mails, mark them as read and then archive them.
I am using libgmail (version 0.1.11) library to do so, using which I
am able to log-in into a gmail account fetch all unread message and
then read them one by one.
Now my problem is that I am not able to mark the unread mail as read
and archive it.

Below is sample code that I am using.


from libgmail import *

ARCHIVE_ACTION='rc_^i'  #the action string to archive a message
UNREAD_MAILS = "is:unread"

def ArchiveAll():
     ga = GmailAccount(name='username', pw='password')
     print 'logging in...',
     ga.login()
     print 'successful'

     def _getAllUnreadMails():
         return ga.getMessagesByQuery(UNREAD_MAILS, True)

     def _readMail(email):
         emailData = ga.getRawMessage(email)

     def _archiveAndMarkRead(email):
         ga._doThreadAction(ARCHIVE_ACTION, email)
         ga._doThreadAction(U_MARKREAD_ACTION, email)

     emails = _getAllUnreadMails()
     for email in emails:
         eData = _readMail(email)
         #Process email data
         _archiveAndMarkRead(email)

     print 'done'

if __name__ == '__main__':
     ArchiveAll()

after executing this code I am getting following error

HTTP Error 500: Internal Server Error
Traceback (most recent call last):
   File "test_libgmail.py", line 30, in<module>
     ArchiveAll()
   File "test_libgmail.py", line 26, in ArchiveAll
     [_archiveAndMarkRead(t) for t in sr[1]]

In the code you show above there is no line

  [_archiveAndMarkRead(t) for t in sr[1]]

Instead you have

  _archiveAndMarkRead(email)

I tentatively conclude from this that the error is in your real code, as opposed to the code you've shown.



   File "test_libgmail.py", line 21, in _archiveAndMarkRead
     ga._doThreadAction(ARCHIVE_ACTION, thread)
   File "/home/3rdparty/libgmail/libgmail.py", line 669, in
_doThreadAction
     items = self._parsePage(_buildURL(**params))
   File "/home/3rdparty/libgmail/libgmail.py", line 383, in _parsePage
     items = _parsePage(self._retrievePage(urlOrRequest))
   File "/home/3rdparty/libgmail/libgmail.py", line 99, in _parsePage
     lines = pageContent.splitlines()
AttributeError: 'NoneType' object has no attribute 'splitlines'

Can anyone help me in figuring out what's going wrong here?

You're passing a None value.

It originates somewhere in your real code, which it appears that you have not 
shown.


I guess google has deprecated this way of marking emails, correct me
if I am wrong here.
But if its true, is there any other way or library in Python to meet
my requirements?

You can access GMail via an ordinary e-mail client. What's that called, POP protocol? I think the protocol for sending is SMTP. Any library handling those two protocols can be used.


Cheers & hth.,

- Alf, who, unfortunately, wrt. to your real code, is not a telepath :-)

--
blog at <url: http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to