2 * Aggregate remote POP3 accounts
10 # include <sys/time.h>
14 # include <sys/time.h>
25 #include "citserver.h"
30 #include "ctdl_module.h"
33 struct pop3aggr *next;
34 char roomname[ROOMNAMELEN];
40 struct pop3aggr *palist = NULL;
42 #ifdef POP3_AGGREGATION
45 void pop3_do_fetching(char *roomname, char *pop3host, char *pop3user, char *pop3pass)
47 lprintf(CTDL_DEBUG, "POP3: %s %s %s %s\n", roomname, pop3host, pop3user, pop3pass);
52 * Scan a room's netconfig to determine whether it requires POP3 aggregation
54 void pop3client_scan_room(struct ctdlroom *qrbuf, void *data)
56 char filename[PATH_MAX];
60 struct pop3aggr *pptr;
62 assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
64 /* Only do net processing for rooms that have netconfigs */
65 fp = fopen(filename, "r");
70 while (fgets(buf, sizeof buf, fp) != NULL) {
71 buf[strlen(buf)-1] = 0;
73 extract_token(instr, buf, 0, '|', sizeof instr);
74 if (!strcasecmp(instr, "pop3client")) {
75 pptr = (struct pop3aggr *) malloc(sizeof(struct pop3aggr));
77 extract_token(pptr->roomname, buf, 1, '|', sizeof pptr->roomname);
78 extract_token(pptr->pop3host, buf, 2, '|', sizeof pptr->pop3host);
79 extract_token(pptr->pop3user, buf, 3, '|', sizeof pptr->pop3user);
80 extract_token(pptr->pop3pass, buf, 4, '|', sizeof pptr->pop3pass);
93 void pop3client_scan(void) {
94 static time_t last_run = 0L;
95 static int doing_pop3client = 0;
96 struct pop3aggr *pptr;
99 * Run POP3 aggregation no more frequently than once every n seconds
101 if ( (time(NULL) - last_run) < config.c_net_freq ) {
106 * This is a simple concurrency check to make sure only one pop3client run
107 * is done at a time. We could do this with a mutex, but since we
108 * don't really require extremely fine granularity here, we'll do it
109 * with a static variable instead.
111 if (doing_pop3client) return;
112 doing_pop3client = 1;
114 lprintf(CTDL_DEBUG, "pop3client started\n");
115 ForEachRoom(pop3client_scan_room, NULL);
117 while (palist != NULL) {
118 pop3_do_fetching(palist->roomname, palist->pop3host, palist->pop3user, palist->pop3pass);
120 palist = palist->next;
124 lprintf(CTDL_DEBUG, "pop3client ended\n");
125 doing_pop3client = 0;
130 CTDL_MODULE_INIT(pop3client)
132 #ifdef POP3_AGGREGATION
133 CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER);
136 /* return our Subversion id for the Log */