def main(): args = parser.parse_args() gmail = gmail_client.login(args.username, args.password) checker = GmailSpamChecker(gmail, args.subject) exit_code = sum(checker.check_box(mb, l, msg, c) for mb, l, msg, c in [ ["INBOX", "^smartlabel_promo", "ERROR: The email is marked as promotion.", lambda x:x>0], ["INBOX", "", "ERROR: No email received in the inbox.", lambda x:x==0], ["[Gmail]/Spam", "", "ERROR: The email has been marked as Spam!!!", lambda x:x>0], ]) gmail.logout() sys.exit(exit_code)
def main(): args = parser.parse_args() gmail = gmail_client.login(args.username, args.password) checker = GmailSpamChecker(gmail, args.subject) exit_code = sum( checker.check_box(mb, l, msg, c) for mb, l, msg, c in [ [ "INBOX", "^smartlabel_promo", "ERROR: The email is marked as promotion.", lambda x: x > 0 ], [ "INBOX", "", "ERROR: No email received in the inbox.", lambda x: x == 0 ], [ "[Gmail]/Spam", "", "ERROR: The email has been marked as Spam!!!", lambda x: x > 0 ], ]) gmail.logout() sys.exit(exit_code)
def run(): # log in to gmail if 'GMAIL_PASSWORD' in os.environ: g = gmail.login(os.environ['GMAIL_USERNAME'], os.environ['GMAIL_PASSWORD']) else: print "Need GMAIL_USERNAME/GMAIL_PASSWORD to be set in environment" exit(1) parser = argparse.ArgumentParser(description='Check email for sheet change notifications.' 'For when webhooks are not an option.') args = parser.parse_args() # look for recent emails from google notify window = datetime.datetime.now() - datetime.timedelta(days=10) mail = g.inbox().mail(sender='*****@*****.**', after=window) # check emails for action items keys = {} for msg in mail: msg.fetch() print msg.subject # msg.remove_label('sheetmailed') if msg.has_label('sheetmailed'): continue sheet = find_sheet(msg) if sheet is not None: if sheet['key'] in keys: sheet = None else: keys[sheet['key']] = True if sheet is not None: store_work(sheet) msg.add_label('sheetmailed') # leave g.logout()
def __init__(self): threading.Thread.__init__(self) self.client = gmail_client.login(os.environ.get(USER), os.environ.get(PASS))