Handle hostnames with upper-case letters
[webmin.git] / status / mailserver.pl
1 #!/usr/local/bin/perl
2 # mailserver.pl
3 # Called from a sendmail alias when an autoresponse arrives, as sent by the 
4 # mailserver monitor
5
6 $no_acl_check++;
7 require './status-lib.pl';
8
9 # read headers and body
10 while(<STDIN>) {
11         s/\r|\n//g;
12         if (/^(\S+):\s+(.*)/) {
13                 $header{lc($1)} = $2;
14                 }
15         elsif (!$_) { last; }
16         }
17 while(<STDIN>) {
18         $body .= $_;
19         }
20
21 if ($header{'subject'} =~ /TEST-(\S+)-(\S+)/) {
22         # Looks like a valid reply
23         local ($sserv, $sid) = ( $1, $2 );
24         $replies_file = "$module_config_directory/mailserver-replies";
25         &read_file($replies_file, \%replies);
26         local ($when, $got, $id) = split(/\s+/, $replies{$sserv});
27         if ($id eq $sid) {
28                 # Got a reply to an outstanding email
29                 local $now = time();
30                 $replies{$sserv} = "$when $now $id";
31                 }
32         else {
33                 # Reply is to an email that is way out of date!
34                 }
35         $replies_file =~ /^(.*)$/;
36         &write_file("$1", \%replies);
37         exit(0);
38         }
39 else {
40         # Unknown email!
41         print STDERR "Only Mailserver Response auto-reply messages should be sent to this address\n";
42         exit(1);
43         }
44