Workaround pop3 servers sending empty lines in message lists
[citadel.git] / citadel / modules / pop3client / serv_pop3client.c
index 25c835c7561022bd276c5e8093b879101a1ce8d6..81feca096c9410fc52ac54865480b007e765a2cd 100644 (file)
@@ -199,8 +199,10 @@ void DeletePOP3Aggregator(void *vptr)
        FreeStrBuf(&ptr->IO.SendBuf.Buf);
        FreeStrBuf(&ptr->IO.RecvBuf.Buf);
        DeleteAsyncMsg(&ptr->IO.ReadMsg);
-       ((struct CitContext*)ptr->IO.CitContext)->state = CON_IDLE;
-       ((struct CitContext*)ptr->IO.CitContext)->kill_me = 1;
+       if (((struct CitContext*)ptr->IO.CitContext)) {
+               ((struct CitContext*)ptr->IO.CitContext)->state = CON_IDLE;
+               ((struct CitContext*)ptr->IO.CitContext)->kill_me = 1;
+       }
        FreeAsyncIOContents(&ptr->IO);
        free(ptr);
 }
@@ -330,6 +332,17 @@ eNextState POP3C_GetListOneLine(pop3aggr *RecvMsg)
                return eSendReply;
 
        }
+
+       /*
+        * work around buggy pop3 servers which send
+        * empty lines in their listings.
+       */
+       if ((StrLength(RecvMsg->IO.IOBuf) == 0) ||
+           !isdigit(ChrPtr(RecvMsg->IO.IOBuf)[0]))
+       {
+               return eReadMore;
+       }
+
        OneMsg = (FetchItem*) malloc(sizeof(FetchItem));
        memset(OneMsg, 0, sizeof(FetchItem));
        OneMsg->MSGID = atol(ChrPtr(RecvMsg->IO.IOBuf));
@@ -1081,6 +1094,7 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data, OneRoomNetCfg *One
                    DeletePOP3Aggregator);
 
                pthread_mutex_unlock(&POP3QueueMutex);
+               pLine = pLine->next;
 
        }
 }