def check(self): global usr, pwd, msgs self.ga = libgmail.GmailAccount(usr, pwd) self.ga.login() self.sources = [ cleanGmailSubject(i.subject) for i in self.ga.getMessagesByQuery("is:unread in:inbox") ] self.ms = self.ga.getunreadInfo() if self.ms != None: #self.msgs = str(self.ms) #self.msgs = self.msgs.replace('[' , '') #self.msgs = self.msgs.replace(']' , '') #self.msgs = self.msgs.replace('inbox' , '') #self.msgs = self.msgs.replace(' ' , '') #self.msgs = self.msgs.replace(',' , '') #self.msgs = self.msgs.replace("'" , '') self.msgs = re.sub(r"\[|\]|(inbox)|,|'| ", "", str(self.ms)) else: self.msgs = "0" #if str(self.msgs) == "1": # txt = " Unread Message" #else: # txt = " Unread Messages" # #print str(self.msgs) + txt msgs = self.sources
def smtp_AUTH(self, arg): """ """ kind, data = arg.split(" ") # TODO: Ensure kind == "PLAIN" data = base64.decodestring(data)[1:] user, pw = data.split("\x00") global ga ga = libgmail.GmailAccount(user, pw) try: ga.login() except: self.push("535 Authorization failed") else: self.push('235 Ok')
def mw_gmail_update(self): try: ga = libgmail.GmailAccount(self.account, self.password) ga.login() #result = ga.getMessagesByFolder('inbox', True) unread = ga.getUnreadMsgCount() inbox = self.getInboxMsgCount(ga) # Format the message self.wm_gmail_message.set_text('%d/%d' % (unread, inbox)) except: import traceback traceback.print_exc() self.wm_gmail_message.set_text('N.A.') # Check again in 10 minutes. self.events.add_timer(event.TimerEvent(GMAILTimerEvent, after=600))
def main(): if libgmail.Version != '0.1.8-rafael4': warn = """ Warning: Please use libgmail-0.1.8-rafael4. Without it you won't have access to all features. Look at gmailreader's web page for details. """ sys.stderr.write(warn) conf = Config(os.path.expanduser('~/.gmailreader/config')) email = conf.get('username', lambda: raw_input("Username: "******"Password: "******"Login failed: %s" % e.message raise SystemExit
if __name__ == "__main__": import sys from getpass import getpass try: name = sys.argv[1] to = sys.argv[2] subject = sys.argv[3] msg = sys.argv[4] except IndexError: print "Usage: %s <account> <to address> <subject> <body>" % sys.argv[0] raise SystemExit pw = getpass("Password: "******"\nPlease wait, logging in..." ga.login() print "Log in successful.\n" gmsg = libgmail.GmailComposedMessage(to, subject, msg) if ga.sendMessage(gmsg): print "Message sent `%s` successfully." % subject else: print "Could not send message." print "Done."
def get_gmail_mail_count(self): """Returns the number of unread mails in this Gmail account.""" import time gmail = libgmail.GmailAccount(self.username, self.password) gmail.login() return len(gmail.getMessagesByQuery('is:unread', True))
def __init__(self, username, password): super(GoogleAddressBookAccount, self).__init__(username, password) self._acc = libgmail.GmailAccount(self._username, self._password)
#!/usr/bin/env python import libgmail ga = libgmail.GmailAccount("name", "pass") ga.login() messagecount = ga.getUnreadMsgCount() print 'You have ' + str(messagecount) + ' new G Mail messages.' folder = ga.getMessagesByFolder('inbox') x = 1 for thread in folder: print 'Thread ' + str(x) + ', ' print 'Length ' + str(len(thread)) + ', ' for message in thread: print 'From ' + str(message.author) + ', ' print 'About, ' + str(message.subject) + ', ' x += 1
try: threads = items[libgmail.D_THREAD] except KeyError: break else: for th in threads: if not type(th[0]) is libgmail.types.ListType: th = [th] threadsInfo.append(th) threadListSummary = items[libgmail.D_THREADLIST_SUMMARY][0] threadsPerPage = threadListSummary[libgmail.TS_NUM] index += threadsPerPage yield libgmail.GmailSearchResult(ga, (searchType, kwargs), threadsInfo) ga = libgmail.GmailAccount("*****@*****.**", "PyL070407_") ga.login() for page in thread_search(ga, "query", q="is:chat"): print "New Page" time.sleep(13) for thread in page: if thread.info[0] == thread.info[10]: # Common case: Chats that only span one message filename = "chats/%s_%s.eml" % (thread.id, thread.id) #only download the message if we don't have it already if os.path.exists(filename): print "already have %s" % filename continue print "Downloading raw message: %s" % filename, message = ga.getRawMessage(thread.id).decode('utf-8').lstrip()
import libgmail except ImportError: # Urghhh... sys.path.insert( 1, os.path.realpath( os.path.join(os.path.dirname(__file__), os.path.pardir))) import libgmail if __name__ == "__main__": import sys from getpass import getpass if not os.path.isfile(filename): ga = libgmail.GmailAccount(name, pw) try: ga.login() except libgmail.GmailLoginFailure: print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" print "<openbox_pipe_menu>" print " <item label=\"login failed.\">" print " <action name=\"Execute\"><execute>" + browser + " " + login + "</execute></action>" print " </item>" print "</openbox_pipe_menu>" raise SystemExit else: ga = libgmail.GmailAccount(state=libgmail.GmailSessionState( filename=filename))
import libgmail password = raw_input("add your password (Be carful! its not hidden)") ga = libgmail.GmailAccount("*****@*****.**", password) ga.login() folder = ga.getMessagesByFolder('inbox') for thread in folder: print thread.id, len(thread), thread.subject for msg in thread: print " ", msg.id, msg.number, msg.subject print msg.source input()
import libgmail ga = libgmail.GmailAccount("*****@*****.**", "qwerty") ga.login() folder = ga.getMessagesByFolder('inbox') def KnownGuid(guid): print "not implemented" return False # check against the rss to prevent downloading spam def GuidInRss(guid): #lookup if guid == "rwaudio20041202.mp3": return True else: return False for thread in folder: #print thread.id, len(thread), thread.subject for msg in thread: print " ", msg.id, msg.number, msg.subject if KnownGuid(msg.subject) == False: if GuidInRss(msg.subject): print "downloading: ", msg.subject show = open(msg.subject, "w") show.write(msg.attachments[0]._getContent()) show.close()
try: threads = items[libgmail.D_THREAD] except KeyError: break else: for th in threads: if not type(th[0]) is libgmail.types.ListType: th = [th] threadsInfo.append(th) threadListSummary = items[libgmail.D_THREADLIST_SUMMARY][0] threadsPerPage = threadListSummary[libgmail.TS_NUM] index += threadsPerPage yield libgmail.GmailSearchResult(ga, (searchType, kwargs), threadsInfo) ga = libgmail.GmailAccount("*****@*****.**", "") ga.login() for page in thread_search(ga, "query", q="is:chat"): print "New Page" time.sleep(13) for thread in page: if thread.info[0] == thread.info[10]: # Common case: Chats that only span one message filename = "chats/%s_%s.eml" % (thread.id, thread.id) #only download the message if we don't have it already if os.path.exists(filename): print "already have %s" % filename continue print "Downloading raw message: %s" % filename, message = ga.getRawMessage(thread.id).decode('utf-8').lstrip()
#tregex = re.compile("rawdata_([0-9a-f]{32,32})(.*)\.bz2") #outp = commands.getoutput("s3cmd ls s3://questhelper_data/rawdata_") #print "S3 listing snagged" #for line in outp.split('\n'): # if line == "Bucket 's3://questhelper_data':": # continue # serch = tregex.search(line) # if not serch: # print line # toki = serch.group(1) # ext = serch.group(2) # #print toki # filehashdict[toki] = ext #print "Filenames isolated: %d" % len(filehashdict) ga = libgmail.GmailAccount(passwords.gmail_username, passwords.gmail_password) ga.login() destination = "./LocalInput/" label = passwords.gmail_label argument = "!label:" + label + " has:attachment" argument = "has:attachment" inbox = ga.getMessagesByQuery(argument) i = 0 print ` len(inbox) ` + " messages" while len(inbox) > 0: try: for thread in inbox: for message in thread:
import sys from getpass import getpass try: user = sys.argv[1] except IndexError: user = raw_input("Gmail account name: ") try: password = sys.argv[3] except IndexError: password = getpass("Password: "******"Connecting to %[email protected]..." % user ga = libgmail.GmailAccount(user, password) try: ga.login() except libgmail.GmailLoginFailure: print 'Unable to login as %s on GMail' % user else: print 'Successfully connected to GMail' try: label = sys.argv[2] except IndexError: print 'List of folders/labels:' labels = libgmail.STANDARD_FOLDERS + ga.getLabelNames() for optionId, optionName in enumerate(labels):