Debian Codegraph @

modules/nickserv/listownmail.c

raw
1 /*
2 * Copyright (c) 2005-2008 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the NickServ LISTOWNMAIL function.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "nickserv/listownmail", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ns_cmd_listownmail(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t ns_listownmail = { "LISTOWNMAIL", N_("Lists accounts registered to your e-mail address."), AC_AUTHENTICATED, 1, ns_cmd_listownmail, { .path = "nickserv/listownmail" } };
21
22 void _modinit(module_t *m)
23 {
24 service_named_bind_command("nickserv", &ns_listownmail);
25 }
26
27 void _moddeinit(module_unload_intent_t intent)
28 {
29 service_named_unbind_command("nickserv", &ns_listownmail);
30 }
31
32 static void ns_cmd_listownmail(sourceinfo_t *si, int parc, char *parv[])
33 {
34 myentity_t *mt;
35 myentity_iteration_state_t state;
36 unsigned int matches = 0;
37
38 if (si->smu->flags & MU_WAITAUTH)
39 {
40 command_fail(si, fault_noprivs, _("You have to verify your email address before you can perform this operation."));
41 return;
42 }
43
44 /* Normally this couldn't fail due to the verification check above,
45 * except when accounts have been imported from another services
46 * database that didn't require them, in which case lots of unrelated
47 * accounts may have 'noemail' or similar.
48 */
49 if (!validemail(si->smu->email))
50 {
51 command_fail(si, fault_noprivs, _("You must have a valid email address to perform this operation."));
52 return;
53 }
54
55 command_add_flood(si, FLOOD_HEAVY);
56
57 MYENTITY_FOREACH_T(mt, &state, ENT_USER)
58 {
59 myuser_t *mu = user(mt);
60
61 continue_if_fail(mu != NULL);
62
63 if (!strcasecmp(si->smu->email, mu->email))
64 {
65 /* in the future we could add a LIMIT parameter */
66 if (matches == 0)
67 command_success_nodata(si, "Accounts matching e-mail address \2%s\2:", si->smu->email);
68
69 command_success_nodata(si, "- %s (%s)", entity(mu)->name, mu->email);
70 matches++;
71 }
72 }
73
74 logcommand(si, CMDLOG_GET, "LISTOWNMAIL: \2%s\2 (\2%d\2 matches)", si->smu->email, matches);
75 command_success_nodata(si, ngettext(N_("\2%d\2 match for e-mail address \2%s\2"),
76 N_("\2%d\2 matches for e-mail address \2%s\2"), matches), matches, si->smu->email);
77 }
78
79 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
80 * vim:ts=8
81 * vim:sw=8
82 * vim:noexpandtab
83 */