Handle hostnames with upper-case letters
[webmin.git] / dovecot / save_mail.cgi
1 #!/usr/local/bin/perl
2 # Update mail file options
3
4 require './dovecot-lib.pl';
5 &ReadParse();
6 &error_setup($text{'mail_err'});
7 $conf = &get_config();
8 &lock_dovecot_files($conf);
9
10 # Mail file location
11 if ($in{'envmode'} == 4) {
12         $in{'other'} =~ /^\S+$/ || &error($text{'mail_eenv'});
13         $env = $in{'other'};
14         }
15 else {
16         $env = $mail_envs[$in{'envmode'}];
17         }
18
19 # Add index file location
20 $env || !$in{'indexmode'} || &error($text{'mail_eindexmode'});
21 $env || !$in{'controlmode'} || &error($text{'mail_econtrolmode'});
22 if ($in{'indexmode'} == 1) {
23         $env .= ":INDEX=MEMORY";
24         }
25 elsif ($in{'indexmode'} == 2) {
26         $in{'index'} =~ /^\/\S+$/ || &error($text{'mail_eindex'});
27         $env .= ":INDEX=".$in{'index'};
28         }
29 if ($in{'controlmode'}) {
30         $in{'control'} =~ /^\/\S+$/ || &error($text{'mail_econtrol'});
31         $env .= ":CONTROL=".$in{'control'};
32         }
33
34 if (&find("mail_location", $conf, 2)) {
35         &save_directive($conf, "mail_location", $env eq "" ? undef : $env);
36         }
37 else {
38         &save_directive($conf, "default_mail_env", $env eq "" ? undef : $env);
39         }
40
41 # Check and idle intervals
42 $in{'check'} != 2 || $in{'checki'} =~ /^\d+$/ || &error($text{'mail_echeck'});
43 &save_directive($conf, "mailbox_check_interval",
44         $in{'check'} == 1 ? 0 : $in{'check'} == 2 ? $in{'checki'} : undef);
45 $in{'idle'} != 2 || $in{'idlei'} =~ /^\d+$/ || &error($text{'mail_eidle'});
46 &save_directive($conf, "mailbox_idle_check_interval",
47         $in{'idle'} == 1 ? 0 : $in{'idle'} == 2 ? $in{'idlei'} : undef);
48
49 # Yes/no options
50 &save_directive($conf, "mail_full_filesystem_access",
51                 $in{'full'} ? $in{'full'} : undef);
52 &save_directive($conf, "mail_save_crlf",
53                 $in{'crlf'} ? $in{'crlf'} : undef);
54 if (&find("mbox_dirty_syncs", $conf, 2)) {
55         &save_directive($conf, "mbox_dirty_syncs",
56                         $in{'change'} ? $in{'change'} : undef);
57         }
58 else {
59         &save_directive($conf, "maildir_check_content_changes",
60                         $in{'change'} ? $in{'change'} : undef);
61         }
62
63 # Umask
64 $in{'umask_def'} || $in{'umask'} =~ /^[0-7]{4}$/ ||&error($text{'mail_eumask'});
65 &save_directive($conf, "umask",
66                 $in{'umask_def'} ? undef : $in{'umask'});
67
68 # UIDL format
69 if (&find("pop3_uidl_format", $conf, 2)) {
70         $uidl = $in{'pop3_uidl_format'} eq '*' ?
71                         $in{'pop3_uidl_format_other'} : $in{'pop3_uidl_format'};
72         $uidl =~ /^\S+$/ || &error($text{'mail_euidl'});
73         &save_directive($conf, "pop3_uidl_format", $uidl);
74         }
75
76 # LAST command
77 &save_directive($conf, "pop3_enable_last",
78                 $in{'last'} ? $in{'last'} : undef);
79
80 # Index lock method
81 if (&find("lock_method", $conf, 2)) {
82         &save_directive($conf, "lock_method",
83                         $in{'lock_method'} ? $in{'lock_method'} : undef);
84         }
85
86 # Mailbox lock method
87 foreach $l ("mbox_read_locks", "mbox_write_locks") {
88         next if (!&find($l, $conf, 2));
89         if ($in{$l."_def"}) {
90                 &save_directive($conf, $l, undef);
91                 }
92         else {
93                 @methods = ( );
94                 for(my $i=0; defined($m = $in{$l."_".$i}); $i++) {
95                         push(@methods, $m) if ($m);
96                         }
97                 @methods || &error($text{'mail_e'.$l});
98                 &save_directive($conf, $l, join(" ", @methods));
99                 }
100         }
101
102 &flush_file_lines();
103 &unlock_dovecot_files($conf);
104 &webmin_log("mail");
105 &redirect("");
106