#!/usr/local/bin/perl

# @(#)pmcancel	1.2 (PGP Moose) 96/02/14

# Originally discovered in a message from tale@uunet.uu.net (David C Lawrence),
# but I don't know if he is the original author or not. -- Greg Rose

# $user below is used for the Approved: line
# any existing control header is removed, as is any Distribution: (so
#   the cancel will go "world")
# a new date header is inserted, and the message-id munged to have a
#   leading "cPROCESSID-" at the start of the original message-id
# the subject is munged into the old style cmsg cancel form
# the path is reset so it will propagate properly
# the lines header is changed to reflect the new minimal body

$* = 1;         # let ^ and $ work with newlines embedded in input.
$/ = "";        # read until empty line mode
$_ = <STDIN>;
undef $/;       # read in whole file mode
$body = <STDIN>;
$user = `whoami` . '@' . `hostname`;
$user =~ s/\n//g;

$time  = time;

chop($date = `/usr/bin/date -u '+%d %h %y %T GMT'`);

# nuke headers (if they exist)
s/^Control: .*\n([ \t].*\n)*//i;
s/^Distribution: .*\n([ \t].*\n)*//i;
s/^X-Auth.*: PGPMoose.*\n([ \t].*\n)*//i;

# replace headers (no big deal if Lines and/or Approved absent)
s/^Date: .*\n([ \t].*\n)*/Date: $date\n/i;
s/^Path: .*\n([ \t].*\n)*/Path: bounce-back\n/i;
s/^Lines: .*\n([ \t].*\n)*/Lines: 1\n/i;
s/^Approved: .*\n([ \t].*\n)*/Approved: $user\n/i;

# cancel
s/^Message-ID: <(.*)$/Message-ID: <c$$-$1/i;
$msgid=$1;
s/^/Control: cancel <$msgid\n/i;
s/^Subject: .*\n([ \t].*\n)*/Subject: cmsg cancel <$msgid\n/i;

# open(RNEWS, '| rnews');
print;
print "Article cancelled by PGP Moose Daemon $user.\n";
close;
