2 * This module is an SMTP and ESMTP implementation for the Citadel system.
3 * It is compliant with all of the following:
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
20 * The VRFY and EXPN commands have been removed from this implementation
21 * because nobody uses these commands anymore, except for spammers.
23 * Copyright (c) 1998-2012 by the citadel.org team
25 * This program is open source software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License version 3.
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.
49 #include <sys/types.h>
52 #if TIME_WITH_SYS_TIME
53 # include <sys/time.h>
57 # include <sys/time.h>
66 #include <sys/socket.h>
67 #include <netinet/in.h>
68 #include <arpa/inet.h>
69 #include <libcitadel.h>
72 #include "citserver.h"
79 #include "internet_addressing.h"
82 #include "clientsocket.h"
83 #include "locate_host.h"
84 #include "citadel_dirs.h"
86 #include "ctdl_module.h"
88 #include "smtp_util.h"
89 #include "event_client.h"
90 #include "smtpqueue.h"
91 #include "smtp_clienthandlers.h"
93 ConstStr SMTPStates[] = {
94 {HKEY("looking up mx - record")},
95 {HKEY("evaluating what to do next")},
96 {HKEY("looking up a - record")},
97 {HKEY("looking up aaaa - record")},
98 {HKEY("connecting remote")},
99 {HKEY("smtp conversation ongoing")},
100 {HKEY("smtp sending maildata")},
101 {HKEY("smtp sending done")},
102 {HKEY("smtp successfully finished")},
103 {HKEY("failed one attempt")},
104 {HKEY("failed temporarily")},
105 {HKEY("failed permanently")}
108 void SetSMTPState(AsyncIO *IO, smtpstate State)
110 CitContext* CCC = IO->CitContext;
111 memcpy(CCC->cs_clientname, SMTPStates[State].Key, SMTPStates[State].len + 1);
114 int SMTPClientDebugEnabled = 0;
115 void DeleteSmtpOutMsg(void *v)
118 AsyncIO *IO = &Msg->IO;
119 EV_syslog(LOG_DEBUG, "%s Exit\n", __FUNCTION__);
121 /* these are kept in our own space and free'd below */
122 Msg->IO.ConnectMe = NULL;
124 ares_free_data(Msg->AllMX);
125 if (Msg->HostLookup.VParsedDNSReply != NULL)
126 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
127 FreeURL(&Msg->Relay);
128 FreeStrBuf(&Msg->msgtext);
129 FreeAsyncIOContents(&Msg->IO);
130 memset (Msg, 0, sizeof(SmtpOutMsg)); /* just to be shure... */
134 eNextState SMTP_C_Shutdown(AsyncIO *IO);
135 eNextState SMTP_C_Timeout(AsyncIO *IO);
136 eNextState SMTP_C_ConnFail(AsyncIO *IO);
137 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO);
138 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO);
139 eNextState SMTP_C_DNSFail(AsyncIO *IO);
140 eNextState SMTP_C_Terminate(AsyncIO *IO);
141 eNextState SMTP_C_TerminateDB(AsyncIO *IO);
142 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO);
144 eNextState mx_connect_ip(AsyncIO *IO);
145 eNextState get_one_mx_host_ip(AsyncIO *IO);
147 /******************************************************************************
148 * So, we're finished with sending (regardless of success or failure) *
149 * This Message might be referenced by several Queue-Items, if we're the last,*
150 * we need to free the memory and send bounce messages (on terminal failure) *
151 * else we just free our SMTP-Message struct. *
152 ******************************************************************************/
153 eNextState FinalizeMessageSend_DB(AsyncIO *IO)
156 SmtpOutMsg *Msg = IO->Data;
158 if (Msg->MyQEntry->Status == 2) {
159 SetSMTPState(IO, eSTMPfinished);
160 Status = "Delivery successful.";
162 else if (Msg->MyQEntry->Status == 5) {
163 SetSMTPState(IO, eSMTPFailTotal);
164 Status = "Delivery failed permanently; giving up.";
167 SetSMTPState(IO, eSMTPFailTemporary);
168 Status = "Delivery failed temporarily; will retry later.";
172 "%s Time[%fs] Recipient <%s> @ <%s> (%s) Status message: %s\n",
174 Msg->IO.Now - Msg->IO.StartIO,
178 ChrPtr(Msg->MyQEntry->StatusMessage));
181 Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
183 Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem, 0);
185 if (Msg->MyQEntry->Active &&
186 !Msg->MyQEntry->StillActive &&
187 CheckQEntryIsBounce(Msg->MyQEntry))
189 /* are we casue for a bounce mail? */
190 Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
193 if ((Msg->nRemain > 0) || Msg->IDestructQueItem)
194 Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
196 Msg->QMsgData = NULL;
199 * Uncompleted delivery instructions remain, so delete the old
200 * instructions and replace with the updated ones.
202 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
203 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
204 Msg->MyQItem->QueMsgID = -1;
206 if (Msg->IDestructQueItem)
207 smtpq_do_bounce(Msg->MyQItem, Msg->msgtext, Msg->pCurrRelay);
209 if (Msg->nRemain > 0)
211 struct CtdlMessage *msg;
212 msg = malloc(sizeof(struct CtdlMessage));
213 memset(msg, 0, sizeof(struct CtdlMessage));
214 msg->cm_magic = CTDLMESSAGE_MAGIC;
215 msg->cm_anon_type = MES_NORMAL;
216 msg->cm_format_type = FMT_RFC822;
217 msg->cm_fields['M'] = SmashStrBuf(&Msg->QMsgData);
218 msg->cm_fields['U'] = strdup("QMSG");
219 Msg->MyQItem->QueMsgID =
220 CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
221 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
222 CtdlFreeMessage(msg);
225 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM,
226 &Msg->MyQItem->MessageID,
229 FreeStrBuf(&Msg->QMsgData);
232 RemoveContext(Msg->IO.CitContext);
236 eNextState Terminate(AsyncIO *IO)
238 SmtpOutMsg *Msg = IO->Data;
240 if (Msg->IDestructQueItem)
241 RemoveQItem(Msg->MyQItem);
243 DeleteSmtpOutMsg(Msg);
246 eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
248 /* hand over to DB Queue */
249 return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB);
252 eNextState FailOneAttempt(AsyncIO *IO)
254 SmtpOutMsg *Msg = IO->Data;
256 SetSMTPState(IO, eSTMPfailOne);
257 if (Msg->MyQEntry->Status == 2)
261 * possible ways here:
262 * - connection timeout
263 * - dns lookup failed
265 StopClientWatchers(IO, 1);
267 Msg->MyQEntry->nAttempt ++;
268 if (Msg->MyQEntry->AllStatusMessages == NULL)
269 Msg->MyQEntry->AllStatusMessages = NewStrBuf();
271 StrBufAppendPrintf(Msg->MyQEntry->AllStatusMessages, "%ld) ", Msg->MyQEntry->nAttempt);
272 StrBufAppendBuf(Msg->MyQEntry->AllStatusMessages, Msg->MyQEntry->StatusMessage, 0);
273 StrBufAppendBufPlain(Msg->MyQEntry->AllStatusMessages, HKEY("; "), 0);
275 if (Msg->pCurrRelay != NULL)
276 Msg->pCurrRelay = Msg->pCurrRelay->Next;
277 if ((Msg->pCurrRelay != NULL) &&
278 !Msg->pCurrRelay->IsRelay &&
279 Msg->MyQItem->HaveRelay)
281 EVS_syslog(LOG_DEBUG, "%s Aborting; last relay failed.\n", __FUNCTION__);
285 if (Msg->pCurrRelay == NULL) {
286 EVS_syslog(LOG_DEBUG, "%s Aborting\n", __FUNCTION__);
289 if (Msg->pCurrRelay->IsIP) {
290 EVS_syslog(LOG_DEBUG, "%s connecting IP\n", __FUNCTION__);
291 return mx_connect_ip(IO);
294 EVS_syslog(LOG_DEBUG,
295 "%s resolving next MX Record\n",
297 return get_one_mx_host_ip(IO);
302 void SetConnectStatus(AsyncIO *IO)
304 SmtpOutMsg *Msg = IO->Data;
310 if (IO->ConnectMe->IPv6) {
311 src = &IO->ConnectMe->Addr.sin6_addr;
314 struct sockaddr_in *addr;
316 addr = (struct sockaddr_in *)&IO->ConnectMe->Addr;
317 src = &addr->sin_addr.s_addr;
320 inet_ntop((IO->ConnectMe->IPv6)?AF_INET6:AF_INET,
325 if (Msg->mx_host == NULL)
326 Msg->mx_host = "<no MX-Record>";
329 "connecting to %s [%s]:%d ...\n",
332 Msg->IO.ConnectMe->Port);
334 Msg->MyQEntry->Status = 4;
335 StrBufPrintf(Msg->MyQEntry->StatusMessage,
336 "Timeout while connecting %s [%s]:%d ",
339 Msg->IO.ConnectMe->Port);
340 Msg->IO.NextState = eConnect;
343 /*****************************************************************************
344 * So we connect our Relay IP here. *
345 *****************************************************************************/
346 eNextState mx_connect_ip(AsyncIO *IO)
348 SmtpOutMsg *Msg = IO->Data;
349 SetSMTPState(IO, eSTMPconnecting);
351 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
353 IO->ConnectMe = Msg->pCurrRelay;
354 Msg->State = eConnectMX;
356 SetConnectStatus(IO);
358 return EvConnectSock(IO,
360 SMTP_C_ReadTimeouts[0],
364 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
366 SmtpOutMsg *Msg = IO->Data;
367 struct hostent *hostent;
369 IO->ConnectMe = Msg->pCurrRelay;
372 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
374 IO->Now - IO->DNS.Start);
376 hostent = Msg->HostLookup.VParsedDNSReply;
377 if ((Msg->HostLookup.DNSStatus == ARES_SUCCESS) &&
378 (hostent != NULL) ) {
379 memset(&Msg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
380 if (Msg->pCurrRelay->IPv6) {
381 memcpy(&Msg->pCurrRelay->Addr.sin6_addr.s6_addr,
382 &hostent->h_addr_list[0],
383 sizeof(struct in6_addr));
385 Msg->pCurrRelay->Addr.sin6_family =
387 Msg->pCurrRelay->Addr.sin6_port =
388 htons(Msg->IO.ConnectMe->Port);
391 struct sockaddr_in *addr;
393 * Bypass the ns lookup result like this:
394 * IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
395 * addr->sin_addr.s_addr =
396 * htonl((uint32_t)&hostent->h_addr_list[0]);
399 addr = (struct sockaddr_in*) &Msg->pCurrRelay->Addr;
401 memcpy(&addr->sin_addr.s_addr,
402 hostent->h_addr_list[0],
405 addr->sin_family = hostent->h_addrtype;
406 addr->sin_port = htons(Msg->IO.ConnectMe->Port);
408 Msg->mx_host = Msg->pCurrRelay->Host;
409 if (Msg->HostLookup.VParsedDNSReply != NULL) {
410 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
411 Msg->HostLookup.VParsedDNSReply = NULL;
413 return mx_connect_ip(IO);
416 SetSMTPState(IO, eSTMPfailOne);
417 if (Msg->HostLookup.VParsedDNSReply != NULL) {
418 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
419 Msg->HostLookup.VParsedDNSReply = NULL;
421 return FailOneAttempt(IO);
425 eNextState get_one_mx_host_ip(AsyncIO *IO)
427 SmtpOutMsg * Msg = IO->Data;
429 * here we start with the lookup of one host. it might be...
430 * - the relay host *sigh*
431 * - the direct hostname if there was no mx record
434 SetSMTPState(IO, (Msg->pCurrRelay->IPv6)?eSTMPalookup:eSTMPaaaalookup);
436 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
438 EVS_syslog(LOG_DEBUG,
439 "looking up %s-Record %s : %d ...\n",
440 (Msg->pCurrRelay->IPv6)? "aaaa": "a",
441 Msg->pCurrRelay->Host,
442 Msg->pCurrRelay->Port);
444 if (!QueueQuery((Msg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a,
445 Msg->pCurrRelay->Host,
448 get_one_mx_host_ip_done))
450 Msg->MyQEntry->Status = 5;
451 StrBufPrintf(Msg->MyQEntry->StatusMessage,
452 "No MX hosts found for <%s>", Msg->node);
453 Msg->IO.NextState = eTerminateConnection;
454 return IO->NextState;
456 IO->NextState = eReadDNSReply;
457 return IO->NextState;
461 /*****************************************************************************
462 * here we try to find out about the MX records for our recipients. *
463 *****************************************************************************/
464 eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
466 SmtpOutMsg * Msg = IO->Data;
471 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
473 IO->Now - IO->DNS.Start);
476 while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
479 if ((IO->DNS.Query->DNSStatus == ARES_SUCCESS) &&
480 (IO->DNS.Query->VParsedDNSReply != NULL))
481 { /* ok, we found mx records. */
485 = IO->DNS.Query->VParsedDNSReply;
486 while (Msg->CurrMX) {
488 for (i = 0; i < 2; i++) {
491 p = (ParsedURL*) malloc(sizeof(ParsedURL));
492 memset(p, 0, sizeof(ParsedURL));
493 p->Priority = Msg->CurrMX->priority;
495 p->Port = DefaultMXPort;
497 p->Host = Msg->CurrMX->host;
501 ParsedURL *ppp = *pp;
503 while ((ppp->Next != NULL) &&
504 (ppp->Next->Priority <= p->Priority))
507 (ppp->Priority > p->Priority)) {
517 Msg->CurrMX = Msg->CurrMX->next;
519 Msg->CXFlags = Msg->CXFlags & F_HAVE_MX;
521 else { /* else fall back to the plain hostname */
523 for (i = 0; i < 2; i++) {
526 p = (ParsedURL*) malloc(sizeof(ParsedURL));
527 memset(p, 0, sizeof(ParsedURL));
529 p->Port = DefaultMXPort;
536 Msg->CXFlags = Msg->CXFlags & F_DIRECT;
538 if (Msg->MyQItem->FallBackHost != NULL)
540 Msg->MyQItem->FallBackHost->Next = *pp;
541 *pp = Msg->MyQItem->FallBackHost;
543 Msg->pCurrRelay = Msg->Relay;
544 return get_one_mx_host_ip(IO);
547 eNextState resolve_mx_records(AsyncIO *IO)
549 SmtpOutMsg * Msg = IO->Data;
551 SetSMTPState(IO, eSTMPmxlookup);
553 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
554 /* start resolving MX records here. */
555 if (!QueueQuery(ns_t_mx,
559 smtp_resolve_mx_record_done))
561 Msg->MyQEntry->Status = 5;
562 StrBufPrintf(Msg->MyQEntry->StatusMessage,
563 "No MX hosts found for <%s>", Msg->node);
564 return IO->NextState;
566 Msg->IO.NextState = eReadDNSReply;
567 return IO->NextState;
572 /******************************************************************************
573 * so, we're going to start a SMTP delivery. lets get it on. *
574 ******************************************************************************/
576 SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem,
577 MailQEntry *MyQEntry,
582 Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
585 memset(Msg, 0, sizeof(SmtpOutMsg));
588 Msg->MyQEntry = MyQEntry;
589 Msg->MyQItem = MyQItem;
590 Msg->pCurrRelay = MyQItem->URL;
592 InitIOStruct(&Msg->IO,
595 SMTP_C_ReadServerStatus,
597 SMTP_C_DispatchWriteDone,
598 SMTP_C_DispatchReadDone,
605 Msg->IO.ErrMsg = Msg->MyQEntry->StatusMessage;
610 void smtp_try_one_queue_entry(OneQueItem *MyQItem,
611 MailQEntry *MyQEntry,
613 /*KeepMsgText allows us to use MsgText as ours.*/
619 SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
621 Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
623 SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__);
625 FreeStrBuf (&MsgText);
628 if (KeepMsgText) Msg->msgtext = MsgText;
629 else Msg->msgtext = NewStrBufDup(MsgText);
631 if (smtp_resolve_recipients(Msg) &&
632 (!MyQItem->HaveRelay ||
633 (MyQItem->URL != NULL)))
636 ((CitContext *)Msg->IO.CitContext)->cs_host,
638 sizeof(((CitContext *)
639 Msg->IO.CitContext)->cs_host));
641 SMTPC_syslog(LOG_DEBUG, "Starting: [%ld] <%s> CC <%d> \n",
642 Msg->MyQItem->MessageID,
643 ChrPtr(Msg->MyQEntry->Recipient),
644 ((CitContext*)Msg->IO.CitContext)->cs_pid);
645 if (Msg->pCurrRelay == NULL) {
646 SetSMTPState(&Msg->IO, eSTMPmxlookup);
647 QueueEventContext(&Msg->IO,
650 else { /* oh... via relay host */
651 if (Msg->pCurrRelay->IsIP) {
652 SetSMTPState(&Msg->IO, eSTMPconnecting);
653 QueueEventContext(&Msg->IO,
657 SetSMTPState(&Msg->IO, eSTMPalookup);
658 /* uneducated admin has chosen to
659 add DNS to the equation... */
660 QueueEventContext(&Msg->IO,
666 SetSMTPState(&Msg->IO, eSMTPFailTotal);
667 /* No recipients? well fail then. */
668 if (Msg->MyQEntry != NULL) {
669 Msg->MyQEntry->Status = 5;
670 if (StrLength(Msg->MyQEntry->StatusMessage) == 0)
671 StrBufPlain(Msg->MyQEntry->StatusMessage,
672 HKEY("Invalid Recipient!"));
674 FinalizeMessageSend_DB(&Msg->IO);
675 DeleteSmtpOutMsg(Msg);
684 /*****************************************************************************/
685 /* SMTP CLIENT DISPATCHER */
686 /*****************************************************************************/
688 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *Msg)
690 double Timeout = 0.0;
691 AsyncIO *IO = &Msg->IO;
693 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
695 switch (NextTCPState) {
699 Timeout = SMTP_C_SendTimeouts[Msg->State];
700 if (Msg->State == eDATABody) {
701 /* if we're sending a huge message,
704 Timeout += StrLength(Msg->msgtext) / 512;
708 Timeout = SMTP_C_ReadTimeouts[Msg->State];
709 if (Msg->State == eDATATerminateBody) {
711 * some mailservers take a nap before accepting
712 * the message content inspection and such.
714 Timeout += StrLength(Msg->msgtext) / 512;
724 case eTerminateConnection:
728 SetNextTimeout(&Msg->IO, Timeout);
730 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO)
732 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
733 SmtpOutMsg *Msg = IO->Data;
736 rc = ReadHandlers[Msg->State](Msg);
740 SMTPSetTimeout(rc, Msg);
744 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO)
746 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
747 SmtpOutMsg *Msg = IO->Data;
750 rc = SendHandlers[Msg->State](Msg);
751 SMTPSetTimeout(rc, Msg);
756 /*****************************************************************************/
757 /* SMTP CLIENT ERROR CATCHERS */
758 /*****************************************************************************/
759 eNextState SMTP_C_Terminate(AsyncIO *IO)
761 SmtpOutMsg *Msg = IO->Data;
763 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
764 return FinalizeMessageSend(Msg);
766 eNextState SMTP_C_TerminateDB(AsyncIO *IO)
768 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
769 return Terminate(IO);
771 eNextState SMTP_C_Timeout(AsyncIO *IO)
773 SmtpOutMsg *Msg = IO->Data;
775 Msg->MyQEntry->Status = 4;
776 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
777 StrBufPrintf(IO->ErrMsg, "Timeout: %s while talking to %s",
778 ReadErrors[Msg->State].Key,
780 if (Msg->State > eRCPT)
783 return FailOneAttempt(IO);
785 eNextState SMTP_C_ConnFail(AsyncIO *IO)
787 SmtpOutMsg *Msg = IO->Data;
789 Msg->MyQEntry->Status = 4;
790 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
791 StrBufPrintf(IO->ErrMsg, "Connection failure: %s while talking to %s",
792 ReadErrors[Msg->State].Key,
795 return FailOneAttempt(IO);
797 eNextState SMTP_C_DNSFail(AsyncIO *IO)
799 SmtpOutMsg *Msg = IO->Data;
800 Msg->MyQEntry->Status = 4;
801 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
802 return FailOneAttempt(IO);
804 eNextState SMTP_C_Shutdown(AsyncIO *IO)
806 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
807 SmtpOutMsg *Msg = IO->Data;
809 switch (IO->NextState) {
813 /* todo: abort c-ares */
822 StopClientWatchers(IO, 1);
827 case eTerminateConnection:
831 Msg->MyQEntry->Status = 3;
832 StrBufPlain(Msg->MyQEntry->StatusMessage,
833 HKEY("server shutdown during message submit."));
834 return FinalizeMessageSend(Msg);
839 * @brief lineread Handler;
840 * understands when to read more SMTP lines, and when this is a one-lined reply.
842 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
844 eReadState Finished = eBufferNotEmpty;
846 while (Finished == eBufferNotEmpty) {
847 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
850 case eMustReadMore: /// read new from socket...
853 case eBufferNotEmpty: /* shouldn't happen... */
854 case eReadSuccess: /// done for now...
855 if (StrLength(IO->IOBuf) < 4)
857 if (ChrPtr(IO->IOBuf)[3] == '-')
858 Finished = eBufferNotEmpty;
862 case eReadFail: /// WHUT?
870 void LogDebugEnableSMTPClient(const int n)
872 SMTPClientDebugEnabled = n;
875 CTDL_MODULE_INIT(smtp_eventclient)
878 CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient, &SMTPClientDebugEnabled);
879 return "smtpeventclient";