Stripping and replacing email headers
Thursday, June 22nd, 2006The Perl CPAN module Mail::MboxParser does a great job at stripping and replacing email headers.
Say you have your email message (with headers) in a string variable $msg_str. Now check this
use Mail::MboxParser;
my $mail = Mail::MboxParser::Mail->new($msg_str);
my $mail_new = $mail->make_convertable();
$mail_new->delete_from_header(’received’);
$mail_new->replace_in_header(’to’, ‘new_to@domain.com’);
$mail_new->replace_in_header(’from’, ‘new_from@domain.com’);
$mail_new->send(’sendmail’);
The above code strips all the Received headers and replaces the To and From headers. It even […]
