List the a maildir.

    store is an abstract representation of the source maildir. 

    maildir is the local maildir to which mail will be pulled.

    This is a generator for a reason. Because of the way ssh
    multi-mastering works a single open TCP connection allows multiple
    virtual ssh connections. So the encryption and tcp only has to be
    done once.

    If this command returned a list then the ssh list command would
    have finished and the ssh connection for each message would have
    to be made again.

def _list_remote(store, maildir, verbose=False):
    """List the a maildir.

    store is an abstract representation of the source maildir. 

    maildir is the local maildir to which mail will be pulled.

    This is a generator for a reason. Because of the way ssh
    multi-mastering works a single open TCP connection allows multiple
    virtual ssh connections. So the encryption and tcp only has to be
    done once.

    If this command returned a list then the ssh list command would
    have finished and the ssh connection for each message would have
    to be made again.
    """
    # This command produces a list of all files in the maildir like:
    #   base-filename timestamp container-directory
    command = """echo {maildir}/{{cur,new}} | tr ' ' '\\n' | while read path ; do ls -1Ugo --time-style=+%s $path | sed -rne "s|[a-zA-Z-]+[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+([0-9]+)[ \t]+([0-9]+\\.[A-Za-z0-9]+)(\\.([.A-Za-z0-9-]+))*(:[2],([PRSTDF]*))*|\\2 \\1 $path|p";done"""
    stdout = store.cmd(command, verbose)
    lines = stdout.split("\n")
    for line in lines:
        parts = line.split(" ")
        if len(parts) >= 3:
            yield parts[0:3]