* More license declarations
[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  * Copyright (c) 1987-2009 by the citadel.org team
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 3 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 /*
25  * Name of the New User Greetings room.
26  */
27 #define NEWUSERGREETINGS        "New User Greetings"
28
29
30 #include "sysdep.h"
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <stdio.h>
34 #include <fcntl.h>
35 #include <signal.h>
36 #include <pwd.h>
37 #include <errno.h>
38 #include <sys/types.h>
39
40 #if TIME_WITH_SYS_TIME
41 # include <sys/time.h>
42 # include <time.h>
43 #else
44 # if HAVE_SYS_TIME_H
45 #  include <sys/time.h>
46 # else
47 #  include <time.h>
48 # endif
49 #endif
50
51 #include <sys/wait.h>
52 #include <string.h>
53 #include <limits.h>
54 #include "citadel.h"
55 #include "server.h"
56 #include "citserver.h"
57 #include "support.h"
58 #include "config.h"
59 #include "room_ops.h"
60 #include "user_ops.h"
61 #include "policy.h"
62 #include "database.h"
63 #include "msgbase.h"
64
65
66 #include "ctdl_module.h"
67
68
69
70 extern struct CitContext *ContextList;
71
72
73 /*
74  * Copy the contents of the New User Greetings> room to the user's Mail> room.
75  */
76 void CopyNewUserGreetings(void) {
77         struct cdbdata *cdbfr;
78         long *msglist = NULL;
79         int num_msgs = 0;
80         char mailboxname[ROOMNAMELEN];
81
82
83         /* Only do this for new users. */
84         if (CC->user.timescalled != 1) return;
85
86         /* This user's mailbox. */
87         MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
88
89         /* Go to the source room ... bail out silently if it's not there,
90          * or if it's not private.
91          */
92         if (getroom(&CC->room, NEWUSERGREETINGS) != 0) return;
93         if (! CC->room.QRflags & QR_PRIVATE ) return;
94
95         cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
96
97         if (cdbfr != NULL) {
98                 msglist = malloc(cdbfr->len);
99                 memcpy(msglist, cdbfr->ptr, cdbfr->len);
100                 num_msgs = cdbfr->len / sizeof(long);
101                 cdb_free(cdbfr);
102         }
103
104         if (num_msgs > 0) {
105                 CtdlSaveMsgPointersInRoom(mailboxname, msglist, num_msgs, 1, NULL);
106         }
107
108         /* Now free the memory we used, and go away. */
109         if (msglist != NULL) free(msglist);
110 }
111
112
113 CTDL_MODULE_INIT(newuser)
114 {
115         if (!threading)
116         {
117                 CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN);
118         }
119         
120         /* return our Subversion id for the Log */
121         return "$Id$";
122 }