Created
June 6, 2018 13:25
-
-
Save schmonz/b04a16cb1355b0c594c12987d2ff255f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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