POP3 client is now in development, add -DPOP3_AGGREGATION to enable
[citadel.git] / citadel / modules / pop3client / serv_pop3client.c
1 /*
2  * Aggregate remote POP3 accounts
3  */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8
9 #if TIME_WITH_SYS_TIME
10 # include <sys/time.h>
11 # include <time.h>
12 #else
13 # if HAVE_SYS_TIME_H
14 #  include <sys/time.h>
15 # else
16 #  include <time.h>
17 # endif
18 #endif
19
20 #include <ctype.h>
21 #include <string.h>
22 #include <errno.h>
23 #include "citadel.h"
24 #include "server.h"
25 #include "citserver.h"
26 #include "support.h"
27 #include "config.h"
28 #include "tools.h"
29 #include "room_ops.h"
30
31
32 #include "ctdl_module.h"
33
34
35 #ifdef POP3_AGGREGATION
36
37 void pop3client_do_room(struct ctdlroom *qrbuf, void *data)
38 {
39
40         lprintf(CTDL_DEBUG, "POP3 aggregation for <%s>\n", qrbuf->QRname);
41
42 }
43
44
45 void pop3client_scan(void) {
46         static time_t last_run = 0L;
47         static int doing_pop3client = 0;
48
49         /*
50          * Run POP3 aggregation no more frequently than once every n seconds
51          */
52         if ( (time(NULL) - last_run) < config.c_net_freq ) {
53                 return;
54         }
55
56         /*
57          * This is a simple concurrency check to make sure only one pop3client run
58          * is done at a time.  We could do this with a mutex, but since we
59          * don't really require extremely fine granularity here, we'll do it
60          * with a static variable instead.
61          */
62         if (doing_pop3client) return;
63         doing_pop3client = 1;
64
65         lprintf(CTDL_DEBUG, "pop3client started\n");
66         ForEachRoom(pop3client_do_room, NULL);
67         lprintf(CTDL_DEBUG, "pop3client ended\n");
68
69         doing_pop3client = 0;
70 }
71
72 #endif
73
74 CTDL_MODULE_INIT(pop3client)
75 {
76 #ifdef POP3_AGGREGATION
77         CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER);
78 #endif
79
80         /* return our Subversion id for the Log */
81         return "$Id:  $";
82 }