Handle hostnames with upper-case letters
[webmin.git] / filter / autoreply-file-lib.pl
1 # Functions for reading and writing autoreply files
2
3 # read_autoreply(file, &simple)
4 # Fills in the autoreply parts of a simple alias structure from a file
5 sub read_autoreply
6 {
7 local ($file, $simple) = @_;
8 local @lines;
9 open(FILE, $file);
10 while(<FILE>) {
11         if (/^Reply-Tracking:\s*(.*)/) {
12                 $simple->{'replies'} = $1;
13                 }
14         elsif (/^Reply-Period:\s*(.*)/) {
15                 $simple->{'period'} = $1;
16                 }
17         elsif (/^No-Autoreply:\s*(.*)/) {
18                 $simple->{'no_autoreply'} = $1;
19                 }
20         elsif (/^No-Autoreply-Regexp:\s*(.*)/) {
21                 push(@{$simple->{'no_autoreply_regexp'}}, $1);
22                 }
23         elsif (/^Autoreply-File:\s*(.*)/) {
24                 push(@{$simple->{'autoreply_file'}}, $1);
25                 }
26         elsif (/^Autoreply-Start:\s*(\d+)/) {
27                 $simple->{'autoreply_start'} = $1;
28                 }
29         elsif (/^Autoreply-End:\s*(\d+)/) {
30                 $simple->{'autoreply_end'} = $1;
31                 }
32         elsif (/^From:\s*(.*)/) {
33                 $simple->{'from'} = $1;
34                 }
35         elsif (/^Charset:\s*(\S+)/) {
36                 $simple->{'charset'} = $1;
37                 }
38         else {
39                 push(@lines, $_);
40                 }
41         }
42 close(FILE);
43 $simple->{'autotext'} = join("", @lines);
44 }
45
46 # write_autoreply(&file, &simple)
47 # Writes the autoreply parts of a simple alias structure to a file
48 sub write_autoreply
49 {
50 local ($file, $simple) = @_;
51 &open_tempfile(AUTO, ">$file");
52 if ($simple->{'replies'}) {
53         &print_tempfile(AUTO,
54                 "Reply-Tracking: $simple->{'replies'}\n");
55         }
56 if ($simple->{'period'}) {
57         &print_tempfile(AUTO,
58                 "Reply-Period: $simple->{'period'}\n");
59         }
60 if ($simple->{'no_autoreply'}) {
61         &print_tempfile(AUTO,
62                 "No-Autoreply: $simple->{'no_autoreply'}\n");
63         }
64 foreach my $r (@{$simple->{'no_autoreply_regexp'}}) {
65         &print_tempfile(AUTO, "No-Autoreply-Regexp: $r\n");
66         }
67 foreach my $f (@{$simple->{'autoreply_file'}}) {
68         &print_tempfile(AUTO, "Autoreply-File: $f\n");
69         }
70 if ($simple->{'autoreply_start'}) {
71         &print_tempfile(AUTO,
72                 "Autoreply-Start: $simple->{'autoreply_start'}\n");
73         }
74 if ($simple->{'autoreply_end'}) {
75         &print_tempfile(AUTO,
76                 "Autoreply-End: $simple->{'autoreply_end'}\n");
77         }
78 if ($simple->{'from'}) {
79         &print_tempfile(AUTO, "From: $simple->{'from'}\n");
80         }
81 if ($simple->{'charset'}) {
82         &print_tempfile(AUTO, "Charset: $simple->{'charset'}\n");
83         }
84 &print_tempfile(AUTO, $simple->{'autotext'});
85 &close_tempfile(AUTO);
86 }
87
88 1;
89