a2913bb9b23d57a2024c16f1c970c5572170cf95
[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         SendMsg->pCurrRelay = SendMsg->pCurrRelay->Next;
175
176         if (SendMsg->pCurrRelay == NULL)
177                 return eAbort;
178         if (SendMsg->pCurrRelay->IsIP)
179                 return mx_connect_ip(IO);
180         else
181                 return get_one_mx_host_ip(IO);
182 }
183
184
185 void SetConnectStatus(AsyncIO *IO)
186 {
187         
188         SmtpOutMsg *SendMsg = IO->Data;
189         char buf[256];
190         void *src;
191
192         buf[0] = '\0';
193
194         if (IO->ConnectMe->IPv6) {
195                 src = &IO->ConnectMe->Addr.sin6_addr;
196         }
197         else {
198                 struct sockaddr_in *addr = (struct sockaddr_in *)&IO->ConnectMe->Addr;
199
200                 src = &addr->sin_addr.s_addr;
201         }
202
203         inet_ntop((IO->ConnectMe->IPv6)?AF_INET6:AF_INET,
204                   src,
205                   buf, 
206                   sizeof(buf));
207
208         if (SendMsg->mx_host == NULL)
209                 SendMsg->mx_host = "<no name>";
210
211         CtdlLogPrintf(CTDL_DEBUG, 
212                       "SMTP client[%ld]: connecting to %s [%s]:%d ...\n", 
213                       SendMsg->n, 
214                       SendMsg->mx_host, 
215                       buf,
216                       SendMsg->IO.ConnectMe->Port);
217
218         SendMsg->MyQEntry->Status = 5; 
219         StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
220                      "Timeout while connecting %s [%s]:%d ", 
221                      SendMsg->mx_host,
222                      buf,
223                      SendMsg->IO.ConnectMe->Port);
224 }
225
226 /*****************************************************************************
227  * So we connect our Relay IP here.                                          *
228  *****************************************************************************/
229 eNextState mx_connect_ip(AsyncIO *IO)
230 {
231         SmtpOutMsg *SendMsg = IO->Data;
232
233         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
234         
235         IO->ConnectMe = SendMsg->pCurrRelay;
236         /*  Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
237
238         SetConnectStatus(IO);
239
240         return InitEventIO(IO, SendMsg, 
241                            SMTP_C_ConnTimeout, 
242                            SMTP_C_ReadTimeouts[0],
243                            1);
244 }
245
246 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
247 {
248         SmtpOutMsg *SendMsg = IO->Data;
249         struct hostent *hostent;
250
251         QueryCbDone(IO);
252
253         hostent = SendMsg->HostLookup.VParsedDNSReply;
254         if ((SendMsg->HostLookup.DNSStatus == ARES_SUCCESS) && 
255             (hostent != NULL) ) {
256                 memset(&SendMsg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
257                 if (SendMsg->pCurrRelay->IPv6) {
258                         memcpy(&SendMsg->pCurrRelay->Addr.sin6_addr.s6_addr, 
259                                &hostent->h_addr_list[0],
260                                sizeof(struct in6_addr));
261                         
262                         SendMsg->pCurrRelay->Addr.sin6_family = hostent->h_addrtype;
263                         SendMsg->pCurrRelay->Addr.sin6_port   = htons(DefaultMXPort);
264                 }
265                 else {
266                         struct sockaddr_in *addr = (struct sockaddr_in*) &SendMsg->pCurrRelay->Addr;
267                         /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
268 //                      addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
269                         memcpy(&addr->sin_addr.s_addr, 
270                                hostent->h_addr_list[0], 
271                                sizeof(uint32_t));
272                         
273                         addr->sin_family = hostent->h_addrtype;
274                         addr->sin_port   = htons(DefaultMXPort);
275                         
276                 }
277                 return mx_connect_ip(IO);
278         }
279         else // TODO: here we need to find out whether there are more mx'es, backup relay, and so on
280                 return FailOneAttempt(IO);
281 }
282
283 eNextState get_one_mx_host_ip(AsyncIO *IO)
284 {
285         SmtpOutMsg * SendMsg = IO->Data;
286         /* 
287          * here we start with the lookup of one host. it might be...
288          * - the relay host *sigh*
289          * - the direct hostname if there was no mx record
290          * - one of the mx'es
291          */ 
292
293         InitC_ares_dns(IO);
294
295         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
296
297         CtdlLogPrintf(CTDL_DEBUG, 
298                       "SMTP client[%ld]: looking up %s : %d ...\n", 
299                       SendMsg->n, 
300                       SendMsg->pCurrRelay->Host, 
301                       SendMsg->pCurrRelay->Port);
302
303         if (!QueueQuery((SendMsg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a, 
304                         SendMsg->pCurrRelay->Host, 
305                         &SendMsg->IO, 
306                         &SendMsg->HostLookup, 
307                         get_one_mx_host_ip_done))
308         {
309                 SendMsg->MyQEntry->Status = 5;
310                 StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
311                              "No MX hosts found for <%s>", SendMsg->node);
312                 return IO->NextState;
313         }
314         return IO->NextState;
315 }
316
317
318 /*****************************************************************************
319  * here we try to find out about the MX records for our recipients.          *
320  *****************************************************************************/
321 eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
322 {
323         SmtpOutMsg * SendMsg = IO->Data;
324         ParsedURL **pp;
325
326         QueryCbDone(IO);
327
328         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
329         pp = &SendMsg->Relay;
330         while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
331                 pp = &(*pp)->Next;
332
333         if ((IO->DNSQuery->DNSStatus == ARES_SUCCESS) && 
334             (IO->DNSQuery->VParsedDNSReply != NULL))
335         { /* ok, we found mx records. */
336                 SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
337                 
338                 SendMsg->CurrMX    = SendMsg->AllMX 
339                                    = IO->DNSQuery->VParsedDNSReply;
340                 while (SendMsg->CurrMX) {
341                         int i;
342                         for (i = 0; i < 2; i++) {
343                                 ParsedURL *p;
344
345                                 p = (ParsedURL*) malloc(sizeof(ParsedURL));
346                                 memset(p, 0, sizeof(ParsedURL));
347                                 p->IsIP = 0;
348                                 p->Port = DefaultMXPort;
349                                 p->IPv6 = i == 1;
350                                 p->Host = SendMsg->CurrMX->host;
351                                 
352                                 *pp = p;
353                                 pp = &p->Next;
354                         }
355                         SendMsg->CurrMX    = SendMsg->CurrMX->next;
356                 }
357                 SendMsg->CXFlags   = SendMsg->CXFlags & F_HAVE_MX;
358         }
359         else { /* else fall back to the plain hostname */
360                 int i;
361                 for (i = 0; i < 2; i++) {
362                         ParsedURL *p;
363
364                         p = (ParsedURL*) malloc(sizeof(ParsedURL));
365                         memset(p, 0, sizeof(ParsedURL));
366                         p->IsIP = 0;
367                         p->Port = DefaultMXPort;
368                         p->IPv6 = i == 1;
369                         p->Host = SendMsg->node;
370                                 
371                         *pp = p;
372                         pp = &p;
373                 }
374                 SendMsg->CXFlags   = SendMsg->CXFlags & F_DIRECT;
375         }
376         *pp = SendMsg->MyQItem->FallBackHost;
377         SendMsg->pCurrRelay = SendMsg->Relay;
378         return get_one_mx_host_ip(IO);
379 }
380
381 eNextState resolve_mx_records(AsyncIO *IO)
382 {
383         SmtpOutMsg * SendMsg = IO->Data;
384
385         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
386         /* start resolving MX records here. */
387         if (!QueueQuery(ns_t_mx, 
388                         SendMsg->node, 
389                         &SendMsg->IO, 
390                         &SendMsg->MxLookup, 
391                         smtp_resolve_mx_record_done))
392         {
393                 SendMsg->MyQEntry->Status = 5;
394                 StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
395                              "No MX hosts found for <%s>", SendMsg->node);
396                 return IO->NextState;
397         }
398         return eAbort;
399 }
400
401
402
403 /******************************************************************************
404  *  so, we're going to start a SMTP delivery.  lets get it on.                *
405  ******************************************************************************/
406
407 SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem, 
408                             MailQEntry *MyQEntry, 
409                             int MsgCount)
410 {
411         SmtpOutMsg * SendMsg;
412
413         SendMsg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
414         memset(SendMsg, 0, sizeof(SmtpOutMsg));
415
416         SendMsg->n                = MsgCount;
417         SendMsg->MyQEntry         = MyQEntry;
418         SendMsg->MyQItem          = MyQItem;
419         SendMsg->pCurrRelay       = MyQItem->URL;
420
421         SendMsg->IO.Data          = SendMsg;
422
423         SendMsg->IO.SendDone      = SMTP_C_DispatchWriteDone;
424         SendMsg->IO.ReadDone      = SMTP_C_DispatchReadDone;
425         SendMsg->IO.Terminate     = SMTP_C_Terminate;
426         SendMsg->IO.LineReader    = SMTP_C_ReadServerStatus;
427         SendMsg->IO.ConnFail      = SMTP_C_ConnFail;
428         SendMsg->IO.Timeout       = SMTP_C_Timeout;
429         SendMsg->IO.ShutdownAbort = SMTP_C_Shutdown;
430
431         SendMsg->IO.SendBuf.Buf   = NewStrBufPlain(NULL, 1024);
432         SendMsg->IO.RecvBuf.Buf   = NewStrBufPlain(NULL, 1024);
433         SendMsg->IO.IOBuf         = NewStrBuf();
434
435         SendMsg->IO.NextState     = eReadMessage;
436         
437         return SendMsg;
438 }
439
440 void smtp_try_one_queue_entry(OneQueItem *MyQItem, 
441                               MailQEntry *MyQEntry, 
442                               StrBuf *MsgText, 
443                               int KeepMsgText,  /* KeepMsgText allows us to use MsgText as ours. */
444                               int MsgCount)
445 {
446         SmtpOutMsg *SendMsg;
447
448         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
449
450         SendMsg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
451         if (KeepMsgText) SendMsg->msgtext = MsgText;
452         else             SendMsg->msgtext = NewStrBufDup(MsgText);
453         
454         if (smtp_resolve_recipients(SendMsg)) {
455                 CitContext *SubC;
456                 SubC = CloneContext (CC);
457                 SubC->session_specific_data = (char*) SendMsg;
458                 SendMsg->IO.CitContext = SubC;
459
460                 if (SendMsg->pCurrRelay == NULL)
461                         QueueEventContext(&SendMsg->IO,
462                                           resolve_mx_records);
463                 else { /* oh... via relay host */
464                         if (SendMsg->pCurrRelay->IsIP) {
465                                 QueueEventContext(&SendMsg->IO,
466                                                   mx_connect_ip);
467                         }
468                         else { /* uneducated admin has chosen to add DNS to the equation... */
469                                 QueueEventContext(&SendMsg->IO,
470                                                   get_one_mx_host_ip);
471                         }
472                 }
473         }
474         else {
475                 /* No recipients? well fail then. */
476                 if ((SendMsg==NULL) || 
477                     (SendMsg->MyQEntry == NULL)) {
478                         SendMsg->MyQEntry->Status = 5;
479                         StrBufPlain(SendMsg->MyQEntry->StatusMessage, 
480                                     HKEY("Invalid Recipient!"));
481                 }
482                 FinalizeMessageSend(SendMsg);
483         }
484 }
485
486
487
488
489
490
491 /*****************************************************************************/
492 /*                     SMTP CLIENT DISPATCHER                                */
493 /*****************************************************************************/
494
495 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *pMsg)
496 {
497         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
498         double Timeout;
499         switch (NextTCPState) {
500         case eSendReply:
501         case eSendMore:
502                 Timeout = SMTP_C_SendTimeouts[pMsg->State];
503                 if (pMsg->State == eDATABody) {
504                         /* if we're sending a huge message, we need more time. */
505                         Timeout += StrLength(pMsg->msgtext) / 1024;
506                 }
507                 break;
508         case eReadMessage:
509                 Timeout = SMTP_C_ReadTimeouts[pMsg->State];
510                 if (pMsg->State == eDATATerminateBody) {
511                         /* 
512                          * some mailservers take a nap before accepting the message
513                          * content inspection and such.
514                          */
515                         Timeout += StrLength(pMsg->msgtext) / 1024;
516                 }
517                 break;
518         case eTerminateConnection:
519         case eAbort:
520                 return;
521         }
522         SetNextTimeout(&pMsg->IO, Timeout);
523 }
524 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO)
525 {
526         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
527         SmtpOutMsg *pMsg = IO->Data;
528         eNextState rc;
529
530         rc = ReadHandlers[pMsg->State](pMsg);
531         pMsg->State++;
532         SMTPSetTimeout(rc, pMsg);
533         return rc;
534 }
535 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO)
536 {
537         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
538         SmtpOutMsg *pMsg = IO->Data;
539         eNextState rc;
540
541         rc = SendHandlers[pMsg->State](pMsg);
542         SMTPSetTimeout(rc, pMsg);
543         return rc;
544 }
545
546
547 /*****************************************************************************/
548 /*                     SMTP CLIENT ERROR CATCHERS                            */
549 /*****************************************************************************/
550 eNextState SMTP_C_Terminate(AsyncIO *IO)
551 {
552         SmtpOutMsg *pMsg = IO->Data;
553
554         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
555         FinalizeMessageSend(pMsg);
556         return eAbort;
557 }
558 eNextState SMTP_C_Timeout(AsyncIO *IO)
559 {
560         SmtpOutMsg *pMsg = IO->Data;
561
562         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
563         StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[pMsg->State]));
564         return FailOneAttempt(IO);
565 }
566 eNextState SMTP_C_ConnFail(AsyncIO *IO)
567 {
568         SmtpOutMsg *pMsg = IO->Data;
569
570         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
571         StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[pMsg->State]));
572         return FailOneAttempt(IO);
573 }
574 eNextState SMTP_C_Shutdown(AsyncIO *IO)
575 {
576         CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
577         SmtpOutMsg *pMsg = IO->Data;
578
579         pMsg->MyQEntry->Status = 3;
580         StrBufPlain(pMsg->MyQEntry->StatusMessage, HKEY("server shutdown during message submit."));
581         FinalizeMessageSend(pMsg);
582         return eAbort;
583 }
584
585
586 /**
587  * @brief lineread Handler; understands when to read more SMTP lines, and when this is a one-lined reply.
588  */
589 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
590 {
591         eReadState Finished = eBufferNotEmpty; 
592
593         while (Finished == eBufferNotEmpty) {
594                 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
595                 
596                 switch (Finished) {
597                 case eMustReadMore: /// read new from socket... 
598                         return Finished;
599                         break;
600                 case eBufferNotEmpty: /* shouldn't happen... */
601                 case eReadSuccess: /// done for now...
602                         if (StrLength(IO->IOBuf) < 4)
603                                 continue;
604                         if (ChrPtr(IO->IOBuf)[3] == '-')
605                                 Finished = eBufferNotEmpty;
606                         else 
607                                 return Finished;
608                         break;
609                 case eReadFail: /// WHUT?
610                         ///todo: shut down! 
611                         break;
612                 }
613         }
614         return Finished;
615 }
616
617 #endif
618 CTDL_MODULE_INIT(smtp_eventclient)
619 {
620         return "smtpeventclient";
621 }