* Eliminated the CtdlCopyMsgsToRoom() function, since it has been reduced to nothing...
[citadel.git] / citadel / modules / newuser / serv_newuser.c
1 /*
2  * $Id$
3  *
4  * Automaticalyl copies the contents of a "New User Greetings" room to the
5  * inbox of any new user upon account creation.
6  *
7  */
8
9 /*
10  * Name of the New User Greetings room.
11  */
12 #define NEWUSERGREETINGS        "New User Greetings"
13
14
15 #include "sysdep.h"
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <fcntl.h>
20 #include <signal.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <sys/types.h>
24
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
27 # include <time.h>
28 #else
29 # if HAVE_SYS_TIME_H
30 #  include <sys/time.h>
31 # else
32 #  include <time.h>
33 # endif
34 #endif
35
36 #include <sys/wait.h>
37 #include <string.h>
38 #include <limits.h>
39 #include "citadel.h"
40 #include "server.h"
41 #include "citserver.h"
42 #include "support.h"
43 #include "config.h"
44 #include "room_ops.h"
45 #include "user_ops.h"
46 #include "policy.h"
47 #include "database.h"
48 #include "msgbase.h"
49
50
51 #include "ctdl_module.h"
52
53
54
55 extern struct CitContext *ContextList;
56
57
58 /*
59  * Copy the contents of the New User Greetings> room to the user's Mail> room.
60  */
61 void CopyNewUserGreetings(void) {
62         struct cdbdata *cdbfr;
63         long *msglist = NULL;
64         int num_msgs = 0;
65         char mailboxname[ROOMNAMELEN];
66
67
68         /* Only do this for new users. */
69         if (CC->user.timescalled != 1) return;
70
71         /* This user's mailbox. */
72         MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
73
74         /* Go to the source room ... bail out silently if it's not there,
75          * or if it's not private.
76          */
77         if (getroom(&CC->room, NEWUSERGREETINGS) != 0) return;
78         if (! CC->room.QRflags & QR_PRIVATE ) return;
79
80         cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
81
82         if (cdbfr != NULL) {
83                 msglist = malloc(cdbfr->len);
84                 memcpy(msglist, cdbfr->ptr, cdbfr->len);
85                 num_msgs = cdbfr->len / sizeof(long);
86                 cdb_free(cdbfr);
87         }
88
89         if (num_msgs > 0) {
90                 CtdlSaveMsgPointersInRoom(mailboxname, msglist, num_msgs, 1, NULL);
91         }
92
93         /* Now free the memory we used, and go away. */
94         if (msglist != NULL) free(msglist);
95 }
96
97
98 CTDL_MODULE_INIT(newuser)
99 {
100         if (!threading)
101         {
102                 CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN);
103         }
104         
105         /* return our Subversion id for the Log */
106         return "$Id$";
107 }