+datatype listing =
+ Error of string
+ | Listing of string list
+
+fun list domain =
+ let
+ val inf = TextIO.openIn (OS.Path.joinDirFile {dir = Config.Courier.userdbDir,
+ file = domain})
+
+ fun loop users =
+ case TextIO.inputLine inf of
+ NONE => Listing (rev users)
+ | SOME line =>
+ case String.tokens Char.isSpace line of
+ [addr, _] =>
+ (case String.fields (fn ch => ch = #"@") addr of
+ [user, _] => loop (user :: users)
+ | _ => Error "Invalid e-mail address format in database")
+ | _ => Error "Invalid entry in database"
+ in
+ loop []
+ before TextIO.closeIn inf
+ end
+ handle IO.Io _ => Listing []
+