]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/pop3client/serv_pop3client.c
Revoke refetching of already polled pop3 messages
[citadel.git] / citadel / modules / pop3client / serv_pop3client.c
index 8bbb74bfc007551fa1ca8573c66dfcac226ed759..199f051ee452f507f08ac563ddcf48dcd0471971 100644 (file)
@@ -1,21 +1,21 @@
 /*
  * Consolidate mail from remote POP3 accounts.
  *
- * Copyright (c) 2007-2009 by the citadel.org team
+ * Copyright (c) 2007-2011 by the citadel.org team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 3 of the License, or
- *  (at your option) any later version.
+ * This program is open source software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 #include <stdlib.h>
@@ -55,7 +55,7 @@
 
 struct CitContext pop3_client_CC;
 
-citthread_mutex_t POP3QueueMutex; /* locks the access to the following vars: */
+pthread_mutex_t POP3QueueMutex; /* locks the access to the following vars: */
 HashList *POP3QueueRooms = NULL; /* rss_room_counter */
 HashList *POP3FetchUrls = NULL; /* -> rss_aggregator; ->RefCount access to be locked too. */
 
@@ -159,12 +159,12 @@ eNextState FinalizePOP3AggrRun(AsyncIO *IO)
        syslog(LOG_DEBUG, "Terminating Aggregator; bye.\n");
 
        It = GetNewHashPos(POP3FetchUrls, 0);
-       citthread_mutex_lock(&POP3QueueMutex);
+       pthread_mutex_lock(&POP3QueueMutex);
        {
                GetHashPosFromKey(POP3FetchUrls, SKEY(cptr->Url), It);
                DeleteEntryFromHash(POP3FetchUrls, It);
        }
-       citthread_mutex_unlock(&POP3QueueMutex);
+       pthread_mutex_unlock(&POP3QueueMutex);
        DeleteHashPos(&It);
        return eAbort;
 }
@@ -174,6 +174,7 @@ eNextState FailAggregationRun(AsyncIO *IO)
        return eAbort;
 }
 
+
 #define POP3C_DBG_SEND() syslog(LOG_DEBUG, "POP3 client[%ld]: > %s\n", RecvMsg->n, ChrPtr(RecvMsg->IO.SendBuf.Buf))
 #define POP3C_DBG_READ() syslog(LOG_DEBUG, "POP3 client[%ld]: < %s\n", RecvMsg->n, ChrPtr(RecvMsg->IO.IOBuf))
 #define POP3C_OK (strncasecmp(ChrPtr(RecvMsg->IO.IOBuf), "+OK", 3) == 0)
@@ -186,7 +187,6 @@ eNextState POP3C_ReadGreeting(pop3aggr *RecvMsg)
        else return eSendReply;
 }
 
-
 eNextState POP3C_SendUser(pop3aggr *RecvMsg)
 {
        /* Identify ourselves.  NOTE: we have to append a CR to each command.  The LF will
@@ -301,7 +301,9 @@ eNextState POP3_FetchNetworkUsetableEntry(AsyncIO *IO)
        if(GetNextHashPos(RecvMsg->MsgNumbers, RecvMsg->Pos, &HKLen, &HKey, &vData))
        {
                struct UseTable ut;
-
+               if (server_shutting_down)
+                       return eAbort;
+                       
                RecvMsg->CurrMsg = (FetchItem*) vData;
                syslog(LOG_DEBUG, "CHECKING: whether %s has already been seen: ", ChrPtr(RecvMsg->CurrMsg->MsgUID));
                /* Find out if we've already seen this item */
@@ -320,7 +322,7 @@ eNextState POP3_FetchNetworkUsetableEntry(AsyncIO *IO)
                        cdb_store(CDB_USETABLE, 
                                  SKEY(RecvMsg->CurrMsg->MsgUID), 
                                  &ut, sizeof(struct UseTable) );
-                       RecvMsg->CurrMsg->NeedFetch = 1; ////TODO0;
+                       RecvMsg->CurrMsg->NeedFetch = 0; ////TODO0;
                }
                else
                {
@@ -882,21 +884,22 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data)
 //     pop3_room_counter *Count = NULL;
 //     pop3aggr *cpptr;
 
-       citthread_mutex_lock(&POP3QueueMutex);
+       pthread_mutex_lock(&POP3QueueMutex);
        if (GetHash(POP3QueueRooms, LKEY(qrbuf->QRnumber), &vptr))
        {
                syslog(LOG_DEBUG, 
                              "pop3client: [%ld] %s already in progress.\n", 
                              qrbuf->QRnumber, 
                              qrbuf->QRname);
-               citthread_mutex_unlock(&POP3QueueMutex);
-               return;
+               pthread_mutex_unlock(&POP3QueueMutex);
        }
-       citthread_mutex_unlock(&POP3QueueMutex);
+       pthread_mutex_unlock(&POP3QueueMutex);
+
+       if (server_shutting_down) return;
 
        assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
 
-       if (CtdlThreadCheckStop())
+       if (server_shutting_down)
                return;
                
        /* Only do net processing for rooms that have netconfigs */
