#!/bin/bash

# Remove html and txt mailman archive files for the specified list.
# Use for lists where archives need to be kept but web-accessible archives are not wanted.
# Lists with no need for mbox archives should have mailman archiving disabled.
# TODO patch mailman to add mbox-no-html archives as an actual option, making this script unnecessary.

mailman_prefix='/home/mailman'
list=$1

# check list exists in mailman archives/private/
if [[ ! -d "$mailman_prefix/lists/$list" ]] ;then
	echo "$list is not a valid listname!"
	exit 1
elif [[ ! -d "$mailman_prefix/archives/private/$list" ]] ;then
	echo "$list has no mailman web archives in $mailman_prefix/archives/private/$list"
	exit 1
fi

# remove archive files from archives/private/listname/
find "$mailman_prefix/archives/private/$list/" -mindepth 1 -not -path "*attachments*" -delete

# insert stub index.html
echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML>
  <HEAD>
     <title>$list List</title>
     <META NAME="robots" CONTENT="noindex,follow">
  </HEAD>
  <BODY BGCOLOR="#ffffff">
    <h1>$list List</h1>
    <p>No web-accessible archives are kept for this list. Use ssh to access the mbox archive file.</p>
  </BODY>
  </HTML>
" >> "$mailman_prefix/archives/private/$list/index.html"

exit 0
