#!/usr/bin/perl
#
# Author: Peter Keel <killer@discordia.ch>
# Version: 1.0
# 
# This script tries to convert "The Bat!" .tbb-mailfiles into normal,
# good, plain, unix mbox-files. 
# 
# License: GPL, Artistic, take your pick. 
#
# Bugs: 
#	All it can have. 
# 
# 	Lazily, it produces a line-feed too much at the beginning of 
#	the file. 
# 
# 	Also, it may happen that still some garbage is left. YMMV
#
# 	The Envelope-From-Date is hardcoded. ;) Ouch!
# 
# 	And finally, all mail sent from you will be incomplete, 
#	since that bugger "The Bat!" saves it like that. Did I  
#	mention "The Bat!" sucks?
# 

die "Usage: $0 filename\n"       unless($ARGV[0]);

foreach $file_name (@ARGV) {
    $temp_file="/tmp/$file_name";
    open(IN_FILE,"<$file_name") || die "Cannot open $file_name for input\n";
    open(TEMP,">$temp_file");
    while(<IN_FILE>){
        $_ =~ s/.*\000\000\000Return\-Path/Return\-Path/g;
	$_ =~ s/.*\041\011\160\031\060\000\000\000.*//g;
	$_ =~ s/\r\n$/\n/g;
	$_ =~ s/\017$//g;
	if(/Return\-Path\:\ .*/) { 
	/\<(.*)\>/;
	print TEMP "\nFrom $1  Fri Jan 11 11:11:11 2002\n";
	print TEMP "$_";
	} else { 
        print TEMP ($_);
	}
    }
    close IN;
    close TEMP;
    system ("mv $temp_file $file_name.mbox");
}
