(config, target_token)
return success
fetch emails from IMAP server using the given configuration
        each email is parsed to see whether it matches a submission
        if so, its token is extracted and checked against the given
        one.
        if found, the email is deleted from the server and True is returned
fetch emails from IMAP server using the given configuration
        each email is parsed to see whether it matches a submission
        if so, its token is extracted and checked against the given
        one.
        if found, the email is deleted from the server and True is returned
fetch emails from IMAP server using the given configuration each email is parsed to see whether it matches a submission if so its token is extracted and checked against the given one . if found the email is deleted from the server and True is returned
def fetch_test_submissions(config, target_token):
    """ fetch emails from IMAP server using the given configuration
        each email is parsed to see whether it matches a submission
        if so, its token is extracted and checked against the given
        one.
        if found, the email is deleted from the server and True is returned
    """
    from distutils import util
    use_ssl = bool(util.strtobool(config.get('imap_ssl', True)))
    server = IMAPClient(
        config["imap_host"], port=int(config.get("imap_port", 143)), use_uid=True, ssl=use_ssl,
    )
    server.login(config["imap_user"], config["imap_passwd"])
    server.select_folder("INBOX")
    candidates = server.fetch(
        server.search(criteria='NOT DELETED SUBJECT "Drop"'),
        ["BODY[HEADER.FIELDS (SUBJECT)]"],
    )
    success = False
    for imap_id, message in candidates.items():
        subject = message.get(b"BODY[HEADER.FIELDS (SUBJECT)]", "Subject: ")
        try:
            drop_id = find_drop_id.findall(subject.decode('utf-8'))[0]
        except IndexError:
            # ignore emails that are not test submissions
            continue
        if drop_id == target_token:
            server.delete_messages([imap_id])
            success = True
            log.info("Success! Found %s" % target_token)
            break
    server.logout()
    return success
def fetch_test_submissions ( config , target_token ) : from distutils import util use_ssl = bool ( util . strtobool ( config . get ( 'imap_ssl' , True ) ) ) server = IMAPClient ( config [ "imap_host" ] , port = int ( config . get ( "imap_port" , 143 ) ) , use_uid = True , ssl = use_ssl , ) server . login ( config [ "imap_user" ] , config [ "imap_passwd" ] ) server . select_folder ( "INBOX" ) candidates = server . fetch ( server . search ( criteria = 'NOT DELETED SUBJECT "Drop"' ) , [ "BODY[HEADER.FIELDS (SUBJECT)]" ] , ) success = False for imap_id , message in candidates . items ( ) : subject = message . get ( b"BODY[HEADER.FIELDS (SUBJECT)]" , "Subject: " ) try : drop_id = find_drop_id . findall ( subject . decode ( 'utf-8' ) ) [ 0 ] except IndexError : # ignore emails that are not test submissions continue if drop_id == target_token : server . delete_messages ( [ imap_id ] ) success = True log . info ( "Success! Found %s" % target_token ) break server . logout ( ) return success