2 * Automatically copies the contents of a "New User Greetings" room to the
3 * inbox of any new user upon account creation.
5 * Copyright (c) 1987-2022 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 * Name of the New User Greetings room.
19 #define NEWUSERGREETINGS "New User Greetings"
21 #include "../../sysdep.h"
29 #include <sys/types.h>
34 #include "../../ctdl_module.h"
35 #include "../../citadel.h"
36 #include "../../server.h"
37 #include "../../citserver.h"
38 #include "../../support.h"
39 #include "../../config.h"
40 #include "../../user_ops.h"
41 #include "../../database.h"
42 #include "../../msgbase.h"
45 * Copy the contents of the New User Greetings> room to the user's Mail> room.
47 void CopyNewUserGreetings(void) {
48 struct cdbdata *cdbfr;
51 char mailboxname[ROOMNAMELEN];
54 /* Only do this for new users. */
55 if (CC->user.timescalled != 1) return;
57 /* This user's mailbox. */
58 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
60 /* Go to the source room ... bail out silently if it's not there,
61 * or if it's not private.
63 if (CtdlGetRoom(&CC->room, NEWUSERGREETINGS) != 0) return;
64 if ((CC->room.QRflags & QR_PRIVATE) == 0) return;
66 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
69 msglist = malloc(cdbfr->len);
70 memcpy(msglist, cdbfr->ptr, cdbfr->len);
71 num_msgs = cdbfr->len / sizeof(long);
76 CtdlSaveMsgPointersInRoom(mailboxname, msglist, num_msgs, 1, NULL, 0);
79 /* Now free the memory we used, and go away. */
80 if (msglist != NULL) free(msglist);
84 // Initialization function, called from modules_init.c
85 char *ctdl_module_init_newuser(void) {
87 CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN, PRIO_LOGIN + 1);
90 /* return our module name for the log */