Citadel API clean up.
[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 "user_ops.h"
60 #include "policy.h"
61 #include "database.h"
62 #include "msgbase.h"
63
64
65 #include "ctdl_module.h"
66
67
68
69 extern struct CitContext *ContextList;
70
71
72 /*
73  * Copy the contents of the New User Greetings> room to the user's Mail> room.
74  */
75 void CopyNewUserGreetings(void) {
76         struct cdbdata *cdbfr;
77         long *msglist = NULL;
78         int num_msgs = 0;
79         char mailboxname[ROOMNAMELEN];
80
81
82         /* Only do this for new users. */
83         if (CC->user.timescalled != 1) return;
84
85         /* This user's mailbox. */
86         MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
87
88         /* Go to the source room ... bail out silently if it's not there,
89          * or if it's not private.
90          */
91         if (CtdlGetRoom(&CC->room, NEWUSERGREETINGS) != 0) return;
92         if (! CC->room.QRflags & QR_PRIVATE ) return;
93
94         cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
95
96         if (cdbfr != NULL) {
97                 msglist = malloc(cdbfr->len);
98                 memcpy(msglist, cdbfr->ptr, cdbfr->len);
99                 num_msgs = cdbfr->len / sizeof(long);
100                 cdb_free(cdbfr);
101         }
102
103         if (num_msgs > 0) {
104                 CtdlSaveMsgPointersInRoom(mailboxname, msglist, num_msgs, 1, NULL);
105         }
106
107         /* Now free the memory we used, and go away. */
108         if (msglist != NULL) free(msglist);
109 }
110
111
112 CTDL_MODULE_INIT(newuser)
113 {
114         if (!threading)
115         {
116                 CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN);
117         }
118         
119         /* return our Subversion id for the Log */
120         return "$Id$";
121 }