2 Domtool (http
://hcoop
.sf
.net
/)
3 Copyright (C
) 2004 Adam Chlipala
5 This program is free software
; you can redistribute it
and/or
6 modify it under the terms
of the GNU General Public License
7 as published by the Free Software Foundation
; either version
2
8 of the License
, or (at your option
) any later version
.
10 This program is distributed
in the hope that it will be useful
,
11 but WITHOUT ANY WARRANTY
; without even the implied warranty
of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
13 GNU General Public License for more details
.
15 You should have received a copy
of the GNU General Public License
16 along
with this program
; if not
, write to the Free Software
17 Foundation
, Inc
., 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA
.
20 (* Administration
of Courier IMAP virtual mailboxes
*)
22 structure Vmail
:> VMAIL
=
24 open Config VmailConfig Util
29 if validDomain domain
then
31 val tooldir
= dataDir ^ toDir domain
32 val maildir
= mailboxDir ^
"/" ^ domain
34 if not (Posix
.FileSys
.access (tooldir
, [])) then
35 (print ("Domain not in domtool (would be " ^ tooldir ^
")\n");
37 else if not (Posix
.FileSys
.access (tooldir
, [Posix
.FileSys
.A_WRITE
])) then
38 (print
"Access denied\n";
44 val dir
= Posix
.FileSys
.opendir maildir
47 case Posix
.FileSys
.readdir dir
of
49 | SOME user
=> (print (user ^
"\n");
53 Posix
.FileSys
.closedir dir
;
55 end handle Io
=> OS
.Process
.success
)
57 if validUser user
then
59 val _
= if Posix
.FileSys
.access (maildir
, []) then
62 ignore (OS
.Process
.system ("mkdir " ^ maildir
))
64 val umaildir
= maildir ^
"/" ^ user
66 if Posix
.FileSys
.access (umaildir
, []) then
67 (print
"Mailbox already exists\n";
69 else if OS
.Process
.system (courierDir ^
"/bin/maildirmake " ^ umaildir
) = OS
.Process
.success
70 andalso OS
.Process
.system (sudo ^
" " ^ courierDir ^
"/sbin/userdb \"" ^ domain ^
"/" ^ user ^
"@" ^ domain ^
"\" set home=/home/vmail mail=/home/vmail/" ^ domain ^
"/" ^ user ^
" uid=1042 gid=1043") = OS
.Process
.success
71 andalso OS
.Process
.system (sudo ^
" " ^ courierDir ^
"/sbin/userdbpw | " ^ sudo ^
" " ^ courierDir ^
"/sbin/userdb \"" ^ domain ^
"/" ^ user ^
"@" ^ domain ^
"\" set systempw") = OS
.Process
.success
then
72 (print
"Mailbox created\n";
75 (print
"Error creating mailbox\n";
79 (print
"Invalid mailbox name\n";
82 if not (validUser user
) then
83 (print
"Invalid mailbox name\n";
85 else if not (Posix
.FileSys
.access (maildir ^
"/" ^ user
, [])) then
86 (print
"Mailbox does not exist\n";
88 else if OS
.Process
.system (sudo ^
" " ^ courierDir ^
"/sbin/userdbpw | " ^ sudo ^
" " ^ courierDir ^
"/sbin/userdb \"" ^ domain ^
"/" ^ user ^
"@" ^ domain ^
"\" set systempw") = OS
.Process
.success
then
89 (print
"Password set\n";
92 (print
"Unable to set password\n";
94 | _
=> (print
"Unknown command\n";
98 (print
"Invalid domain\n";
100 | _
=> (print
"Invalid command\n";