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