]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/pop3client/serv_pop3client.c
More logging for rssclient and pop3client holdoff and concurrency checks
[citadel.git] / citadel / modules / pop3client / serv_pop3client.c
index 0a97df2cc971b402c431c4b6daf5a54dbe9ae3c6..e559f2824a5025212cddafd917c83db18598993f 100644 (file)
@@ -1,21 +1,15 @@
 /*
  * Consolidate mail from remote POP3 accounts.
  *
- * Copyright (c) 2007-2011 by the citadel.org team
+ * Copyright (c) 2007-2012 by the citadel.org team
  *
  * 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.
+ * modify it under the terms of the GNU General Public License version 3.
  *
  * 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
  */
 
 #include <stdlib.h>
@@ -52,7 +46,6 @@
 #include "citadel_dirs.h"
 #include "event_client.h"
 
-
 #define POP3C_OK (strncasecmp(ChrPtr(RecvMsg->IO.IOBuf), "+OK", 3) == 0)
 
 #define POP3C_DBG_SEND()                                       \
@@ -66,7 +59,6 @@
               RecvMsg->n,                              \
               ChrPtr(RecvMsg->IO.IOBuf))
 
-
 struct CitContext pop3_client_CC;
 
 pthread_mutex_t POP3QueueMutex; /* locks the access to the following vars: */
@@ -224,7 +216,7 @@ eNextState POP3C_SendPassword(pop3aggr *RecvMsg)
        StrBufPrintf(RecvMsg->IO.SendBuf.Buf,
                     "PASS %s\r\n", ChrPtr(RecvMsg->pop3pass));
        syslog(LOG_DEBUG, "<PASS <password>\n");
-//     POP3C_DBG_SEND(); No, we won't write the passvoid to syslog...
+//     POP3C_DBG_SEND(); No, we won't write the password to syslog...
        return eReadMessage;
 }
 
@@ -706,6 +698,14 @@ eNextState POP3_C_Terminate(AsyncIO *IO)
        FinalizePOP3AggrRun(IO);
        return eAbort;
 }
+eNextState POP3_C_TerminateDB(AsyncIO *IO)
+{
+///    pop3aggr *pMsg = (pop3aggr *)IO->Data;
+
+       syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__);
+       FinalizePOP3AggrRun(IO);
+       return eAbort;
+}
 eNextState POP3_C_Timeout(AsyncIO *IO)
 {
        pop3aggr *pMsg = IO->Data;
@@ -742,9 +742,9 @@ eNextState POP3_C_Shutdown(AsyncIO *IO)
 }
 
 
-/**
- * @brief lineread Handler; understands when to read more POP3 lines,
- *   and when this is a one-lined reply.
+/*
+ * lineread Handler; understands when to read more POP3 lines,
+ * and when this is a one-lined reply.
  */
 eReadState POP3_C_ReadServerStatus(AsyncIO *IO)
 {
@@ -776,7 +776,8 @@ eReadState POP3_C_ReadServerStatus(AsyncIO *IO)
 
 /*****************************************************************************
  * So we connect our Server IP here.                                         *
- *****************************************************************************/
+ *****************************************************************************
+ */
 eNextState POP3_C_ReAttachToFetchMessages(AsyncIO *IO)
 {
        pop3aggr *cpptr = IO->Data;
@@ -844,14 +845,6 @@ eNextState pop3_get_one_host_ip_done(AsyncIO *IO)
 eNextState pop3_get_one_host_ip(AsyncIO *IO)
 {
        pop3aggr *cpptr = IO->Data;
-       /*
-        * here we start with the lookup of one host. it might be...
-        * - the relay host *sigh*
-        * - the direct hostname if there was no mx record
-        * - one of the mx'es
-        */
-
-       InitC_ares_dns(IO);
 
        syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__);
 
@@ -883,6 +876,7 @@ int pop3_do_fetching(pop3aggr *cpptr)
                     POP3_C_DispatchWriteDone,
                     POP3_C_DispatchReadDone,
                     POP3_C_Terminate,
+                    POP3_C_TerminateDB,
                     POP3_C_ConnFail,
                     POP3_C_Timeout,
                     POP3_C_Shutdown);
@@ -1116,6 +1110,11 @@ void pop3client_scan(void) {
         * Run POP3 aggregation no more frequently than once every n seconds
         */
        if ( (time(NULL) - last_run) < fastest_scan ) {
+               syslog(LOG_DEBUG,
+                       "pop3client: polling interval not yet reached; last run was %ldm%lds ago",
+                       ((time(NULL) - last_run) / 60),
+                       ((time(NULL) - last_run) % 60)
+               );
                return;
        }
 
@@ -1125,7 +1124,10 @@ void pop3client_scan(void) {
         * don't really require extremely fine granularity here, we'll do it
         * with a static variable instead.
         */
-       if (doing_pop3client) return;
+       if (doing_pop3client) {
+               syslog(LOG_DEBUG, "pop3client: concurrency check failed; another poll is already running");
+               return;
+       }
        doing_pop3client = 1;
 
        syslog(LOG_DEBUG, "pop3client started");