#!/usr/bin/perl
#SYNOPSIS
#   dm PAT...
#
#DESCRIPTION
#  This searches the mail directory ~/Mail/inbox for files that contain
#  text that matches the pattern PAT, and moves it to ~/Mail/junk. This
#  is a quick way to get rid of all messages that contain a given string
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2;	# Verbose level.

$H = $ENV{HOME} || '.';
$M = "$H/Mail";
$I = "$M/inbox";
$J = "$M/junk";

for $p (@ARGV) {
	$cmd = "grep -l '$p' $I/*";
	@files = `$cmd`;
	for $f (@files) {
		$f =~ s/[\r\s]$//;
		print "\t$f\n" if $V>1;
		unlink $f;
	}
}
