Back to index

citadel  8.12
serv_newuser.c
Go to the documentation of this file.
00001 /*
00002  * Automatically copies the contents of a "New User Greetings" room to the
00003  * inbox of any new user upon account creation.
00004  *
00005  * Copyright (c) 1987-2012 by the citadel.org team
00006  *
00007  * This program is open source software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 3.
00009  * 
00010  * 
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * 
00018  * 
00019  * 
00020  */
00021 
00022 /*
00023  * Name of the New User Greetings room.
00024  */
00025 #define NEWUSERGREETINGS    "New User Greetings"
00026 
00027 
00028 #include "sysdep.h"
00029 #include <stdlib.h>
00030 #include <unistd.h>
00031 #include <stdio.h>
00032 #include <fcntl.h>
00033 #include <signal.h>
00034 #include <pwd.h>
00035 #include <errno.h>
00036 #include <sys/types.h>
00037 
00038 #if TIME_WITH_SYS_TIME
00039 # include <sys/time.h>
00040 # include <time.h>
00041 #else
00042 # if HAVE_SYS_TIME_H
00043 #  include <sys/time.h>
00044 # else
00045 #  include <time.h>
00046 # endif
00047 #endif
00048 
00049 #include <sys/wait.h>
00050 #include <string.h>
00051 #include <limits.h>
00052 
00053 #include "ctdl_module.h"
00054 
00055 #include "citadel.h"
00056 #include "server.h"
00057 #include "citserver.h"
00058 #include "support.h"
00059 #include "config.h"
00060 #include "user_ops.h"
00061 #include "database.h"
00062 #include "msgbase.h"
00063 
00064 
00065 
00066 
00067 
00068 
00069 /*
00070  * Copy the contents of the New User Greetings> room to the user's Mail> room.
00071  */
00072 void CopyNewUserGreetings(void) {
00073        struct cdbdata *cdbfr;
00074        long *msglist = NULL;
00075        int num_msgs = 0;
00076        char mailboxname[ROOMNAMELEN];
00077 
00078 
00079        /* Only do this for new users. */
00080        if (CC->user.timescalled != 1) return;
00081 
00082        /* This user's mailbox. */
00083        CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
00084 
00085        /* Go to the source room ... bail out silently if it's not there,
00086         * or if it's not private.
00087         */
00088        if (CtdlGetRoom(&CC->room, NEWUSERGREETINGS) != 0) return;
00089        if ((CC->room.QRflags & QR_PRIVATE) == 0) return;
00090 
00091        cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
00092 
00093        if (cdbfr != NULL) {
00094               msglist = malloc(cdbfr->len);
00095               memcpy(msglist, cdbfr->ptr, cdbfr->len);
00096               num_msgs = cdbfr->len / sizeof(long);
00097               cdb_free(cdbfr);
00098        }
00099 
00100        if (num_msgs > 0) {
00101               CtdlSaveMsgPointersInRoom(mailboxname, msglist, num_msgs, 1, NULL, 0);
00102        }
00103 
00104        /* Now free the memory we used, and go away. */
00105        if (msglist != NULL) free(msglist);
00106 }
00107 
00108 
00109 CTDL_MODULE_INIT(newuser)
00110 {
00111        if (!threading)
00112        {
00113               CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN, PRIO_LOGIN + 1);
00114        }
00115        
00116        /* return our module name for the log */
00117        return "newuser";
00118 }