| 1 |
/* |
| 2 |
* Copyright (c) 2005 William Pitcock, et al. |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains code for the NickServ LISTMAIL function. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
|
| 11 |
DECLARE_MODULE_V1 |
| 12 |
( |
| 13 |
"nickserv/listmail", false, _modinit, _moddeinit, |
| 14 |
PACKAGE_STRING, |
| 15 |
VENDOR_STRING |
| 16 |
); |
| 17 |
|
| 18 |
static void ns_cmd_listmail(sourceinfo_t *si, int parc, char *parv[]); |
| 19 |
|
| 20 |
command_t ns_listmail = { "LISTMAIL", N_("Lists accounts registered to an e-mail address."), PRIV_USER_AUSPEX, 1, ns_cmd_listmail, { .path = "nickserv/listmail" } }; |
| 21 |
|
| 22 |
void _modinit(module_t *m) |
| 23 |
{ |
| 24 |
service_named_bind_command("nickserv", &ns_listmail); |
| 25 |
} |
| 26 |
|
| 27 |
void _moddeinit(module_unload_intent_t intent) |
| 28 |
{ |
| 29 |
service_named_unbind_command("nickserv", &ns_listmail); |
| 30 |
} |
| 31 |
|
| 32 |
struct listmail_state |
| 33 |
{ |
| 34 |
sourceinfo_t *origin; |
| 35 |
char *pattern; |
| 36 |
stringref email_canonical; |
| 37 |
int matches; |
| 38 |
}; |
| 39 |
|
| 40 |
static int listmail_foreach_cb(myentity_t *mt, void *privdata) |
| 41 |
{ |
| 42 |
struct listmail_state *state = (struct listmail_state *) privdata; |
| 43 |
myuser_t *mu = user(mt); |
| 44 |
|
| 45 |
if (state->email_canonical == mu->email_canonical || !match(state->pattern, mu->email)) |
| 46 |
{ |
| 47 |
/* in the future we could add a LIMIT parameter */ |
| 48 |
if (state->matches == 0) |
| 49 |
command_success_nodata(state->origin, "Accounts matching e-mail address \2%s\2:", state->pattern); |
| 50 |
|
| 51 |
command_success_nodata(state->origin, "- %s (%s)", entity(mu)->name, mu->email); |
| 52 |
state->matches++; |
| 53 |
} |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
static void ns_cmd_listmail(sourceinfo_t *si, int parc, char *parv[]) |
| 59 |
{ |
| 60 |
char *email = parv[0]; |
| 61 |
struct listmail_state state; |
| 62 |
|
| 63 |
if (!email) |
| 64 |
{ |
| 65 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "LISTMAIL"); |
| 66 |
command_fail(si, fault_needmoreparams, _("Syntax: LISTMAIL <email>")); |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
state.matches = 0; |
| 71 |
state.pattern = email; |
| 72 |
state.email_canonical = canonicalize_email(email); |
| 73 |
state.origin = si; |
| 74 |
myentity_foreach_t(ENT_USER, listmail_foreach_cb, &state); |
| 75 |
strshare_unref(state.email_canonical); |
| 76 |
|
| 77 |
logcommand(si, CMDLOG_ADMIN, "LISTMAIL: \2%s\2 (\2%d\2 matches)", email, state.matches); |
| 78 |
if (state.matches == 0) |
| 79 |
command_success_nodata(si, _("No accounts matched e-mail address \2%s\2"), email); |
| 80 |
else |
| 81 |
command_success_nodata(si, ngettext(N_("\2%d\2 match for e-mail address \2%s\2"), |
| 82 |
N_("\2%d\2 matches for e-mail address \2%s\2"), state.matches), state.matches, email); |
| 83 |
} |
| 84 |
|
| 85 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 86 |
* vim:ts=8 |
| 87 |
* vim:sw=8 |
| 88 |
* vim:noexpandtab |
| 89 |
*/ |