def parse_flags(headers):
    """Copied from https://github.com/girishramnani/gmail/blob/master/gmail/message.py"""
    if len(headers) == 0:
        return []
    if sys.version_info[0] == 3:
        headers = bytes(headers, "ascii")
    return list(imaplib.ParseFlags(headers))
Copied from https://github.com/girishramnani/gmail/blob/master/gmail/message.py