#! /bin/sh

# Script to rename a mailman list
# Copyright 2008, Florian Birée
#
#########################################
# License (<http://sam.zoy.org/wtfpl/>)
#
#  DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#                    Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar
#  14 rue de Plaisance, 75014 Paris, France
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
#  0. You just DO WHAT THE FUCK YOU WANT TO. 
#
###########################################
#
# Source of commands : <http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq03.004.htp>

if [ $# -ne 2 ]
then
    echo "Usage : $0 oldlist newlist" >&2
    exit 1
fi

oldlist="$1"
newlist="$2"

mailman_bin="/usr/lib/mailman/bin"
mailman_var="/var/lib/mailman"

"$mailman_bin"/config_list -o tmpfile $oldlist
"$mailman_bin"/config_list -i tmpfile $newlist
"$mailman_bin"/list_members -o digest_file -p -d -f "$oldlist"
"$mailman_bin"/list_members -o regular_file -p -r -f "$oldlist"
"$mailman_bin"/add_members -d digest_file -r regular_file "$newlist"

# move other infos and archives
cd "$mailman_var"

mv "lists/$oldlist" "lists/$newlist"
mv "archives/private/$oldlist" "archives/private/$newlist"
mv "archives/private/$oldlist.mbox" "archives/private/$newlist.mbox"
mv "archives/private/$newlist.mbox/$oldlist.mbox" "archives/private/$newlist.mbox/$newlist.mbox"

"$mailman_bin"/arch --wipe "$newlist"

exit 0
