#!/usr/bin/perl -w
use strict;

##############################################################################
# - each arg is a qmail-send logfile
# - output is written to oldname.log
# - all usernames + passwords will be scrambled
#
# ctime:   2004-06-13
# mtime:   2004-06-13
# version: 0.1 / rel 02
##############################################################################

foreach my $logfile (@ARGV) {
	open(LOG, $logfile);
	open(OUT, ">$logfile.log");
	while (<LOG>) {
		chomp;

		# 1. replace $USER from <user@host>
		if (/<.+@.+>/) {
			my $user;
			my $host;

			s/<.+@.+>/%MAIL%/g; # spaceholder
			($user,$host) = split(/@/, $&);
			$user =~ s/[=\w+]/x/g;
			s/%MAIL%/$user\@$host/g; # replace spaceholder
		}

		my $line=$_;

		# 2.1 replace "to local user@host" to "to local xxxx@host"
		if (/to local /) {
			my $x1;
			my $x2;
			my $x3;

			($x1,$x2) = split(/to local /);
			($x2,$x3) = split(/@/, $x2);
			$x2 =~ s/[=\w+]/x/g;
			$line = $x1 . "to remote " . $x2 . "@" . $x3;
		}

		# 2.2 replace "to remote user@host" to "to remote xxxx@host"
		if (/to remote /) {
			my $x1;
			my $x2;
			my $x3;

			($x1,$x2) = split(/to remote /);
			($x2,$x3) = split(/@/, $x2);
			$x2 =~ s/[=\w+]/x/g;
			$line = $x1 . "to remote " . $x2 . "@" . $x3;
		}

		print OUT "$line\n";

	}
	close (LOG);
	close (OUT);
}
