Skip to content

Instantly share code, notes, and snippets.

@schmonz
Created June 6, 2018 13:25
Show Gist options
  • Save schmonz/b04a16cb1355b0c594c12987d2ff255f to your computer and use it in GitHub Desktop.
Save schmonz/b04a16cb1355b0c594c12987d2ff255f to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# in .qmail:
# | rewriteto something@somewhere.else | forward something@somewhere.else
use warnings;
use strict;
sub munge_to_header {
my ($new_to) = @_;
my $read_all_headers = 0;
while (my $line = <STDIN>) {
$read_all_headers++ if $line =~ /^$/;
if (defined $new_to && ! $read_all_headers) {
print STDERR "rewriteto: replaced '$2' with '$new_to'\n"
if $line =~ s/^([Tt]o:\s+)(.+)$/$1$new_to/;
}
print $line;
}
}
sub main { my @args = @_;
munge_to_header($args[0]);
}
exit(main(@ARGV));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment