/** * listmail.C: This file contains code for the NickServ LISTMAIL function. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: listmail.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include static char const rcsid[] = "$Id: listmail.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("nickserv/listmail", false, "The Ermyth Team "); static void ns_cmd_listmail (sourceinfo_t *si, int parc, char *parv[]); command_t const ns_listmail = { "LISTMAIL", N_("Lists nicknames registered to an e-mail address."), PRIV_USER_AUSPEX, 1, ns_cmd_listmail }; E cmdvec ns_cmdtree; E helpvec ns_helptree; bool _modinit (module *m) { ns_cmdtree << ns_listmail; help_addentry (ns_helptree, "LISTMAIL", "help/nickserv/listmail", NULL); return true; } void _moddeinit () { ns_cmdtree >> ns_listmail; help_delentry (ns_helptree, "LISTMAIL"); } struct listmail_state { sourceinfo_t *origin; char *pattern; int matches; }; struct listmail_foreach_cb { listmail_foreach_cb (listmail_state &s) : state (s) { } void operator () (myuser_t::pair_type &it) { myuser_t *mu = it.second; if (!match (state.pattern, mu->email)) { /* in the future we could add a LIMIT parameter */ if (state.matches == 0) command_success_nodata (state.origin, "Nicknames matching e-mail address \2%s\2:", state.pattern); command_success_nodata (state.origin, "- %s (%s)", mu->name, mu->email); state.matches++; } } private: listmail_state &state; }; static void ns_cmd_listmail (sourceinfo_t *si, int parc, char *parv[]) { char *email = parv[0]; listmail_state state; if (!email) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "LISTMAIL"); command_fail (si, fault::needmoreparams, _("Syntax: LISTMAIL ")); return; } snoop ("LISTMAIL: \2%s\2 by \2%s\2", email, get_oper_name (si)); state.matches = 0; state.pattern = email; state.origin = si; std::for_each (myuser_t::map.begin (), myuser_t::map.end (), listmail_foreach_cb (state)); logcommand (si, CMDLOG_ADMIN, "LISTMAIL %s (%d matches)", email, state.matches); if (state.matches == 0) command_success_nodata (si, _("No nicknames matched e-mail address \2%s\2"), email); else command_success_nodata (si, ngettext (N_("\2%d\2 match for e-mail address \2%s\2"), N_("\2%d\2 matches for e-mail address \2%s\2"), state.matches), state.matches, email); }