Hey Hey,
Since this forum hasn't been used in a while, it's time to use it again... here's my lastest bit of playing around... a small simple implementation of libgmail from http://libgmail.sourceforge.net/.
Of course you'll need to go there and download libgmail and have it available to the script...
Here's the code
You can find some examples and more information on my blog post related to it, I'll also have follow up examples in the next couple days.. -- http://www.computerdefense.org/?p=54Code:#!/usr/bin/python ''' Name: checkgmail.py Created by: HTRegz ([email protected]) Date Created: April 27th, 2006 Functional Spec: Provide command line access to gmail. Details and examples @ www.computerdefense.org) ''' import libgmail, sys, getopt, getpass def parseArgs(): try: opts, args = getopt.getopt(sys.argv[1:], "aruhL:F:RSCQ:N:U:P:") except getopt.GetoptError: showHelp() global password global type global label global showMsg global address global showSubject global showCount global query global displayCount global username password = None type = "UNREAD" label = "inbox" showMsg = False address = None showSubject = False showCount = False query = None username = None displayCount = None for o, a in opts: if ( o == "-a" ): type = "ALL" elif ( o == "-u" ): type = "UNREAD" elif ( o == "-r" ): type = "READ" if ( o == "-L" ): label = a if ( o == "-F"): address = a if ( o == "-R" ): showMsg = True if ( o == "-S" ): showSubject = True if ( o == "-C" ): showCount = True if ( o == "-Q" ): query = a if ( o == "-U" ): username = a if ( o == "-P" ): password = a if ( o == "-N" ): displayCount = a if (o == "-h" ): showHelp() def showHelp(): print "Usage: "+ sys.argv[0] + " <option> <parameters>" print "\n" print "Options:" print "-a All messages" print "-r Only read messages" print "-u Only unread messages" print "-h Display this help message" print "Parameters:" print "-L <label> Search only in a specific label (default: inbox)" print " Use ALL to search all folders" print "-F <address> Only messages from a specific address" print "-R Read the messages (display message content)" print "-S Return the subject lines" print "-C Display a message count" print "-Q <query> Run the specified query (search)" print "-N Number of messages to return (default: ALL)" print "-U <username> GMail username" print "-P <password> GMail Password (default: prompt)" sys.exit() if __name__ == "__main__": parseArgs() if ( username == None ): username = raw_input("Username: ") if ( password == None ): password = getpass.getpass("Password: ") ga = libgmail.GmailAccount(username, password) try: ga.login() except libgmail.GmailLoginFailure: print "Login Failure: Unknown username/password." sys.exit() if ( type == "ALL" ): search = "" elif ( type == "READ" ): search = "is: read " else: search = "is: unread " if ( address != None ): search += "from: " + address + " " if ( label != None ): search += "in: "+ label + " " if ( query != None ): search += query + " " tmp = ga.getMessagesByQuery(search, "allPages") counter = 0 for thread in tmp: for msg in thread: counter += 1 if ( showSubject == True ): print msg.subject if ( showMsg == True ): print msg.source if ( counter == displayCount ): break if ( counter == displayCount ): break if ( showCount == True ): print counter
Peace,
HT




Reply With Quote