1 |
/** |
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 |
* Copyright © 2005 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: listmail.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
#include <account/myuser.h> |
18 |
|
19 |
static char const rcsid[] = "$Id: listmail.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $"; |
20 |
|
21 |
REGISTER_MODULE ("nickserv/listmail", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
22 |
|
23 |
static void ns_cmd_listmail (sourceinfo_t *si, int parc, char *parv[]); |
24 |
|
25 |
command_t const ns_listmail = { "LISTMAIL", N_("Lists nicknames registered to an e-mail address."), PRIV_USER_AUSPEX, 1, ns_cmd_listmail }; |
26 |
|
27 |
E cmdvec ns_cmdtree; |
28 |
E helpvec ns_helptree; |
29 |
|
30 |
bool |
31 |
_modinit (module *m) |
32 |
{ |
33 |
ns_cmdtree << ns_listmail; |
34 |
help_addentry (ns_helptree, "LISTMAIL", "help/nickserv/listmail", NULL); |
35 |
|
36 |
return true; |
37 |
} |
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 |
struct listmail_foreach_cb |
54 |
{ |
55 |
listmail_foreach_cb (listmail_state &s) |
56 |
: state (s) |
57 |
{ |
58 |
} |
59 |
|
60 |
void operator () (myuser_t::pair_type &it) |
61 |
{ |
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 |
|
75 |
private: |
76 |
listmail_state &state; |
77 |
}; |
78 |
|
79 |
static void |
80 |
ns_cmd_listmail (sourceinfo_t *si, int parc, char *parv[]) |
81 |
{ |
82 |
char *email = parv[0]; |
83 |
listmail_state state; |
84 |
|
85 |
if (!email) |
86 |
{ |
87 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "LISTMAIL"); |
88 |
command_fail (si, fault::needmoreparams, _("Syntax: LISTMAIL <email>")); |
89 |
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 |
std::for_each (myuser_t::map.begin (), myuser_t::map.end (), listmail_foreach_cb (state)); |
98 |
|
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 |
} |