Fix Crash
[citadel.git] / citadel / modules / smtp / serv_smtpeventclient.c
1 /*
2  * This module is an SMTP and ESMTP implementation for the Citadel system.
3  * It is compliant with all of the following:
4  *
5  * RFC  821 - Simple Mail Transfer Protocol
6  * RFC  876 - Survey of SMTP Implementations
7  * RFC 1047 - Duplicate messages and SMTP
8  * RFC 1652 - 8 bit MIME
9  * RFC 1869 - Extended Simple Mail Transfer Protocol
10  * RFC 1870 - SMTP Service Extension for Message Size Declaration
11  * RFC 2033 - Local Mail Transfer Protocol
12  * RFC 2197 - SMTP Service Extension for Command Pipelining
13  * RFC 2476 - Message Submission
14  * RFC 2487 - SMTP Service Extension for Secure SMTP over TLS
15  * RFC 2554 - SMTP Service Extension for Authentication
16  * RFC 2821 - Simple Mail Transfer Protocol
17  * RFC 2822 - Internet Message Format
18  * RFC 2920 - SMTP Service Extension for Command Pipelining
19  *  
20  * The VRFY and EXPN commands have been removed from this implementation
21  * because nobody uses these commands anymore, except for spammers.
22  *
23  * Copyright (c) 1998-2009 by the citadel.org team
24  *
25  *  This program is free software; you can redistribute it and/or modify
26  *  it under the terms of the GNU General Public License as published by
27  *  the Free Software Foundation; either version 3 of the License, or
28  *  (at your option) any later version.
29  *
30  *  This program is distributed in the hope that it will be useful,
31  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
32  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  *  GNU General Public License for more details.
34  *
35  *  You should have received a copy of the GNU General Public License
36  *  along with this program; if not, write to the Free Software
37  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38  */
39
40 #include "sysdep.h"
41 #include <stdlib.h>
42 #include <unistd.h>
43 #include <stdio.h>
44 #include <termios.h>
45 #include <fcntl.h>
46 #include <signal.h>
47 #include <pwd.h>
48 #include <errno.h>
49 #include <sys/types.h>
50 #include <syslog.h>
51
52 #if TIME_WITH_SYS_TIME
53 # include <sys/time.h>
54 # include <time.h>
55 #else
56 # if HAVE_SYS_TIME_H
57 #  include <sys/time.h>
58 # else
59 #  include <time.h>
60 # endif
61 #endif
62 #include <sys/wait.h>
63 #include <ctype.h>
64 #include <string.h>
65 #include <limits.h>
66 #include <sys/socket.h>
67 #include <netinet/in.h>
68 #include <arpa/inet.h>
69 #include <libcitadel.h>
70 #include "citadel.h"
71 #include "server.h"
72 #include "citserver.h"
73 #include "support.h"
74 #include "config.h"
75 #include "control.h"
76 #include "user_ops.h"
77 #include "database.h"
78 #include "msgbase.h"
79 #include "internet_addressing.h"
80 #include "genstamp.h"
81 #include "domain.h"
82 #include "clientsocket.h"
83 #include "locate_host.h"
84 #include "citadel_dirs.h"
85
86 #include "ctdl_module.h"
87
88 #include "smtp_util.h"
89 #include "event_client.h"
90 #include "smtpqueue.h"
91 #include "smtp_clienthandlers.h"
92
93 #ifdef EXPERIMENTAL_SMTP_EVENT_CLIENT
94 const unsigned short DefaultMXPort = 25;
95 void DeleteSmtpOutMsg(void *v)
96 {
97         SmtpOutMsg *Msg = v;
98
99         ares_free_data(Msg->AllMX);
100         if (Msg->HostLookup.VParsedDNSReply != NULL)
101                 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
102         FreeStrBuf(&Msg->msgtext);
103         FreeAsyncIOContents(&Msg->IO);
104         free(Msg);
105 }
106
107 eNextState SMTP_C_Shutdown(AsyncIO *IO);
108 eNextState SMTP_C_Timeout(AsyncIO *IO);
109 eNextState SMTP_C_ConnFail(AsyncIO *IO);
110 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO);
111 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO);
112 eNextState SMTP_C_Terminate(AsyncIO *IO);
113 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO);
114
115 eNextState mx_connect_ip(AsyncIO *IO);
116 eNextState get_one_mx_host_ip(AsyncIO *IO);
117
118 /******************************************************************************
119  * So, we're finished with sending (regardless of success or failure)         *
120  * This Message might be referenced by several Queue-Items, if we're the last,*
121  * we need to free the memory and send bounce messages (on terminal failure)  *
122  * else we just free our SMTP-Message struct.                                 *
123  ******************************************************************************/
124 void FinalizeMessageSend(SmtpOutMsg *Msg)
125 {
126         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
127         
128         if (DecreaseQReference(Msg->MyQItem)) 
129         {
130                 int nRemain;
131                 StrBuf *MsgData;
132
133                 nRemain = CountActiveQueueEntries(Msg->MyQItem);
134
135                 MsgData = SerializeQueueItem(Msg->MyQItem);
136                 /*
137                  * Uncompleted delivery instructions remain, so delete the old
138                  * instructions and replace with the updated ones.
139                  */
140                 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
141                 smtpq_do_bounce(Msg->MyQItem,
142                                 Msg->msgtext); 
143                 if (nRemain > 0) {
144                         struct CtdlMessage *msg;
145                         msg = malloc(sizeof(struct CtdlMessage));
146                         memset(msg, 0, sizeof(struct CtdlMessage));
147                         msg->cm_magic = CTDLMESSAGE_MAGIC;
148                         msg->cm_anon_type = MES_NORMAL;
149                         msg->cm_format_type = FMT_RFC822;
150                         msg->cm_fields['M'] = SmashStrBuf(&MsgData);
151                         CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
152                         CtdlFreeMessage(msg);
153                 }
154                 else {
155                         CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->MessageID, 1, "");
156                         FreeStrBuf(&MsgData);
157                 }
158
159                 RemoveQItem(Msg->MyQItem);
160         }
161
162         RemoveContext(Msg->IO.CitContext);
163         DeleteSmtpOutMsg(Msg);
164 }
165
166 eNextState FailOneAttempt(AsyncIO *IO)
167 {
168         SmtpOutMsg *SendMsg = IO->Data;
169         /* 
170          * possible ways here: 
171          * - connection timeout 
172          * - 
173          */
174         if (SendMsg->pCurrRelay != NULL)
175                 SendMsg->pCurrRelay = SendMsg->pCurrRelay->Next;
176
177         if (SendMsg->pCurrRelay == NULL)
178                 return eAbort;
179         if (SendMsg->pCurrRelay->IsIP)
180                 return mx_connect_ip(IO);
181         else
182                 return get_one_mx_host_ip(IO);
183 }
184
185
186 void SetConnectStatus(AsyncIO *IO)
187 {
188         
189         SmtpOutMsg *SendMsg = IO->Data;
190         char buf[256];
191         void *src;
192
193         buf[0] = '\0';
194
195         if (IO->ConnectMe->IPv6) {
196                 src = &IO->ConnectMe->Addr.sin6_addr;
197         }
198         else {
199                 struct sockaddr_in *addr = (struct sockaddr_in *)&IO->ConnectMe->Addr;
200
201                 src = &addr->sin_addr.s_addr;
202         }
203
204         inet_ntop((IO->ConnectMe->IPv6)?AF_INET6:AF_INET,
205                   src,
206                   buf, 
207                   sizeof(buf));
208
209         if (SendMsg->mx_host == NULL)
210                 SendMsg->mx_host = "<no name>";
211
212         CtdlLogPrintf(CTDL_DEBUG, 
213                       "SMTP client[%ld]: connecting to %s [%s]:%d ...\n", 
214                       SendMsg->n, 
215                       SendMsg->mx_host, 
216                       buf,
217                       SendMsg->IO.ConnectMe->Port);
218
219         SendMsg->MyQEntry->Status = 5; 
220         StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
221                      "Timeout while connecting %s [%s]:%d ", 
222                      SendMsg->mx_host,
223                      buf,
224                      SendMsg->IO.ConnectMe->Port);
225 }
226
227 /*****************************************************************************
228  * So we connect our Relay IP here.                                          *
229  *****************************************************************************/
230 eNextState mx_connect_ip(AsyncIO *IO)
231 {
232         SmtpOutMsg *SendMsg = IO->Data;
233
234         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
235         
236         IO->ConnectMe = SendMsg->pCurrRelay;
237         /*  Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
238
239         SetConnectStatus(IO);
240
241         return InitEventIO(IO, SendMsg, 
242                            SMTP_C_ConnTimeout, 
243                            SMTP_C_ReadTimeouts[0],
244                            1);
245 }
246
247 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
248 {
249         SmtpOutMsg *SendMsg = IO->Data;
250         struct hostent *hostent;
251
252         QueryCbDone(IO);
253
254         hostent = SendMsg->HostLookup.VParsedDNSReply;
255         if ((SendMsg->HostLookup.DNSStatus == ARES_SUCCESS) && 
256             (hostent != NULL) ) {
257                 memset(&SendMsg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
258                 if (SendMsg->pCurrRelay->IPv6) {
259                         memcpy(&SendMsg->pCurrRelay->Addr.sin6_addr.s6_addr, 
260                                &hostent->h_addr_list[0],
261                                sizeof(struct in6_addr));
262                         
263                         SendMsg->pCurrRelay->Addr.sin6_family = hostent->h_addrtype;
264                         SendMsg->pCurrRelay->Addr.sin6_port   = htons(DefaultMXPort);
265                 }
266                 else {
267                         struct sockaddr_in *addr = (struct sockaddr_in*) &SendMsg->pCurrRelay->Addr;
268                         /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
269 //                      addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
270                         memcpy(&addr->sin_addr.s_addr, 
271                                hostent->h_addr_list[0], 
272                                sizeof(uint32_t));
273                         
274                         addr->sin_family = hostent->h_addrtype;
275                         addr->sin_port   = htons(DefaultMXPort);
276                         
277                 }
278                 return mx_connect_ip(IO);
279         }
280         else // TODO: here we need to find out whether there are more mx'es, backup relay, and so on
281                 return FailOneAttempt(IO);
282 }
283
284 eNextState get_one_mx_host_ip(AsyncIO *IO)
285 {
286         SmtpOutMsg * SendMsg = IO->Data;
287         /* 
288          * here we start with the lookup of one host. it might be...
289          * - the relay host *sigh*
290          * - the direct hostname if there was no mx record
291          * - one of the mx'es
292          */ 
293
294         InitC_ares_dns(IO);
295
296         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
297
298         CtdlLogPrintf(CTDL_DEBUG, 
299                       "SMTP client[%ld]: looking up %s : %d ...\n", 
300                       SendMsg->n, 
301                       SendMsg->pCurrRelay->Host, 
302                       SendMsg->pCurrRelay->Port);
303
304         if (!QueueQuery((SendMsg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a, 
305                         SendMsg->pCurrRelay->Host, 
306                         &SendMsg->IO, 
307                         &SendMsg->HostLookup, 
308                         get_one_mx_host_ip_done))
309         {
310                 SendMsg->MyQEntry->Status = 5;
311                 StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
312                              "No MX hosts found for <%s>", SendMsg->node);
313                 return IO->NextState;
314         }
315         return IO->NextState;
316 }
317
318
319 /*****************************************************************************
320  * here we try to find out about the MX records for our recipients.          *
321  *****************************************************************************/
322 eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
323 {
324         SmtpOutMsg * SendMsg = IO->Data;
325         ParsedURL **pp;
326
327         QueryCbDone(IO);
328
329         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
330         pp = &SendMsg->Relay;
331         while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
332                 pp = &(*pp)->Next;
333
334         if ((IO->DNSQuery->DNSStatus == ARES_SUCCESS) && 
335             (IO->DNSQuery->VParsedDNSReply != NULL))
336         { /* ok, we found mx records. */
337                 SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
338                 
339                 SendMsg->CurrMX    = SendMsg->AllMX 
340                                    = IO->DNSQuery->VParsedDNSReply;
341                 while (SendMsg->CurrMX) {
342                         int i;
343                         for (i = 0; i < 2; i++) {
344                                 ParsedURL *p;
345
346                                 p = (ParsedURL*) malloc(sizeof(ParsedURL));
347                                 memset(p, 0, sizeof(ParsedURL));
348                                 p->IsIP = 0;
349                                 p->Port = DefaultMXPort;
350                                 p->IPv6 = i == 1;
351                                 p->Host = SendMsg->CurrMX->host;
352                                 
353                                 *pp = p;
354                                 pp = &p->Next;
355                         }
356                         SendMsg->CurrMX    = SendMsg->CurrMX->next;
357                 }
358                 SendMsg->CXFlags   = SendMsg->CXFlags & F_HAVE_MX;
359         }
360         else { /* else fall back to the plain hostname */
361                 int i;
362                 for (i = 0; i < 2; i++) {
363                         ParsedURL *p;
364
365                         p = (ParsedURL*) malloc(sizeof(ParsedURL));
366                         memset(p, 0, sizeof(ParsedURL));
367                         p->IsIP = 0;
368                         p->Port = DefaultMXPort;
369                         p->IPv6 = i == 1;
370                         p->Host = SendMsg->node;
371                                 
372                         *pp = p;
373                         pp = &p;
374                 }
375                 SendMsg->CXFlags   = SendMsg->CXFlags & F_DIRECT;
376         }
377         *pp = SendMsg->MyQItem->FallBackHost;
378         SendMsg->pCurrRelay = SendMsg->Relay;
379         return get_one_mx_host_ip(IO);
380 }
381
382 eNextState resolve_mx_records(AsyncIO *IO)
383 {
384         SmtpOutMsg * SendMsg = IO->Data;
385
386         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
387         /* start resolving MX records here. */
388         if (!QueueQuery(ns_t_mx, 
389                         SendMsg->node, 
390                         &SendMsg->IO, 
391                         &SendMsg->MxLookup, 
392                         smtp_resolve_mx_record_done))
393         {
394                 SendMsg->MyQEntry->Status = 5;
395                 StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
396                              "No MX hosts found for <%s>", SendMsg->node);
397                 return IO->NextState;
398         }
399         return eAbort;
400 }
401
402
403
404 /******************************************************************************
405  *  so, we're going to start a SMTP delivery.  lets get it on.                *
406  ******************************************************************************/
407
408 SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem, 
409                             MailQEntry *MyQEntry, 
410                             int MsgCount)
411 {
412         SmtpOutMsg * SendMsg;
413
414         SendMsg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
415         memset(SendMsg, 0, sizeof(SmtpOutMsg));
416
417         SendMsg->n                = MsgCount;
418         SendMsg->MyQEntry         = MyQEntry;
419         SendMsg->MyQItem          = MyQItem;
420         SendMsg->pCurrRelay       = MyQItem->URL;
421
422         SendMsg->IO.Data          = SendMsg;
423
424         SendMsg->IO.SendDone      = SMTP_C_DispatchWriteDone;
425         SendMsg->IO.ReadDone      = SMTP_C_DispatchReadDone;
426         SendMsg->IO.Terminate     = SMTP_C_Terminate;
427         SendMsg->IO.LineReader    = SMTP_C_ReadServerStatus;
428         SendMsg->IO.ConnFail      = SMTP_C_ConnFail;
429         SendMsg->IO.Timeout       = SMTP_C_Timeout;
430         SendMsg->IO.ShutdownAbort = SMTP_C_Shutdown;
431
432         SendMsg->IO.SendBuf.Buf   = NewStrBufPlain(NULL, 1024);
433         SendMsg->IO.RecvBuf.Buf   = NewStrBufPlain(NULL, 1024);
434         SendMsg->IO.IOBuf         = NewStrBuf();
435
436         SendMsg->IO.NextState     = eReadMessage;
437         
438         return SendMsg;
439 }
440
441 void smtp_try_one_queue_entry(OneQueItem *MyQItem, 
442                               MailQEntry *MyQEntry, 
443                               StrBuf *MsgText, 
444                               int KeepMsgText,  /* KeepMsgText allows us to use MsgText as ours. */
445                               int MsgCount)
446 {
447         SmtpOutMsg *SendMsg;
448
449         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
450
451         SendMsg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
452         if (KeepMsgText) SendMsg->msgtext = MsgText;
453         else             SendMsg->msgtext = NewStrBufDup(MsgText);
454         
455         if (smtp_resolve_recipients(SendMsg)) {
456                 CitContext *SubC;
457                 SubC = CloneContext (CC);
458                 SubC->session_specific_data = (char*) SendMsg;
459                 SendMsg->IO.CitContext = SubC;
460
461                 if (SendMsg->pCurrRelay == NULL)
462                         QueueEventContext(&SendMsg->IO,
463                                           resolve_mx_records);
464                 else { /* oh... via relay host */
465                         if (SendMsg->pCurrRelay->IsIP) {
466                                 QueueEventContext(&SendMsg->IO,
467                                                   mx_connect_ip);
468                         }
469                         else { /* uneducated admin has chosen to add DNS to the equation... */
470                                 QueueEventContext(&SendMsg->IO,
471                                                   get_one_mx_host_ip);
472                         }
473                 }
474         }
475         else {
476                 /* No recipients? well fail then. */
477                 if ((SendMsg==NULL) || 
478                     (SendMsg->MyQEntry == NULL)) {
479                         SendMsg->MyQEntry->Status = 5;
480                         StrBufPlain(SendMsg->MyQEntry->StatusMessage, 
481                                     HKEY("Invalid Recipient!"));
482                 }
483                 FinalizeMessageSend(SendMsg);
484         }
485 }
486
487
488
489
490
491
492 /*****************************************************************************/
493 /*                     SMTP CLIENT DISPATCHER                                */
494 /*****************************************************************************/
495
496 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *pMsg)
497 {
498         double Timeout = 0.0;
499
500         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
501
502         switch (NextTCPState) {
503         case eSendReply:
504         case eSendMore:
505                 Timeout = SMTP_C_SendTimeouts[pMsg->State];
506                 if (pMsg->State == eDATABody) {
507                         /* if we're sending a huge message, we need more time. */
508                         Timeout += StrLength(pMsg->msgtext) / 1024;
509                 }
510                 break;
511         case eReadMessage:
512                 Timeout = SMTP_C_ReadTimeouts[pMsg->State];
513                 if (pMsg->State == eDATATerminateBody) {
514                         /* 
515                          * some mailservers take a nap before accepting the message
516                          * content inspection and such.
517                          */
518                         Timeout += StrLength(pMsg->msgtext) / 1024;
519                 }
520                 break;
521         case eTerminateConnection:
522         case eAbort:
523                 return;
524         }
525         SetNextTimeout(&pMsg->IO, Timeout);
526 }
527 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO)
528 {
529         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
530         SmtpOutMsg *pMsg = IO->Data;
531         eNextState rc;
532
533         rc = ReadHandlers[pMsg->State](pMsg);
534         pMsg->State++;
535         SMTPSetTimeout(rc, pMsg);
536         return rc;
537 }
538 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO)
539 {
540         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
541         SmtpOutMsg *pMsg = IO->Data;
542         eNextState rc;
543
544         rc = SendHandlers[pMsg->State](pMsg);
545         SMTPSetTimeout(rc, pMsg);
546         return rc;
547 }
548
549
550 /*****************************************************************************/
551 /*                     SMTP CLIENT ERROR CATCHERS                            */
552 /*****************************************************************************/
553 eNextState SMTP_C_Terminate(AsyncIO *IO)
554 {
555         SmtpOutMsg *pMsg = IO->Data;
556
557         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
558         FinalizeMessageSend(pMsg);
559         return eAbort;
560 }
561 eNextState SMTP_C_Timeout(AsyncIO *IO)
562 {
563         SmtpOutMsg *pMsg = IO->Data;
564
565         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
566         StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[pMsg->State]));
567         return FailOneAttempt(IO);
568 }
569 eNextState SMTP_C_ConnFail(AsyncIO *IO)
570 {
571         SmtpOutMsg *pMsg = IO->Data;
572
573         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
574         StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[pMsg->State]));
575         return FailOneAttempt(IO);
576 }
577 eNextState SMTP_C_Shutdown(AsyncIO *IO)
578 {
579         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
580         SmtpOutMsg *pMsg = IO->Data;
581
582         pMsg->MyQEntry->Status = 3;
583         StrBufPlain(pMsg->MyQEntry->StatusMessage, HKEY("server shutdown during message submit."));
584         FinalizeMessageSend(pMsg);
585         return eAbort;
586 }
587
588
589 /**
590  * @brief lineread Handler; understands when to read more SMTP lines, and when this is a one-lined reply.
591  */
592 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
593 {
594         eReadState Finished = eBufferNotEmpty; 
595
596         while (Finished == eBufferNotEmpty) {
597                 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
598                 
599                 switch (Finished) {
600                 case eMustReadMore: /// read new from socket... 
601                         return Finished;
602                         break;
603                 case eBufferNotEmpty: /* shouldn't happen... */
604                 case eReadSuccess: /// done for now...
605                         if (StrLength(IO->IOBuf) < 4)
606                                 continue;
607                         if (ChrPtr(IO->IOBuf)[3] == '-')
608                                 Finished = eBufferNotEmpty;
609                         else 
610                                 return Finished;
611                         break;
612                 case eReadFail: /// WHUT?
613                         ///todo: shut down! 
614                         break;
615                 }
616         }
617         return Finished;
618 }
619
620 #endif
621 CTDL_MODULE_INIT(smtp_eventclient)
622 {
623         return "smtpeventclient";
624 }