def parse_bro_metadata(filename, meta_separator):
    """Parses Bro metadata.

    This function parses Bro metadata that is encoded in the filename. The
    parsed metadata can include any of the following, in order:
        File source (e.g. HTTP, SMTP, SMB)
        Connection UID
        File UID
        Originator address
        Responder address
        File MIME type
        Flex metadata (e.g. for files sourced from HTTP, this is the HTTP host
            metadata, for files sourced from SMTP, this is the SMTP subject
            metadata)

    The filename must adhere to the following pattern (where <SEP> is a
    defined separator string):
        <random integers><SEP><Bro Source field OR empty><SEP><Bro Connection UID field OR empty><SEP><Bro file UID field OR empty><SEP><Bro id.orig_h field OR empty><SEP><Bro MIME type field OR empty><SEP><Bro metadata field OR empty><SEP>

    In the example below, the separator string is "S^E^P^" and all fields are
    present except the MIME type field:
        0046S^E^PHTTPS^E^PC5lS4i1kVyL9cCrMAfS^E^PFT9iQI3w7gllMdjxEhS^E^P192.168.1.1S^E^P192.168.1.2S^E^PS^E^Pexample.comS^E^P

    The example expands to this:
        '0046'
        'HTTP'
        'C5lS4i1kVyL9cCrMAf'
        'FT9iQI3w7gllMdjxEh'
        '192.168.1.1'
        '192.168.1.2'
        ''
        'example.com'
        ''

    Args:
        filename: Bro filename to parse.
        meta_separator: String used as the separator in the filename.

    Returns:
        Tuple containing parsed Bro metadata as a dictionary and Bro MIME
        type (flavors) as a list.
    """
    bro_metadata = {}
    bro_flavors = []

    split_filename = filename.split(meta_separator)
    bro_metadata["broSource"] = split_filename[1]
    bro_metadata["broUid"] = split_filename[2]
    bro_metadata["broFuid"] = split_filename[3]
    bro_metadata["broIdOrigH"] = split_filename[4]
    bro_metadata["broIdRespH"] = split_filename[5]
    if split_filename[6]:
        bro_metadata["broMimeType"] = split_filename[6]
        bro_flavors.append(split_filename[6])
    if split_filename[7]:
        bro_metadata["broMetadata"] = split_filename[7]

    return (bro_metadata, bro_flavors)