def env_content(env_data):
    """Returns a tuple with (content, args) for a given environment block.
    
    >>> tex = r"\\begin{foo}[ham]{spam} foo content \\end{foo}"
    >>> env_content(tex)
    ('foo content', ['ham', 'spam'])
    """
    _, __, content = env_data.partition('}')
    content, _, __ = content.rpartition('\\end')
    args = []
    if content.startswith('['):
        arg, _, content = content[1:].partition(']')
        args.append(arg)
    while content.startswith('{'):
        arg, _, content = content[1:].partition('}')
        args.append(arg)
    return content.strip(), args
