| 1 |
pippijn |
1.7 |
/** |
| 2 |
|
|
* listmail.C: This file contains code for the NickServ LISTMAIL function. |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.4 |
* Copyright © 2005 William Pitcock, et al. |
| 10 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.8 |
* $Id: listmail.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#include "atheme.h" |
| 16 |
pippijn |
1.4 |
#include <ermyth/module.h> |
| 17 |
pippijn |
1.1 |
#include <account/myuser.h> |
| 18 |
|
|
|
| 19 |
pippijn |
1.8 |
static char const rcsid[] = "$Id: listmail.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $"; |
| 20 |
pippijn |
1.1 |
|
| 21 |
pippijn |
1.8 |
REGISTER_MODULE ("nickserv/listmail", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 22 |
pippijn |
1.1 |
|
| 23 |
|
|
static void ns_cmd_listmail (sourceinfo_t *si, int parc, char *parv[]); |
| 24 |
|
|
|
| 25 |
pippijn |
1.4 |
command_t const ns_listmail = { "LISTMAIL", N_("Lists nicknames registered to an e-mail address."), PRIV_USER_AUSPEX, 1, ns_cmd_listmail }; |
| 26 |
pippijn |
1.1 |
|
| 27 |
pippijn |
1.4 |
E cmdvec ns_cmdtree; |
| 28 |
|
|
E helpvec ns_helptree; |
| 29 |
pippijn |
1.1 |
|
| 30 |
pippijn |
1.4 |
bool |
| 31 |
|
|
_modinit (module *m) |
| 32 |
pippijn |
1.1 |
{ |
| 33 |
|
|
ns_cmdtree << ns_listmail; |
| 34 |
|
|
help_addentry (ns_helptree, "LISTMAIL", "help/nickserv/listmail", NULL); |
| 35 |
pippijn |
1.4 |
|
| 36 |
|
|
return true; |
| 37 |
pippijn |
1.1 |
} |
| 38 |
|
|
|
| 39 |
|
|
void |
| 40 |
|
|
_moddeinit () |
| 41 |
|
|
{ |
| 42 |
|
|
ns_cmdtree >> ns_listmail; |
| 43 |
|
|
help_delentry (ns_helptree, "LISTMAIL"); |
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
struct listmail_state |
| 47 |
|
|
{ |
| 48 |
|
|
sourceinfo_t *origin; |
| 49 |
|
|
char *pattern; |
| 50 |
|
|
int matches; |
| 51 |
|
|
}; |
| 52 |
|
|
|
| 53 |
pippijn |
1.4 |
struct listmail_foreach_cb |
| 54 |
pippijn |
1.1 |
{ |
| 55 |
pippijn |
1.4 |
listmail_foreach_cb (listmail_state &s) |
| 56 |
|
|
: state (s) |
| 57 |
|
|
{ |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
pippijn |
1.6 |
void operator () (myuser_t::pair_type &it) |
| 61 |
pippijn |
1.4 |
{ |
| 62 |
|
|
myuser_t *mu = it.second; |
| 63 |
|
|
|
| 64 |
|
|
if (!match (state.pattern, mu->email)) |
| 65 |
|
|
{ |
| 66 |
|
|
/* in the future we could add a LIMIT parameter */ |
| 67 |
|
|
if (state.matches == 0) |
| 68 |
|
|
command_success_nodata (state.origin, "Nicknames matching e-mail address \2%s\2:", state.pattern); |
| 69 |
|
|
|
| 70 |
|
|
command_success_nodata (state.origin, "- %s (%s)", mu->name, mu->email); |
| 71 |
|
|
state.matches++; |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
pippijn |
1.1 |
|
| 75 |
pippijn |
1.4 |
private: |
| 76 |
|
|
listmail_state &state; |
| 77 |
|
|
}; |
| 78 |
pippijn |
1.1 |
|
| 79 |
|
|
static void |
| 80 |
|
|
ns_cmd_listmail (sourceinfo_t *si, int parc, char *parv[]) |
| 81 |
|
|
{ |
| 82 |
|
|
char *email = parv[0]; |
| 83 |
pippijn |
1.4 |
listmail_state state; |
| 84 |
|
|
|
| 85 |
pippijn |
1.1 |
if (!email) |
| 86 |
|
|
{ |
| 87 |
pippijn |
1.5 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "LISTMAIL"); |
| 88 |
|
|
command_fail (si, fault::needmoreparams, _("Syntax: LISTMAIL <email>")); |
| 89 |
pippijn |
1.1 |
return; |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
snoop ("LISTMAIL: \2%s\2 by \2%s\2", email, get_oper_name (si)); |
| 93 |
|
|
|
| 94 |
|
|
state.matches = 0; |
| 95 |
|
|
state.pattern = email; |
| 96 |
|
|
state.origin = si; |
| 97 |
pippijn |
1.6 |
std::for_each (myuser_t::map.begin (), myuser_t::map.end (), listmail_foreach_cb (state)); |
| 98 |
pippijn |
1.1 |
|
| 99 |
|
|
logcommand (si, CMDLOG_ADMIN, "LISTMAIL %s (%d matches)", email, state.matches); |
| 100 |
|
|
if (state.matches == 0) |
| 101 |
|
|
command_success_nodata (si, _("No nicknames matched e-mail address \2%s\2"), email); |
| 102 |
|
|
else |
| 103 |
|
|
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); |
| 104 |
|
|
} |