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;
157 StrBuf *StatusMessage;
159 if (Msg->MyQEntry->AllStatusMessages != NULL)
160 StatusMessage = Msg->MyQEntry->AllStatusMessages;
162 StatusMessage = Msg->MyQEntry->StatusMessage;
165 if (Msg->MyQEntry->Status == 2) {
166 SetSMTPState(IO, eSTMPfinished);
167 Status = "Delivery successful.";
169 else if (Msg->MyQEntry->Status == 5) {
170 SetSMTPState(IO, eSMTPFailTotal);
171 Status = "Delivery failed permanently; giving up.";
174 SetSMTPState(IO, eSMTPFailTemporary);
175 Status = "Delivery failed temporarily; will retry later.";
179 "%s Time[%fs] Recipient <%s> @ <%s> (%s) Status message: %s\n",
181 Msg->IO.Now - Msg->IO.StartIO,
185 ChrPtr(StatusMessage));
188 Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
190 Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem, 0);
192 if (Msg->MyQEntry->Active &&
193 !Msg->MyQEntry->StillActive &&
194 CheckQEntryIsBounce(Msg->MyQEntry))
196 /* are we casue for a bounce mail? */
197 Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
200 if ((Msg->nRemain > 0) || Msg->IDestructQueItem)
201 Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
203 Msg->QMsgData = NULL;
206 * Uncompleted delivery instructions remain, so delete the old
207 * instructions and replace with the updated ones.
209 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
210 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
211 Msg->MyQItem->QueMsgID = -1;
213 if (Msg->IDestructQueItem)
214 smtpq_do_bounce(Msg->MyQItem, StatusMessage, Msg->msgtext, Msg->pCurrRelay);
216 if (Msg->nRemain > 0)
218 struct CtdlMessage *msg;
219 msg = malloc(sizeof(struct CtdlMessage));
220 memset(msg, 0, sizeof(struct CtdlMessage));
221 msg->cm_magic = CTDLMESSAGE_MAGIC;
222 msg->cm_anon_type = MES_NORMAL;
223 msg->cm_format_type = FMT_RFC822;
224 msg->cm_fields['M'] = SmashStrBuf(&Msg->QMsgData);
225 msg->cm_fields['U'] = strdup("QMSG");
226 Msg->MyQItem->QueMsgID =
227 CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
228 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
229 CtdlFreeMessage(msg);
232 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM,
233 &Msg->MyQItem->MessageID,
236 FreeStrBuf(&Msg->QMsgData);
239 RemoveContext(Msg->IO.CitContext);
243 eNextState Terminate(AsyncIO *IO)
245 SmtpOutMsg *Msg = IO->Data;
247 if (Msg->IDestructQueItem)
248 RemoveQItem(Msg->MyQItem);
250 DeleteSmtpOutMsg(Msg);
253 eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
255 /* hand over to DB Queue */
256 return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB);
259 eNextState FailOneAttempt(AsyncIO *IO)
261 SmtpOutMsg *Msg = IO->Data;
263 SetSMTPState(IO, eSTMPfailOne);
264 if (Msg->MyQEntry->Status == 2)
268 * possible ways here:
269 * - connection timeout
270 * - dns lookup failed
272 StopClientWatchers(IO, 1);
274 Msg->MyQEntry->nAttempt ++;
275 if (Msg->MyQEntry->AllStatusMessages == NULL)
276 Msg->MyQEntry->AllStatusMessages = NewStrBuf();
278 StrBufAppendPrintf(Msg->MyQEntry->AllStatusMessages, "%ld) ", Msg->MyQEntry->nAttempt);
279 StrBufAppendBuf(Msg->MyQEntry->AllStatusMessages, Msg->MyQEntry->StatusMessage, 0);
280 StrBufAppendBufPlain(Msg->MyQEntry->AllStatusMessages, HKEY("; "), 0);
282 if (Msg->pCurrRelay != NULL)
283 Msg->pCurrRelay = Msg->pCurrRelay->Next;
284 if ((Msg->pCurrRelay != NULL) &&
285 !Msg->pCurrRelay->IsRelay &&
286 Msg->MyQItem->HaveRelay)
288 EVS_syslog(LOG_DEBUG, "%s Aborting; last relay failed.\n", __FUNCTION__);
292 if (Msg->pCurrRelay == NULL) {
293 EVS_syslog(LOG_DEBUG, "%s Aborting\n", __FUNCTION__);
296 if (Msg->pCurrRelay->IsIP) {
297 EVS_syslog(LOG_DEBUG, "%s connecting IP\n", __FUNCTION__);
298 return mx_connect_ip(IO);
301 EVS_syslog(LOG_DEBUG,
302 "%s resolving next MX Record\n",
304 return get_one_mx_host_ip(IO);
309 void SetConnectStatus(AsyncIO *IO)
311 SmtpOutMsg *Msg = IO->Data;
317 if (IO->ConnectMe->IPv6) {
318 src = &IO->ConnectMe->Addr.sin6_addr;
321 struct sockaddr_in *addr;
323 addr = (struct sockaddr_in *)&IO->ConnectMe->Addr;
324 src = &addr->sin_addr.s_addr;
327 inet_ntop((IO->ConnectMe->IPv6)?AF_INET6:AF_INET,
332 if (Msg->mx_host == NULL)
333 Msg->mx_host = "<no MX-Record>";
336 "connecting to %s [%s]:%d ...\n",
339 Msg->IO.ConnectMe->Port);
341 Msg->MyQEntry->Status = 4;
342 StrBufPrintf(Msg->MyQEntry->StatusMessage,
343 "Timeout while connecting %s [%s]:%d ",
346 Msg->IO.ConnectMe->Port);
347 Msg->IO.NextState = eConnect;
350 /*****************************************************************************
351 * So we connect our Relay IP here. *
352 *****************************************************************************/
353 eNextState mx_connect_ip(AsyncIO *IO)
355 SmtpOutMsg *Msg = IO->Data;
356 SetSMTPState(IO, eSTMPconnecting);
358 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
360 IO->ConnectMe = Msg->pCurrRelay;
361 Msg->State = eConnectMX;
363 SetConnectStatus(IO);
365 return EvConnectSock(IO,
367 SMTP_C_ReadTimeouts[0],
371 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
373 SmtpOutMsg *Msg = IO->Data;
374 struct hostent *hostent;
376 IO->ConnectMe = Msg->pCurrRelay;
379 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
381 IO->Now - IO->DNS.Start);
383 hostent = Msg->HostLookup.VParsedDNSReply;
384 if ((Msg->HostLookup.DNSStatus == ARES_SUCCESS) &&
385 (hostent != NULL) ) {
386 memset(&Msg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
387 if (Msg->pCurrRelay->IPv6) {
388 memcpy(&Msg->pCurrRelay->Addr.sin6_addr.s6_addr,
389 &hostent->h_addr_list[0],
390 sizeof(struct in6_addr));
392 Msg->pCurrRelay->Addr.sin6_family =
394 Msg->pCurrRelay->Addr.sin6_port =
395 htons(Msg->IO.ConnectMe->Port);
398 struct sockaddr_in *addr;
400 * Bypass the ns lookup result like this:
401 * IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
402 * addr->sin_addr.s_addr =
403 * htonl((uint32_t)&hostent->h_addr_list[0]);
406 addr = (struct sockaddr_in*) &Msg->pCurrRelay->Addr;
408 memcpy(&addr->sin_addr.s_addr,
409 hostent->h_addr_list[0],
412 addr->sin_family = hostent->h_addrtype;
413 addr->sin_port = htons(Msg->IO.ConnectMe->Port);
415 Msg->mx_host = Msg->pCurrRelay->Host;
416 if (Msg->HostLookup.VParsedDNSReply != NULL) {
417 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
418 Msg->HostLookup.VParsedDNSReply = NULL;
420 return mx_connect_ip(IO);
423 SetSMTPState(IO, eSTMPfailOne);
424 if (Msg->HostLookup.VParsedDNSReply != NULL) {
425 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
426 Msg->HostLookup.VParsedDNSReply = NULL;
428 return FailOneAttempt(IO);
432 eNextState get_one_mx_host_ip(AsyncIO *IO)
434 SmtpOutMsg * Msg = IO->Data;
436 * here we start with the lookup of one host. it might be...
437 * - the relay host *sigh*
438 * - the direct hostname if there was no mx record
441 SetSMTPState(IO, (Msg->pCurrRelay->IPv6)?eSTMPalookup:eSTMPaaaalookup);
443 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
445 EVS_syslog(LOG_DEBUG,
446 "looking up %s-Record %s : %d ...\n",
447 (Msg->pCurrRelay->IPv6)? "aaaa": "a",
448 Msg->pCurrRelay->Host,
449 Msg->pCurrRelay->Port);
451 if (!QueueQuery((Msg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a,
452 Msg->pCurrRelay->Host,
455 get_one_mx_host_ip_done))
457 Msg->MyQEntry->Status = 5;
458 StrBufPrintf(Msg->MyQEntry->StatusMessage,
459 "No MX hosts found for <%s>", Msg->node);
460 Msg->IO.NextState = eTerminateConnection;
461 return IO->NextState;
463 IO->NextState = eReadDNSReply;
464 return IO->NextState;
468 /*****************************************************************************
469 * here we try to find out about the MX records for our recipients. *
470 *****************************************************************************/
471 eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
473 SmtpOutMsg * Msg = IO->Data;
478 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
480 IO->Now - IO->DNS.Start);
483 while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
486 if ((IO->DNS.Query->DNSStatus == ARES_SUCCESS) &&
487 (IO->DNS.Query->VParsedDNSReply != NULL))
488 { /* ok, we found mx records. */
492 = IO->DNS.Query->VParsedDNSReply;
493 while (Msg->CurrMX) {
495 for (i = 0; i < 2; i++) {
498 p = (ParsedURL*) malloc(sizeof(ParsedURL));
499 memset(p, 0, sizeof(ParsedURL));
500 p->Priority = Msg->CurrMX->priority;
502 p->Port = DefaultMXPort;
504 p->Host = Msg->CurrMX->host;
508 ParsedURL *ppp = *pp;
510 while ((ppp->Next != NULL) &&
511 (ppp->Next->Priority <= p->Priority))
514 (ppp->Priority > p->Priority)) {
524 Msg->CurrMX = Msg->CurrMX->next;
526 Msg->CXFlags = Msg->CXFlags & F_HAVE_MX;
528 else { /* else fall back to the plain hostname */
530 for (i = 0; i < 2; i++) {
533 p = (ParsedURL*) malloc(sizeof(ParsedURL));
534 memset(p, 0, sizeof(ParsedURL));
536 p->Port = DefaultMXPort;
543 Msg->CXFlags = Msg->CXFlags & F_DIRECT;
545 if (Msg->MyQItem->FallBackHost != NULL)
547 Msg->MyQItem->FallBackHost->Next = *pp;
548 *pp = Msg->MyQItem->FallBackHost;
550 Msg->pCurrRelay = Msg->Relay;
551 return get_one_mx_host_ip(IO);
554 eNextState resolve_mx_records(AsyncIO *IO)
556 SmtpOutMsg * Msg = IO->Data;
558 SetSMTPState(IO, eSTMPmxlookup);
560 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
561 /* start resolving MX records here. */
562 if (!QueueQuery(ns_t_mx,
566 smtp_resolve_mx_record_done))
568 Msg->MyQEntry->Status = 5;
569 StrBufPrintf(Msg->MyQEntry->StatusMessage,
570 "No MX hosts found for <%s>", Msg->node);
571 return IO->NextState;
573 Msg->IO.NextState = eReadDNSReply;
574 return IO->NextState;
579 /******************************************************************************
580 * so, we're going to start a SMTP delivery. lets get it on. *
581 ******************************************************************************/
583 SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem,
584 MailQEntry *MyQEntry,
589 Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
592 memset(Msg, 0, sizeof(SmtpOutMsg));
595 Msg->MyQEntry = MyQEntry;
596 Msg->MyQItem = MyQItem;
597 Msg->pCurrRelay = MyQItem->URL;
599 InitIOStruct(&Msg->IO,
602 SMTP_C_ReadServerStatus,
604 SMTP_C_DispatchWriteDone,
605 SMTP_C_DispatchReadDone,
612 Msg->IO.ErrMsg = Msg->MyQEntry->StatusMessage;
617 void smtp_try_one_queue_entry(OneQueItem *MyQItem,
618 MailQEntry *MyQEntry,
620 /*KeepMsgText allows us to use MsgText as ours.*/
626 SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
628 Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
630 SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__);
632 FreeStrBuf (&MsgText);
635 if (KeepMsgText) Msg->msgtext = MsgText;
636 else Msg->msgtext = NewStrBufDup(MsgText);
638 if (smtp_resolve_recipients(Msg) &&
639 (!MyQItem->HaveRelay ||
640 (MyQItem->URL != NULL)))
643 ((CitContext *)Msg->IO.CitContext)->cs_host,
645 sizeof(((CitContext *)
646 Msg->IO.CitContext)->cs_host));
648 SMTPC_syslog(LOG_DEBUG, "Starting: [%ld] <%s> CC <%d> \n",
649 Msg->MyQItem->MessageID,
650 ChrPtr(Msg->MyQEntry->Recipient),
651 ((CitContext*)Msg->IO.CitContext)->cs_pid);
652 if (Msg->pCurrRelay == NULL) {
653 SetSMTPState(&Msg->IO, eSTMPmxlookup);
654 QueueEventContext(&Msg->IO,
657 else { /* oh... via relay host */
658 if (Msg->pCurrRelay->IsIP) {
659 SetSMTPState(&Msg->IO, eSTMPconnecting);
660 QueueEventContext(&Msg->IO,
664 SetSMTPState(&Msg->IO, eSTMPalookup);
665 /* uneducated admin has chosen to
666 add DNS to the equation... */
667 QueueEventContext(&Msg->IO,
673 SetSMTPState(&Msg->IO, eSMTPFailTotal);
674 /* No recipients? well fail then. */
675 if (Msg->MyQEntry != NULL) {
676 Msg->MyQEntry->Status = 5;
677 if (StrLength(Msg->MyQEntry->StatusMessage) == 0)
678 StrBufPlain(Msg->MyQEntry->StatusMessage,
679 HKEY("Invalid Recipient!"));
681 FinalizeMessageSend_DB(&Msg->IO);
682 DeleteSmtpOutMsg(Msg);
691 /*****************************************************************************/
692 /* SMTP CLIENT DISPATCHER */
693 /*****************************************************************************/
695 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *Msg)
697 double Timeout = 0.0;
698 AsyncIO *IO = &Msg->IO;
700 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
702 switch (NextTCPState) {
706 Timeout = SMTP_C_SendTimeouts[Msg->State];
707 if (Msg->State == eDATABody) {
708 /* if we're sending a huge message,
711 Timeout += StrLength(Msg->msgtext) / 512;
715 Timeout = SMTP_C_ReadTimeouts[Msg->State];
716 if (Msg->State == eDATATerminateBody) {
718 * some mailservers take a nap before accepting
719 * the message content inspection and such.
721 Timeout += StrLength(Msg->msgtext) / 512;
731 case eTerminateConnection:
735 SetNextTimeout(&Msg->IO, Timeout);
737 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO)
739 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
740 SmtpOutMsg *Msg = IO->Data;
743 rc = ReadHandlers[Msg->State](Msg);
747 SMTPSetTimeout(rc, Msg);
751 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO)
753 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
754 SmtpOutMsg *Msg = IO->Data;
757 rc = SendHandlers[Msg->State](Msg);
758 SMTPSetTimeout(rc, Msg);
763 /*****************************************************************************/
764 /* SMTP CLIENT ERROR CATCHERS */
765 /*****************************************************************************/
766 eNextState SMTP_C_Terminate(AsyncIO *IO)
768 SmtpOutMsg *Msg = IO->Data;
770 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
771 return FinalizeMessageSend(Msg);
773 eNextState SMTP_C_TerminateDB(AsyncIO *IO)
775 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
776 return Terminate(IO);
778 eNextState SMTP_C_Timeout(AsyncIO *IO)
780 SmtpOutMsg *Msg = IO->Data;
782 Msg->MyQEntry->Status = 4;
783 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
784 StrBufPrintf(IO->ErrMsg, "Timeout: %s while talking to %s",
785 ReadErrors[Msg->State].Key,
787 if (Msg->State > eRCPT)
790 return FailOneAttempt(IO);
792 eNextState SMTP_C_ConnFail(AsyncIO *IO)
794 SmtpOutMsg *Msg = IO->Data;
796 Msg->MyQEntry->Status = 4;
797 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
798 StrBufPrintf(IO->ErrMsg, "Connection failure: %s while talking to %s",
799 ReadErrors[Msg->State].Key,
802 return FailOneAttempt(IO);
804 eNextState SMTP_C_DNSFail(AsyncIO *IO)
806 SmtpOutMsg *Msg = IO->Data;
807 Msg->MyQEntry->Status = 4;
808 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
809 return FailOneAttempt(IO);
811 eNextState SMTP_C_Shutdown(AsyncIO *IO)
813 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
814 SmtpOutMsg *Msg = IO->Data;
816 switch (IO->NextState) {
820 /* todo: abort c-ares */
829 StopClientWatchers(IO, 1);
834 case eTerminateConnection:
838 Msg->MyQEntry->Status = 3;
839 StrBufPlain(Msg->MyQEntry->StatusMessage,
840 HKEY("server shutdown during message submit."));
841 return FinalizeMessageSend(Msg);
846 * @brief lineread Handler;
847 * understands when to read more SMTP lines, and when this is a one-lined reply.
849 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
851 eReadState Finished = eBufferNotEmpty;
853 while (Finished == eBufferNotEmpty) {
854 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
857 case eMustReadMore: /// read new from socket...
860 case eBufferNotEmpty: /* shouldn't happen... */
861 case eReadSuccess: /// done for now...
862 if (StrLength(IO->IOBuf) < 4)
864 if (ChrPtr(IO->IOBuf)[3] == '-')
865 Finished = eBufferNotEmpty;
869 case eReadFail: /// WHUT?
877 void LogDebugEnableSMTPClient(const int n)
879 SMTPClientDebugEnabled = n;
882 CTDL_MODULE_INIT(smtp_eventclient)
885 CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient, &SMTPClientDebugEnabled);
886 return "smtpeventclient";