#!/usr/bin/perl

$old_line = "";

while(<STDIN>){
  chop();
  if(/^From/){
    s/From: //;
      $hostname = $_;
      $hostname =~ s/.+\@(.+)/$1/;
      # convert hostname to ip
      #print "FROM ./getip.pl $hostname\n";
      $result = `./getip.pl $hostname`;
      chop($result);
      #print "$result\n";
      $_ = $result;
    if($old_line ne ""){
      chop($old_line);
      print "$old_line\n";
      $old_line = "";
    }
  }
  if(s/To: //) { 
    $hostname = $_;
    $hostname =~ s/.+\@(.+)/$1/;
    # convert hostname to ip
    #print "TO ./getip.pl $hostname\n";
    $result = `./getip.pl $hostname`;
    chop($result);
    #print "$result\n";
    $_ = $result;
  }
  $old_line .= "$_ ";
}

chop($old_line);
print "$old_line\n";