@@ -905,14 +908,14 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data)
                //syslog(LOG_DEBUG, "rssclient: %s no config.\n", qrbuf->QRname);
                return;
        }
-       if (CtdlThreadCheckStop())
+       if (server_shutting_down)
                return;
        if (fstat(fd, &statbuf) == -1) {
                syslog(LOG_DEBUG, "ERROR: could not stat configfile '%s' - %s\n",
                              filename, strerror(errno));
                return;
        }
-       if (CtdlThreadCheckStop())
+       if (server_shutting_down)
                return;
        CfgData = NewStrBufPlain(NULL, statbuf.st_size + 1);
        if (StrBufReadBLOB(CfgData, &fd, 1, statbuf.st_size, &Err) < 0) {
@@ -923,7 +926,7 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data)
                return;
        }
        close(fd);
-       if (CtdlThreadCheckStop())
+       if (server_shutting_down)
                return;
        
        CfgPtr = NULL;
@@ -977,7 +980,7 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data)
 #if 0 
 /* todo: we need to reunite the url to be shure. */
                                
-                               citthread_mutex_lock(&POP3ueueMutex);
+                               pthread_mutex_lock(&POP3ueueMutex);
                                GetHash(POP3FetchUrls, SKEY(ptr->Url), &vptr);
                                use_this_cptr = (pop3aggr *)vptr;
                                
@@ -1004,15 +1007,15 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data)
                                                Put(use_this_cptr->OtherQRnumbers, LKEY(qrbuf->QRnumber), QRnumber, NULL);
                                                use_this_cptr->roomlist_parts++;
                                        }
-                                       citthread_mutex_unlock(&POP3QueueMutex);
+                                       pthread_mutex_unlock(&POP3QueueMutex);
                                        continue;
                                }
-                               citthread_mutex_unlock(&RSSQueueMutex);
+                               pthread_mutex_unlock(&RSSQueueMutex);
 #endif
 
-                               citthread_mutex_lock(&POP3QueueMutex);
+                               pthread_mutex_lock(&POP3QueueMutex);
                                Put(POP3FetchUrls, SKEY(cptr->Url), cptr, DeletePOP3Aggregator);
-                               citthread_mutex_unlock(&POP3QueueMutex);
+                               pthread_mutex_unlock(&POP3QueueMutex);
 
                        }
 
@@ -1059,23 +1062,33 @@ void pop3client_scan(void) {
        if (doing_pop3client) return;
        doing_pop3client = 1;
 
-       syslog(LOG_DEBUG, "pop3client started\n");
+       syslog(LOG_DEBUG, "pop3client started");
        CtdlForEachRoom(pop3client_scan_room, NULL);
 
-
-       citthread_mutex_lock(&POP3QueueMutex);
+       pthread_mutex_lock(&POP3QueueMutex);
        it = GetNewHashPos(POP3FetchUrls, 0);
-       while (GetNextHashPos(POP3FetchUrls, it, &len, &Key, &vrptr) && 
+       while (!server_shutting_down && 
+              GetNextHashPos(POP3FetchUrls, it, &len, &Key, &vrptr) && 
               (vrptr != NULL)) {
                cptr = (pop3aggr *)vrptr;
                if (cptr->RefCount == 0) 
                        if (!pop3_do_fetching(cptr))
                                DeletePOP3Aggregator(cptr);////TODO
+
+/*
+               if ((palist->interval && time(NULL) > (last_run + palist->interval))
+                       || (time(NULL) > last_run + config.c_pop3_fetch))
+                               pop3_do_fetching(palist->roomname, palist->pop3host,
+                                       palist->pop3user, palist->pop3pass, palist->keep);
+               pptr = palist;
+               palist = palist->next;
+               free(pptr);
+*/
        }
        DeleteHashPos(&it);
-       citthread_mutex_unlock(&POP3QueueMutex);
+       pthread_mutex_unlock(&POP3QueueMutex);
 
-       syslog(LOG_DEBUG, "pop3client ended\n");
+       syslog(LOG_DEBUG, "pop3client ended");
        last_run = time(NULL);
        doing_pop3client = 0;
 }
@@ -1083,8 +1096,8 @@ void pop3client_scan(void) {
 
 void pop3_cleanup(void)
 {
-       citthread_mutex_destroy(&POP3QueueMutex);
-       DeleteHash(&POP3FetchUrls);
+       /* citthread_mutex_destroy(&POP3QueueMutex); TODO */
+//     DeleteHash(&POP3FetchUrls);
        DeleteHash(&POP3QueueRooms);
 }
 
@@ -1093,12 +1106,13 @@ CTDL_MODULE_INIT(pop3client)
        if (!threading)
        {
                CtdlFillSystemContext(&pop3_client_CC, "POP3aggr");
-               citthread_mutex_init(&POP3QueueMutex, NULL);
+               pthread_mutex_init(&POP3QueueMutex, NULL);
                POP3QueueRooms = NewHash(1, lFlathash);
                POP3FetchUrls = NewHash(1, NULL);
                CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER);
                 CtdlRegisterCleanupHook(pop3_cleanup);
        }
-       /* return our Subversion id for the Log */
+
+       /* return our module id for the log */
         return "pop3client";
 }