ffde5e3b2f742f5f1c12b887c5539f664e5fa03d
[citadel.git] / citadel / 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 "sysdep_decls.h"
42 #include "citserver.h"
43 #include "support.h"
44 #include "config.h"
45 #include "serv_extensions.h"
46 #include "room_ops.h"
47 #include "user_ops.h"
48 #include "policy.h"
49 #include "database.h"
50 #include "msgbase.h"
51
52 extern struct CitContext *ContextList;
53
54
55 /*
56  * Copy the contents of the New User Greetings> room to the user's Mail> room.
57  */
58 void CopyNewUserGreetings(void) {
59         struct cdbdata *cdbfr;
60         long *msglist = NULL;
61         int num_msgs = 0;
62         char mailboxname[ROOMNAMELEN];
63
64
65         /* Only do this for new users. */
66         if (CC->user.timescalled != 1) return;
67
68         /* This user's mailbox. */
69         MailboxName(mailboxname, sizeof mailboxname, &CC->user, 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->room, NEWUSERGREETINGS) != 0) return;
75         if (! CC->room.QRflags & QR_PRIVATE ) return;
76
77         cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
78
79         if (cdbfr != NULL) {
80                 msglist = malloc(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                 CtdlCopyMsgsToRoom(msglist, num_msgs, mailboxname);
88         }
89
90         /* Now free the memory we used, and go away. */
91         if (msglist != NULL) free(msglist);
92 }
93
94
95 char *serv_newuser_init(void)
96 {
97    CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN);
98
99    /* return our Subversion id for the Log */
100    return "$Id$";
101 }