Commit | Line | Data |
---|---|---|
182a2654 AC |
1 | (* |
2 | Domtool (http://hcoop.sf.net/) | |
3 | Copyright (C) 2004 Adam Chlipala | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | *) | |
19 | ||
20 | (* Utility to reload Courier IMAP data after modifying virtual mailboxes *) | |
21 | ||
22 | structure Reloadusers :> RELOADUSERS = | |
23 | struct | |
24 | open VmailConfig | |
25 | ||
26 | fun main _ = | |
27 | let | |
28 | val proc = Unix.execute("/bin/sh", ["-c", courierDir ^ "/sbin/pw2userdb"]) | |
29 | val (stdout, stdin) = Unix.streamsOf proc | |
30 | ||
31 | val outf = TextIO.openOut (userdbDir ^ "/localhost") | |
32 | ||
33 | fun loop () = | |
34 | case TextIO.inputLine stdout of | |
35 | "" => () | |
36 | | line => | |
37 | let | |
38 | val tokens = String.tokens (fn ch => Char.isSpace ch orelse ch = #"|" orelse ch = #"=") line | |
39 | ||
40 | fun findHome (n::v::rest) = | |
41 | if n = "home" then | |
42 | TextIO.output (outf, "|mail=" ^ v ^ "/Maildir") | |
43 | else | |
44 | findHome rest | |
45 | | findHome _ = () | |
46 | in | |
47 | TextIO.output (outf, String.substring (line, 0, size line - 1)); | |
48 | case tokens of | |
49 | first::rest => | |
50 | (case Int.fromString first of | |
51 | NONE => findHome rest | |
52 | | _ => ()) | |
53 | | _ => (); | |
54 | TextIO.output (outf, "\n"); | |
55 | loop () | |
56 | end | |
57 | in | |
58 | loop (); | |
59 | TextIO.closeOut outf; | |
60 | TextIO.closeIn stdout; | |
61 | TextIO.closeOut stdin; | |
62 | Unix.reap proc; | |
63 | if OS.Process.isSuccess (OS.Process.system (courierDir ^ "/sbin/makeuserdb")) then | |
64 | OS.Process.system postReload | |
65 | else | |
66 | (print "Error running makeuserdb\n"; | |
67 | OS.Process.failure) | |
68 | end | |
69 | end |