#! /bin/sh
# Script to extract mail adresses from mailman subscriber page
# </roster/LISTNAME>

if [ $# -gt 2 -o "$1" = "-h" -o "$1" = "--help" ]
then
    echo "Usage : $0 [source.html [mail_list]]" >&2
    echo "source.html is the HTML page from mailman subscriber list" >&2
    echo "mail_list is the output file" >&2
    echo "without parameters, $0 will read from stdin and write to stdout">&2
    exit 1
fi

if [ $# -ge 1 ]
then
    source="$1"
else
    source="-"
fi

if [ $# -eq 2 ]
then
    cat "$source" | grep '<a href=".*/options/.*/.*--at--.*">' | \
    sed 's;^.*<a href=".*/options/.*/\(.*\)--at--\(.*\)">.*$;\1@\2;' > "$2"
else
    cat "$source" | grep '<a href=".*/options/.*/.*--at--.*">' | \
    sed 's;^.*<a href=".*/options/.*/\(.*\)--at--\(.*\)">.*$;\1@\2;'
fi

exit 0
