def scan(string):

    if not isinstance(string, str):
        raise DecodingError("Scanner works with byte strings only")

    tokens = tokenize(string)
    if not tokens:
        tokens = [default_content_type()]
    try:
        return traverse(Start(), TokensIterator(tokens, string))
    except DecodingError:
        raise
    except Exception:
        raise DecodingError("Malformed MIME message"), None, sys.exc_info()[2]
Scanner that uses 1 pass to scan the entire message and
dataset/ETHPy150Open mailgun/flanker/flanker/mime/message/scanner.py/scan