#!/bin/sh
# -*- perl -*-
# This code allows us to start perl from our path or an environment variable
# rather than hardcoding a path into the #! line.  It works from sh or csh.
(exit $?0) && eval 'exec ${QPERLQ-perl} -x $0 ${1+"$@"}'
if (! $?QPERLQ) setenv QPERLQ perl
exec $QPERLQ -x $0 $argv:q

#!/usr/local/bin/perl -w
#
# $Id: join_rmail,v 1.1 1998/11/06 05:11:55 ejb Exp $
# $Source: /home/ejb/scripts/RCS/join_rmail,v $
# $Author: ejb $
#
# In a directory containing mail files generated from rmail files by 
# split_rmail, archive everything older than the current month.
#

require 5.002;
use strict;

my $whoami = ($0 =~ m,([^/\\]*)$,) ? $1 : $0;
#my $dirname = ($0 =~ m,(.*)[/\\][^/\\]+$,) ? $1 : ".";

my $rmail_header = "BABYL OPTIONS: -*- rmail -*-
Version: 5
Labels:
Note:   This is the header of an rmail file.
Note:   If you are seeing it in rmail,
Note:    it means the file has no messages in it.
";

my $after = "\037";
my $before = "\014\n";

undef $/;

my $outfile = shift(@ARGV);
die "$whoami: outfile exists\n" if -f $outfile;
my @files = @ARGV;
open(RMAIL, ">$outfile") or
    die "$whoami: can't create $outfile: $!\n";
print RMAIL $rmail_header, $after;
for (@files)
{
    open(F, "<$_") or die "$whoami: failed to open $_: $!\n";
    print RMAIL $before, scalar(<F>), $after or
	die "$whoami: append to $outfile failed: $!\n";
}
close(RMAIL) or die "$whoami: close of $outfile failed: $!\n";
