#!/usr/bin/perl
#
# Set the From: line in an LK git commit email to the author's address
#
# Copyright 2005 James Cloos <cloos@jhcloos.com>
#
# This Perl  is free software; you can redistribute it
# and/or modify it under the same terms as Perl itself.
#

$from = '';
@msg = ();

while(<STDIN>) {
    push @msg, $_;
    next if length($from);
    next unless /^author/;
    s/^author ([^@]+[^ ]+)/$from=$1/e;
}

unless (length($from)) {
    print @msg;
    exit;
}

$done = 0;

foreach $l (@msg) {
    if (($done == 0) && ($l =~ /^From:/)) {
	$l = "From:\t" . $from . "\n";
	$done = 1;
    }
    print $l;
}
