import "services/ad" as ad; fn search_and_print(directory) { let user = ctx::mail_from().local_part; let address = ctx::mail_from().to_string(); let search = directory.search( "dc=example,dc=org", // Search the whole tree. "sub", // Match on the user id and address. `(|(uid=${user})(mail=${address}))`, // Get all attributes from the entries. [] ); if search.result == "error" || search.entries.is_empty() { log("warn", `User could not be found in database: ${search.error}`); return state::deny(); } log("info", `Entry for ${user} found in AD.`); for entry in search.entries { log("info", `dn=${entry.dn}`); log("info", `dn=${entry.attrs}`); for attr in entry.attrs.keys() { for value in entry.attrs.get(attr) { log("info", ` attr=${attr},value=${value}`); } } } state::next() } #{ mail: [ rule "search user" || search_and_print(ad::directory), // TODO: test tls using the following rule. // rule "search user tls" || search_and_print(ad::directory_tls), ], delivery: [ // Do not try to deliver the message. rule "setup delivery" || state::quarantine("hold") ] }