Debian Codegraph @

modules/groupserv/set_email.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * This file contains routines to handle the GroupServ HELP command.
6 *
7 */
8
9 #include "atheme.h"
10 #include "groupserv.h"
11
12 DECLARE_MODULE_V1
13 (
14 "groupserv/set_email", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void gs_cmd_set_email(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t gs_set_email = { "EMAIL", N_("Sets the group e-mail address."), AC_AUTHENTICATED, 2, gs_cmd_set_email, { .path = "groupserv/set_email" } };
22
23 static void gs_cmd_set_email(sourceinfo_t *si, int parc, char *parv[])
24 {
25 mygroup_t *mg;
26 char *mail = parv[1];
27
28 if (!(mg = mygroup_find(parv[0])))
29 {
30 command_fail(si, fault_nosuch_target, _("Group \2%s\2 does not exist."), parv[0]);
31 return;
32 }
33
34 if (!groupacs_sourceinfo_has_flag(mg, si, GA_SET))
35 {
36 command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
37 return;
38 }
39
40 if (!mail || !strcasecmp(mail, "NONE") || !strcasecmp(mail, "OFF"))
41 {
42 if (metadata_find(mg, "email"))
43 {
44 metadata_delete(mg, "email");
45 command_success_nodata(si, _("The e-mail address for group \2%s\2 was deleted."), entity(mg)->name);
46 logcommand(si, CMDLOG_SET, "SET:EMAIL:NONE: \2%s\2", entity(mg)->name);
47 return;
48 }
49
50 command_fail(si, fault_nochange, _("The e-mail address for group \2%s\2 was not set."), entity(mg)->name);
51 return;
52 }
53
54 if (!validemail(mail))
55 {
56 command_fail(si, fault_badparams, _("\2%s\2 is not a valid e-mail address."), mail);
57 return;
58 }
59
60 /* we'll overwrite any existing metadata */
61 metadata_add(mg, "email", mail);
62
63 logcommand(si, CMDLOG_SET, "SET:EMAIL: \2%s\2 \2%s\2", entity(mg)->name, mail);
64 command_success_nodata(si, _("The e-mail address for group \2%s\2 has been set to \2%s\2."), parv[0], mail);
65 }
66
67 void _modinit(module_t *m)
68 {
69 use_groupserv_main_symbols(m);
70 use_groupserv_set_symbols(m);
71
72 command_add(&gs_set_email, gs_set_cmdtree);
73 }
74
75 void _moddeinit(module_unload_intent_t intent)
76 {
77 command_delete(&gs_set_email, gs_set_cmdtree);
78 }
79