def iter_fields(hdr, onlyvalues=False, fields=None):
    """ splits header into lines
        if onlyvalues does not return field names
        if fields returns only specified fields (forces onlyvalues)"""
    if fields:
        for key in hdr:
            if key in fields:
                yield hdr[key]
    elif onlyvalues:
        for val in hdr.values():
            if val:
                yield str(val)
    else:
        for line in repr(hdr).strip().splitlines():
            yield line
