def getEmails(since=None,
              accountName=None,
              accountPasswd=None,
              emailFolder=N.FOLDER,
              sender=N.SENDER):
    if accountName is None:
        accountName = N.ACCOUNT_NAME
    if accountPasswd is None:
        accountPasswd = N.ACCOUNT_PASSWD
    g = pygmail.pygmail()
    g.login(accountName, accountPasswd)
    ids = g.get_mails_from(sender, emailFolder, since=since)
    if since != None and not since.tzinfo:
        since = dateutil.parser.parse(str(since) + ' +0000')
    for id in ids:
        status, response = g.get_date_received_from_id(id)
        dateReceivedStr = response[0][1]

        dateReceived = dateutil.parser.parse(
            dateReceivedStr.split('Date:')[1].strip())
        if not dateReceived.tzinfo:
            dateReceived = dateutil.parser.parse(
                dateReceivedStr.split('Date:')[1].strip() + ' +0000')

        if since != None and dateReceived <= since:
            continue  #We have already downloaded this email!
        status, response = g.get_subject_from_id(id)
        subject = response[0][1]
        status, response = g.get_body_from_id(id)
        body = response[0][1]
        yield EMail.EMail(sender=sender,
                          receiver=accountName,
                          subject=subject,
                          body=cleanupEmailText(body),
                          dateReceivedStr=dateReceivedStr)
Esempio n. 2
0
def init():
    """create gmail object and login"""
    config = ConfigParser.ConfigParser()
    config.read(CONFIG_FILE)
    username = config.get('gmail', 'username')
    password = config.get('gmail', 'password')
    gmail = pygmail.pygmail()
    gmail.login(username, password)
    return gmail
def getEmails(since=None, accountName=N.ACCOUNT_NAME, accountPasswd=N.ACCOUNT_PASSWD, emailFolder=N.FOLDER, sender=N.SENDER):
    g = pygmail.pygmail()
    g.login(accountName, accountPasswd)
    ids = g.get_mails_from(sender,emailFolder, since=since)
    if since != None and not since.tzinfo:
        since = dateutil.parser.parse(str(since)+' +0000')
    for id in ids[:100]:
        status, response = g.get_date_received_from_id(id)
        dateReceivedStr = response[0][1]
        
        dateReceived = dateutil.parser.parse(dateReceivedStr.split('Date:')[1].strip())
        if not dateReceived.tzinfo:
            dateReceived = dateutil.parser.parse(dateReceivedStr.split('Date:')[1].strip() + ' +0000')
        
        if since != None and  dateReceived <= since: continue #We have already downloaded this email!
        status, response = g.get_subject_from_id(id)
        subject = response[0][1]
        status, response = g.get_body_from_id(id)
        body = response[0][1]
        yield EMail.EMail(sender=sender, receiver=accountName, subject=subject, body=cleanupEmailText(body), dateReceivedStr = dateReceivedStr)
Esempio n. 4
0
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      tsilivisn
#
# Created:     28/01/2014
# Copyright:   (c) tsilivisn 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------
from pygmail import pygmail
from time import gmtime, strftime

g = pygmail()
g.login('*****@*****.**', 'notorious3')
##
##print g.response
##
##g.get_mailboxes()
##for item in g.mailboxes:
##    print item
##
##print(g.get_mail_count())
##
##print(g.get_unread_count("INBOX"))
##
##id_list = g.get_mails_from("tsilivism")
##
##for mail in id_list:
##    print(g.get_mail_from_id(mail))
##
Esempio n. 5
0
 def __init__(self, username, password):
     self.username = username
     self.password = password
     self.g = pygmail()
     self.mails = None