-
Notifications
You must be signed in to change notification settings - Fork 4
/
fixreply
executable file
·89 lines (76 loc) · 2.18 KB
/
fixreply
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env perl
#
# fixreply
#
# Rewrite a mail message's Reply-To header to the mailing list address so that
# using the mail client Reply command sends a reply to the list by default.
#
# The headers that override Reply-To, in order of preference, are:
# Mail-Followup-To <http://cr.yp.to/proto/replyto.html>
# List-Post <http://www.ietf.org/rfc/rfc2369.txt>
#
# Michael Wardle <[email protected]>
# $Id$
use Mail::Internet;
# whether to print informational messages
$verbose = 1;
# fields to replace and which fields to replace them with
$replacements{"Reply-To"} = [ "Mail-Followup-To", "List-Post" ];
# read the original message
$original = new Mail::Internet(\*STDIN);
$header = $original->head();
$body = $original->body();
# log the message id
if ($verbose)
{
$value = $header->get("Message-Id");
if (defined($value))
{
chomp($value);
}
print STDERR "Message-Id: " . $value . "\n";
}
# attempt to perform replacements for every key in replacements
for $key (keys(%replacements))
{
$old = $header->get($key);
if (defined($old))
{
chomp($old);
}
# find the first preferred replacement header
$new = undef;
for $replacement (@{$replacements{$key}})
{
if ($header->count($replacement))
{
# retrieve the replacement value
$new = $header->get($replacement);
if (defined($new))
{
chomp($new);
}
# List-Post uses a URI rather than a mail address
if ($new =~ /<mailto:(.*?)>/)
{
$new =~ s/<mailto:(.*?)>/<$1>/;
}
# print the old and new values
if ($verbose)
{
print STDERR "Old $key: " . $old . "\n";
print STDERR "New $key: " . $new . "\n";
}
last;
}
}
# set the new header if a better one was found
if ($new)
{
$header->replace("X-Original-" . $key, "X-Original-" . $key . ": " . $old);
}
}
# print the new (possibly modified) message
$modified = new Mail::Internet(undef, Header=>$header, Body=>$body);
$modified->print(\*STDOUT);
# vi: set sw=4 ts=33: