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;
112 memcpy(CCC->cs_clientname, SMTPStates[State].Key, SMTPStates[State].len + 1);
115 int SMTPClientDebugEnabled = 0;
116 void DeleteSmtpOutMsg(void *v)
119 AsyncIO *IO = &Msg->IO;
120 EV_syslog(LOG_DEBUG, "%s Exit\n", __FUNCTION__);
122 /* these are kept in our own space and free'd below */
123 Msg->IO.ConnectMe = NULL;
125 ares_free_data(Msg->AllMX);
126 if (Msg->HostLookup.VParsedDNSReply != NULL)
127 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
128 FreeURL(&Msg->Relay);
129 FreeStrBuf(&Msg->msgtext);
130 FreeAsyncIOContents(&Msg->IO);
131 memset (Msg, 0, sizeof(SmtpOutMsg)); /* just to be shure... */
135 eNextState SMTP_C_Shutdown(AsyncIO *IO);
136 eNextState SMTP_C_Timeout(AsyncIO *IO);
137 eNextState SMTP_C_ConnFail(AsyncIO *IO);
138 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO);
139 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO);
140 eNextState SMTP_C_DNSFail(AsyncIO *IO);
141 eNextState SMTP_C_Terminate(AsyncIO *IO);
142 eNextState SMTP_C_TerminateDB(AsyncIO *IO);
143 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO);
145 eNextState mx_connect_ip(AsyncIO *IO);
146 eNextState get_one_mx_host_ip(AsyncIO *IO);
148 /******************************************************************************
149 * So, we're finished with sending (regardless of success or failure) *
150 * This Message might be referenced by several Queue-Items, if we're the last,*
151 * we need to free the memory and send bounce messages (on terminal failure) *
152 * else we just free our SMTP-Message struct. *
153 ******************************************************************************/
154 eNextState FinalizeMessageSend_DB(AsyncIO *IO)
157 SmtpOutMsg *Msg = IO->Data;
158 StrBuf *StatusMessage;
160 if (Msg->MyQEntry->AllStatusMessages != NULL)
161 StatusMessage = Msg->MyQEntry->AllStatusMessages;
163 StatusMessage = Msg->MyQEntry->StatusMessage;
166 if (Msg->MyQEntry->Status == 2) {
167 SetSMTPState(IO, eSTMPfinished);
168 Status = "Delivery successful.";
170 else if (Msg->MyQEntry->Status == 5) {
171 SetSMTPState(IO, eSMTPFailTotal);
172 Status = "Delivery failed permanently; giving up.";
175 SetSMTPState(IO, eSMTPFailTemporary);
176 Status = "Delivery failed temporarily; will retry later.";
180 "%s Time[%fs] Recipient <%s> @ <%s> (%s) Status message: %s\n",
182 Msg->IO.Now - Msg->IO.StartIO,
186 ChrPtr(StatusMessage));
189 Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
191 Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem, 0);
193 if (Msg->MyQEntry->Active &&
194 !Msg->MyQEntry->StillActive &&
195 CheckQEntryIsBounce(Msg->MyQEntry))
197 /* are we casue for a bounce mail? */
198 Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
201 if ((Msg->nRemain > 0) || Msg->IDestructQueItem)
202 Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
204 Msg->QMsgData = NULL;
207 * Uncompleted delivery instructions remain, so delete the old
208 * instructions and replace with the updated ones.
210 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
211 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
212 Msg->MyQItem->QueMsgID = -1;
214 if (Msg->IDestructQueItem)
215 smtpq_do_bounce(Msg->MyQItem, StatusMessage, Msg->msgtext, Msg->pCurrRelay);
217 if (Msg->nRemain > 0)
219 struct CtdlMessage *msg;
220 msg = malloc(sizeof(struct CtdlMessage));
221 memset(msg, 0, sizeof(struct CtdlMessage));
222 msg->cm_magic = CTDLMESSAGE_MAGIC;
223 msg->cm_anon_type = MES_NORMAL;
224 msg->cm_format_type = FMT_RFC822;
225 msg->cm_fields['M'] = SmashStrBuf(&Msg->QMsgData);
226 msg->cm_fields['U'] = strdup("QMSG");
227 Msg->MyQItem->QueMsgID =
228 CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
229 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
230 CtdlFreeMessage(msg);
233 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM,
234 &Msg->MyQItem->MessageID,
237 FreeStrBuf(&Msg->QMsgData);
240 RemoveContext(Msg->IO.CitContext);
244 eNextState Terminate(AsyncIO *IO)
246 SmtpOutMsg *Msg = IO->Data;
248 if (Msg->IDestructQueItem)
249 RemoveQItem(Msg->MyQItem);
251 DeleteSmtpOutMsg(Msg);
254 eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
256 /* hand over to DB Queue */
257 return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB);
260 eNextState FailOneAttempt(AsyncIO *IO)
262 SmtpOutMsg *Msg = IO->Data;
264 SetSMTPState(IO, eSTMPfailOne);
265 if (Msg->MyQEntry->Status == 2)
269 * possible ways here:
270 * - connection timeout
271 * - dns lookup failed
273 StopClientWatchers(IO, 1);
275 Msg->MyQEntry->nAttempt ++;
276 if (Msg->MyQEntry->AllStatusMessages == NULL)
277 Msg->MyQEntry->AllStatusMessages = NewStrBuf();
279 StrBufAppendPrintf(Msg->MyQEntry->AllStatusMessages, "%ld) ", Msg->MyQEntry->nAttempt);
280 StrBufAppendBuf(Msg->MyQEntry->AllStatusMessages, Msg->MyQEntry->StatusMessage, 0);
281 StrBufAppendBufPlain(Msg->MyQEntry->AllStatusMessages, HKEY("; "), 0);
283 if (Msg->pCurrRelay != NULL)
284 Msg->pCurrRelay = Msg->pCurrRelay->Next;
285 if ((Msg->pCurrRelay != NULL) &&
286 !Msg->pCurrRelay->IsRelay &&
287 Msg->MyQItem->HaveRelay)
289 EVS_syslog(LOG_DEBUG, "%s Aborting; last relay failed.\n", __FUNCTION__);
293 if (Msg->pCurrRelay == NULL) {
294 EVS_syslog(LOG_DEBUG, "%s Aborting\n", __FUNCTION__);
297 if (Msg->pCurrRelay->IsIP) {
298 EVS_syslog(LOG_DEBUG, "%s connecting IP\n", __FUNCTION__);
299 return mx_connect_ip(IO);
302 EVS_syslog(LOG_DEBUG,
303 "%s resolving next MX Record\n",
305 return get_one_mx_host_ip(IO);
310 void SetConnectStatus(AsyncIO *IO)
312 SmtpOutMsg *Msg = IO->Data;
318 if (IO->ConnectMe->IPv6) {
319 src = &IO->ConnectMe->Addr.sin6_addr;
322 struct sockaddr_in *addr;
324 addr = (struct sockaddr_in *)&IO->ConnectMe->Addr;
325 src = &addr->sin_addr.s_addr;
328 inet_ntop((IO->ConnectMe->IPv6)?AF_INET6:AF_INET,
333 if (Msg->mx_host == NULL)
334 Msg->mx_host = "<no MX-Record>";
337 "connecting to %s [%s]:%d ...\n",
340 Msg->IO.ConnectMe->Port);
342 Msg->MyQEntry->Status = 4;
343 StrBufPrintf(Msg->MyQEntry->StatusMessage,
344 "Timeout while connecting %s [%s]:%d ",
347 Msg->IO.ConnectMe->Port);
348 Msg->IO.NextState = eConnect;
351 /*****************************************************************************
352 * So we connect our Relay IP here. *
353 *****************************************************************************/
354 eNextState mx_connect_ip(AsyncIO *IO)
356 SmtpOutMsg *Msg = IO->Data;
357 SetSMTPState(IO, eSTMPconnecting);
359 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
361 IO->ConnectMe = Msg->pCurrRelay;
362 Msg->State = eConnectMX;
364 SetConnectStatus(IO);
366 return EvConnectSock(IO,
368 SMTP_C_ReadTimeouts[0],
372 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
374 SmtpOutMsg *Msg = IO->Data;
375 struct hostent *hostent;
377 IO->ConnectMe = Msg->pCurrRelay;
380 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
382 IO->Now - IO->DNS.Start);
384 hostent = Msg->HostLookup.VParsedDNSReply;
385 if ((Msg->HostLookup.DNSStatus == ARES_SUCCESS) &&
386 (hostent != NULL) ) {
387 memset(&Msg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
388 if (Msg->pCurrRelay->IPv6) {
389 memcpy(&Msg->pCurrRelay->Addr.sin6_addr.s6_addr,
390 &hostent->h_addr_list[0],
391 sizeof(struct in6_addr));
393 Msg->pCurrRelay->Addr.sin6_family =
395 Msg->pCurrRelay->Addr.sin6_port =
396 htons(Msg->IO.ConnectMe->Port);
399 struct sockaddr_in *addr;
401 * Bypass the ns lookup result like this:
402 * IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
403 * addr->sin_addr.s_addr =
404 * htonl((uint32_t)&hostent->h_addr_list[0]);
407 addr = (struct sockaddr_in*) &Msg->pCurrRelay->Addr;
409 memcpy(&addr->sin_addr.s_addr,
410 hostent->h_addr_list[0],
413 addr->sin_family = hostent->h_addrtype;
414 addr->sin_port = htons(Msg->IO.ConnectMe->Port);
416 Msg->mx_host = Msg->pCurrRelay->Host;
417 if (Msg->HostLookup.VParsedDNSReply != NULL) {
418 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
419 Msg->HostLookup.VParsedDNSReply = NULL;
421 return mx_connect_ip(IO);
424 SetSMTPState(IO, eSTMPfailOne);
425 if (Msg->HostLookup.VParsedDNSReply != NULL) {
426 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
427 Msg->HostLookup.VParsedDNSReply = NULL;
429 return FailOneAttempt(IO);
433 eNextState get_one_mx_host_ip(AsyncIO *IO)
435 SmtpOutMsg * Msg = IO->Data;
437 * here we start with the lookup of one host. it might be...
438 * - the relay host *sigh*
439 * - the direct hostname if there was no mx record
442 SetSMTPState(IO, (Msg->pCurrRelay->IPv6)?eSTMPalookup:eSTMPaaaalookup);
444 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
446 EVS_syslog(LOG_DEBUG,
447 "looking up %s-Record %s : %d ...\n",
448 (Msg->pCurrRelay->IPv6)? "aaaa": "a",
449 Msg->pCurrRelay->Host,
450 Msg->pCurrRelay->Port);
452 if (!QueueQuery((Msg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a,
453 Msg->pCurrRelay->Host,
456 get_one_mx_host_ip_done))
458 Msg->MyQEntry->Status = 5;
459 StrBufPrintf(Msg->MyQEntry->StatusMessage,
460 "No MX hosts found for <%s>", Msg->node);
461 Msg->IO.NextState = eTerminateConnection;
462 return IO->NextState;
464 IO->NextState = eReadDNSReply;
465 return IO->NextState;
469 /*****************************************************************************
470 * here we try to find out about the MX records for our recipients. *
471 *****************************************************************************/
472 eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
474 SmtpOutMsg * Msg = IO->Data;
479 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
481 IO->Now - IO->DNS.Start);
484 while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
487 if ((IO->DNS.Query->DNSStatus == ARES_SUCCESS) &&
488 (IO->DNS.Query->VParsedDNSReply != NULL))
489 { /* ok, we found mx records. */
493 = IO->DNS.Query->VParsedDNSReply;
494 while (Msg->CurrMX) {
496 for (i = 0; i < 2; i++) {
499 p = (ParsedURL*) malloc(sizeof(ParsedURL));
500 memset(p, 0, sizeof(ParsedURL));
501 p->Priority = Msg->CurrMX->priority;
503 p->Port = DefaultMXPort;
505 p->Host = Msg->CurrMX->host;
509 ParsedURL *ppp = *pp;
511 while ((ppp->Next != NULL) &&
512 (ppp->Next->Priority <= p->Priority))
515 (ppp->Priority > p->Priority)) {
525 Msg->CurrMX = Msg->CurrMX->next;
527 Msg->CXFlags = Msg->CXFlags & F_HAVE_MX;
529 else { /* else fall back to the plain hostname */
531 for (i = 0; i < 2; i++) {
534 p = (ParsedURL*) malloc(sizeof(ParsedURL));
535 memset(p, 0, sizeof(ParsedURL));
537 p->Port = DefaultMXPort;
544 Msg->CXFlags = Msg->CXFlags & F_DIRECT;
546 if (Msg->MyQItem->FallBackHost != NULL)
548 Msg->MyQItem->FallBackHost->Next = *pp;
549 *pp = Msg->MyQItem->FallBackHost;
551 Msg->pCurrRelay = Msg->Relay;
552 return get_one_mx_host_ip(IO);
555 eNextState resolve_mx_records(AsyncIO *IO)
557 SmtpOutMsg * Msg = IO->Data;
559 SetSMTPState(IO, eSTMPmxlookup);
561 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
562 /* start resolving MX records here. */
563 if (!QueueQuery(ns_t_mx,
567 smtp_resolve_mx_record_done))
569 Msg->MyQEntry->Status = 5;
570 StrBufPrintf(Msg->MyQEntry->StatusMessage,
571 "No MX hosts found for <%s>", Msg->node);
572 return IO->NextState;
574 Msg->IO.NextState = eReadDNSReply;
575 return IO->NextState;
580 /******************************************************************************
581 * so, we're going to start a SMTP delivery. lets get it on. *
582 ******************************************************************************/
584 SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem,
585 MailQEntry *MyQEntry,
590 Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
593 memset(Msg, 0, sizeof(SmtpOutMsg));
596 Msg->MyQEntry = MyQEntry;
597 Msg->MyQItem = MyQItem;
598 Msg->pCurrRelay = MyQItem->URL;
600 InitIOStruct(&Msg->IO,
603 SMTP_C_ReadServerStatus,
605 SMTP_C_DispatchWriteDone,
606 SMTP_C_DispatchReadDone,
613 Msg->IO.ErrMsg = Msg->MyQEntry->StatusMessage;
618 void smtp_try_one_queue_entry(OneQueItem *MyQItem,
619 MailQEntry *MyQEntry,
621 /*KeepMsgText allows us to use MsgText as ours.*/
627 SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
629 Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
631 SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__);
633 FreeStrBuf (&MsgText);
636 if (KeepMsgText) Msg->msgtext = MsgText;
637 else Msg->msgtext = NewStrBufDup(MsgText);
639 if (smtp_resolve_recipients(Msg) &&
640 (!MyQItem->HaveRelay ||
641 (MyQItem->URL != NULL)))
644 ((CitContext *)Msg->IO.CitContext)->cs_host,
646 sizeof(((CitContext *)
647 Msg->IO.CitContext)->cs_host));
649 SMTPC_syslog(LOG_DEBUG, "Starting: [%ld] <%s> CC <%d> \n",
650 Msg->MyQItem->MessageID,
651 ChrPtr(Msg->MyQEntry->Recipient),
652 ((CitContext*)Msg->IO.CitContext)->cs_pid);
653 if (Msg->pCurrRelay == NULL) {
654 SetSMTPState(&Msg->IO, eSTMPmxlookup);
655 QueueEventContext(&Msg->IO,
658 else { /* oh... via relay host */
659 if (Msg->pCurrRelay->IsIP) {
660 SetSMTPState(&Msg->IO, eSTMPconnecting);
661 QueueEventContext(&Msg->IO,
665 SetSMTPState(&Msg->IO, eSTMPalookup);
666 /* uneducated admin has chosen to
667 add DNS to the equation... */
668 QueueEventContext(&Msg->IO,
674 SetSMTPState(&Msg->IO, eSMTPFailTotal);
675 /* No recipients? well fail then. */
676 if (Msg->MyQEntry != NULL) {
677 Msg->MyQEntry->Status = 5;
678 if (StrLength(Msg->MyQEntry->StatusMessage) == 0)
679 StrBufPlain(Msg->MyQEntry->StatusMessage,
680 HKEY("Invalid Recipient!"));
682 FinalizeMessageSend_DB(&Msg->IO);
683 DeleteSmtpOutMsg(Msg);
692 /*****************************************************************************/
693 /* SMTP CLIENT DISPATCHER */
694 /*****************************************************************************/
696 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *Msg)
698 double Timeout = 0.0;
699 AsyncIO *IO = &Msg->IO;
701 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
703 switch (NextTCPState) {
707 Timeout = SMTP_C_SendTimeouts[Msg->State];
708 if (Msg->State == eDATABody) {
709 /* if we're sending a huge message,
712 Timeout += StrLength(Msg->msgtext) / 512;
716 Timeout = SMTP_C_ReadTimeouts[Msg->State];
717 if (Msg->State == eDATATerminateBody) {
719 * some mailservers take a nap before accepting
720 * the message content inspection and such.
722 Timeout += StrLength(Msg->msgtext) / 512;
732 case eTerminateConnection:
736 SetNextTimeout(&Msg->IO, Timeout);
738 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO)
740 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
741 SmtpOutMsg *Msg = IO->Data;
744 rc = ReadHandlers[Msg->State](Msg);
748 SMTPSetTimeout(rc, Msg);
752 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO)
754 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
755 SmtpOutMsg *Msg = IO->Data;
758 rc = SendHandlers[Msg->State](Msg);
759 SMTPSetTimeout(rc, Msg);
764 /*****************************************************************************/
765 /* SMTP CLIENT ERROR CATCHERS */
766 /*****************************************************************************/
767 eNextState SMTP_C_Terminate(AsyncIO *IO)
769 SmtpOutMsg *Msg = IO->Data;
771 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
772 return FinalizeMessageSend(Msg);
774 eNextState SMTP_C_TerminateDB(AsyncIO *IO)
776 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
777 return Terminate(IO);
779 eNextState SMTP_C_Timeout(AsyncIO *IO)
781 SmtpOutMsg *Msg = IO->Data;
783 Msg->MyQEntry->Status = 4;
784 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
785 StrBufPrintf(IO->ErrMsg, "Timeout: %s while talking to %s",
786 ReadErrors[Msg->State].Key,
788 if (Msg->State > eRCPT)
791 return FailOneAttempt(IO);
793 eNextState SMTP_C_ConnFail(AsyncIO *IO)
795 SmtpOutMsg *Msg = IO->Data;
797 Msg->MyQEntry->Status = 4;
798 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
799 StrBufPrintf(IO->ErrMsg, "Connection failure: %s while talking to %s",
800 ReadErrors[Msg->State].Key,
803 return FailOneAttempt(IO);
805 eNextState SMTP_C_DNSFail(AsyncIO *IO)
807 SmtpOutMsg *Msg = IO->Data;
808 Msg->MyQEntry->Status = 4;
809 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
810 return FailOneAttempt(IO);
812 eNextState SMTP_C_Shutdown(AsyncIO *IO)
814 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
815 SmtpOutMsg *Msg = IO->Data;
817 switch (IO->NextState) {
821 /* todo: abort c-ares */
830 StopClientWatchers(IO, 1);
835 case eTerminateConnection:
839 Msg->MyQEntry->Status = 3;
840 StrBufPlain(Msg->MyQEntry->StatusMessage,
841 HKEY("server shutdown during message submit."));
842 return FinalizeMessageSend(Msg);
847 * @brief lineread Handler;
848 * understands when to read more SMTP lines, and when this is a one-lined reply.
850 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
852 eReadState Finished = eBufferNotEmpty;
854 while (Finished == eBufferNotEmpty) {
855 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
858 case eMustReadMore: /// read new from socket...
861 case eBufferNotEmpty: /* shouldn't happen... */
862 case eReadSuccess: /// done for now...
863 if (StrLength(IO->IOBuf) < 4)
865 if (ChrPtr(IO->IOBuf)[3] == '-')
866 Finished = eBufferNotEmpty;
870 case eReadFail: /// WHUT?
878 void LogDebugEnableSMTPClient(const int n)
880 SMTPClientDebugEnabled = n;
883 CTDL_MODULE_INIT(smtp_eventclient)
886 CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient, &SMTPClientDebugEnabled);
887 return "smtpeventclient";