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 FreeStrBuf(&Msg->MultiLineBuf);
131 FreeAsyncIOContents(&Msg->IO);
132 memset (Msg, 0, sizeof(SmtpOutMsg)); /* just to be shure... */
136 eNextState SMTP_C_Shutdown(AsyncIO *IO);
137 eNextState SMTP_C_Timeout(AsyncIO *IO);
138 eNextState SMTP_C_ConnFail(AsyncIO *IO);
139 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO);
140 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO);
141 eNextState SMTP_C_DNSFail(AsyncIO *IO);
142 eNextState SMTP_C_Terminate(AsyncIO *IO);
143 eNextState SMTP_C_TerminateDB(AsyncIO *IO);
144 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO);
146 eNextState mx_connect_ip(AsyncIO *IO);
147 eNextState get_one_mx_host_ip(AsyncIO *IO);
149 /******************************************************************************
150 * So, we're finished with sending (regardless of success or failure) *
151 * This Message might be referenced by several Queue-Items, if we're the last,*
152 * we need to free the memory and send bounce messages (on terminal failure) *
153 * else we just free our SMTP-Message struct. *
154 ******************************************************************************/
155 eNextState FinalizeMessageSend_DB(AsyncIO *IO)
158 SmtpOutMsg *Msg = IO->Data;
159 StrBuf *StatusMessage;
161 if (Msg->MyQEntry->AllStatusMessages != NULL)
162 StatusMessage = Msg->MyQEntry->AllStatusMessages;
164 StatusMessage = Msg->MyQEntry->StatusMessage;
167 if (Msg->MyQEntry->Status == 2) {
168 SetSMTPState(IO, eSTMPfinished);
169 Status = "Delivery successful.";
171 else if (Msg->MyQEntry->Status == 5) {
172 SetSMTPState(IO, eSMTPFailTotal);
173 Status = "Delivery failed permanently; giving up.";
176 SetSMTPState(IO, eSMTPFailTemporary);
177 Status = "Delivery failed temporarily; will retry later.";
181 "%s Time[%fs] Recipient <%s> @ <%s> (%s) Status message: %s\n",
183 Msg->IO.Now - Msg->IO.StartIO,
187 ChrPtr(StatusMessage));
190 Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
192 Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem, 0);
194 if (Msg->MyQEntry->Active &&
195 !Msg->MyQEntry->StillActive &&
196 CheckQEntryIsBounce(Msg->MyQEntry))
198 /* are we casue for a bounce mail? */
199 Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
202 if ((Msg->nRemain > 0) || Msg->IDestructQueItem)
203 Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
205 Msg->QMsgData = NULL;
208 * Uncompleted delivery instructions remain, so delete the old
209 * instructions and replace with the updated ones.
211 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
212 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
213 Msg->MyQItem->QueMsgID = -1;
215 if (Msg->IDestructQueItem)
216 smtpq_do_bounce(Msg->MyQItem, Msg->msgtext, Msg->pCurrRelay);
218 if (Msg->nRemain > 0)
220 struct CtdlMessage *msg;
221 msg = malloc(sizeof(struct CtdlMessage));
222 memset(msg, 0, sizeof(struct CtdlMessage));
223 msg->cm_magic = CTDLMESSAGE_MAGIC;
224 msg->cm_anon_type = MES_NORMAL;
225 msg->cm_format_type = FMT_RFC822;
226 CM_SetAsFieldSB(msg, eMesageText, &Msg->QMsgData);
227 CM_SetField(msg, eMsgSubject, HKEY("QMSG"));
228 Msg->MyQItem->QueMsgID =
229 CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
230 EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
234 CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM,
235 &Msg->MyQItem->MessageID,
238 FreeStrBuf(&Msg->QMsgData);
241 RemoveContext(Msg->IO.CitContext);
245 eNextState Terminate(AsyncIO *IO)
247 SmtpOutMsg *Msg = IO->Data;
249 if (Msg->IDestructQueItem)
250 RemoveQItem(Msg->MyQItem);
252 DeleteSmtpOutMsg(Msg);
255 eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
257 /* hand over to DB Queue */
258 return EventQueueDBOperation(&Msg->IO, FinalizeMessageSend_DB, 0);
261 eNextState FailOneAttempt(AsyncIO *IO)
263 SmtpOutMsg *Msg = IO->Data;
265 SetSMTPState(IO, eSTMPfailOne);
266 if (Msg->MyQEntry->Status == 2)
270 * possible ways here:
271 * - connection timeout
272 * - dns lookup failed
274 StopClientWatchers(IO, 1);
276 Msg->MyQEntry->nAttempt ++;
277 if (Msg->MyQEntry->AllStatusMessages == NULL)
278 Msg->MyQEntry->AllStatusMessages = NewStrBuf();
280 StrBufAppendPrintf(Msg->MyQEntry->AllStatusMessages, "%ld) ", Msg->MyQEntry->nAttempt);
281 StrBufAppendBuf(Msg->MyQEntry->AllStatusMessages, Msg->MyQEntry->StatusMessage, 0);
282 StrBufAppendBufPlain(Msg->MyQEntry->AllStatusMessages, HKEY("; "), 0);
284 if (Msg->pCurrRelay != NULL)
285 Msg->pCurrRelay = Msg->pCurrRelay->Next;
286 if ((Msg->pCurrRelay != NULL) &&
287 !Msg->pCurrRelay->IsRelay &&
288 Msg->MyQItem->HaveRelay)
290 EVS_syslog(LOG_DEBUG, "%s Aborting; last relay failed.\n", __FUNCTION__);
291 return FinalizeMessageSend(Msg);
294 if (Msg->pCurrRelay == NULL) {
295 EVS_syslog(LOG_DEBUG, "%s Aborting\n", __FUNCTION__);
296 return FinalizeMessageSend(Msg);
298 if (Msg->pCurrRelay->IsIP) {
299 EVS_syslog(LOG_DEBUG, "%s connecting IP\n", __FUNCTION__);
300 return mx_connect_ip(IO);
303 EVS_syslog(LOG_DEBUG,
304 "%s resolving next MX Record\n",
306 return get_one_mx_host_ip(IO);
311 void SetConnectStatus(AsyncIO *IO)
313 SmtpOutMsg *Msg = IO->Data;
319 if (IO->ConnectMe->IPv6) {
320 src = &IO->ConnectMe->Addr.sin6_addr;
323 struct sockaddr_in *addr;
325 addr = (struct sockaddr_in *)&IO->ConnectMe->Addr;
326 src = &addr->sin_addr.s_addr;
329 inet_ntop((IO->ConnectMe->IPv6)?AF_INET6:AF_INET,
334 if (Msg->mx_host == NULL)
335 Msg->mx_host = "<no MX-Record>";
338 "connecting to %s [%s]:%d ...\n",
341 Msg->IO.ConnectMe->Port);
343 Msg->MyQEntry->Status = 4;
344 StrBufPrintf(Msg->MyQEntry->StatusMessage,
345 "Timeout while connecting %s [%s]:%d ",
348 Msg->IO.ConnectMe->Port);
349 Msg->IO.NextState = eConnect;
352 /*****************************************************************************
353 * So we connect our Relay IP here. *
354 *****************************************************************************/
355 eNextState mx_connect_ip(AsyncIO *IO)
357 SmtpOutMsg *Msg = IO->Data;
358 SetSMTPState(IO, eSTMPconnecting);
360 EVS_syslog(LOG_DEBUG, "%s(%s)\n", __FUNCTION__, (Msg->IsRelay)? "Relay":"Remote");
362 IO->ConnectMe = Msg->pCurrRelay;
363 Msg->State = eConnectMX;
365 SetConnectStatus(IO);
367 return EvConnectSock(IO,
369 SMTP_C_ReadTimeouts[0],
373 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
375 SmtpOutMsg *Msg = IO->Data;
376 struct hostent *hostent;
378 IO->ConnectMe = Msg->pCurrRelay;
381 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
383 IO->Now - IO->DNS.Start);
385 hostent = Msg->HostLookup.VParsedDNSReply;
386 if ((Msg->HostLookup.DNSStatus == ARES_SUCCESS) &&
387 (hostent != NULL) ) {
388 memset(&Msg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
389 if (Msg->pCurrRelay->IPv6) {
390 memcpy(&Msg->pCurrRelay->Addr.sin6_addr.s6_addr,
391 &hostent->h_addr_list[0],
392 sizeof(struct in6_addr));
394 Msg->pCurrRelay->Addr.sin6_family =
396 Msg->pCurrRelay->Addr.sin6_port =
397 htons(Msg->IO.ConnectMe->Port);
400 struct sockaddr_in *addr;
402 * Bypass the ns lookup result like this:
403 * IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
404 * addr->sin_addr.s_addr =
405 * htonl((uint32_t)&hostent->h_addr_list[0]);
408 addr = (struct sockaddr_in*) &Msg->pCurrRelay->Addr;
410 memcpy(&addr->sin_addr.s_addr,
411 hostent->h_addr_list[0],
414 addr->sin_family = hostent->h_addrtype;
415 addr->sin_port = htons(Msg->IO.ConnectMe->Port);
417 Msg->mx_host = Msg->pCurrRelay->Host;
418 if (Msg->HostLookup.VParsedDNSReply != NULL) {
419 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
420 Msg->HostLookup.VParsedDNSReply = NULL;
422 return mx_connect_ip(IO);
425 SetSMTPState(IO, eSTMPfailOne);
426 if (Msg->HostLookup.VParsedDNSReply != NULL) {
427 Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
428 Msg->HostLookup.VParsedDNSReply = NULL;
430 return FailOneAttempt(IO);
434 eNextState get_one_mx_host_ip(AsyncIO *IO)
436 SmtpOutMsg * Msg = IO->Data;
438 * here we start with the lookup of one host. it might be...
439 * - the relay host *sigh*
440 * - the direct hostname if there was no mx record
443 SetSMTPState(IO, (Msg->pCurrRelay->IPv6)?eSTMPalookup:eSTMPaaaalookup);
445 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
447 EVS_syslog(LOG_DEBUG,
448 "looking up %s-Record %s : %d ...\n",
449 (Msg->pCurrRelay->IPv6)? "aaaa": "a",
450 Msg->pCurrRelay->Host,
451 Msg->pCurrRelay->Port);
453 if (!QueueQuery((Msg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a,
454 Msg->pCurrRelay->Host,
457 get_one_mx_host_ip_done))
459 Msg->MyQEntry->Status = 5;
460 StrBufPrintf(Msg->MyQEntry->StatusMessage,
461 "No MX hosts found for <%s>", Msg->node);
462 Msg->IO.NextState = eTerminateConnection;
463 return IO->NextState;
465 IO->NextState = eReadDNSReply;
466 return IO->NextState;
470 /*****************************************************************************
471 * here we try to find out about the MX records for our recipients. *
472 *****************************************************************************/
473 eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
475 SmtpOutMsg * Msg = IO->Data;
480 EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
482 IO->Now - IO->DNS.Start);
485 while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
488 if ((IO->DNS.Query->DNSStatus == ARES_SUCCESS) &&
489 (IO->DNS.Query->VParsedDNSReply != NULL))
490 { /* ok, we found mx records. */
494 = IO->DNS.Query->VParsedDNSReply;
495 while (Msg->CurrMX) {
497 for (i = 0; i < 2; i++) {
500 p = (ParsedURL*) malloc(sizeof(ParsedURL));
501 memset(p, 0, sizeof(ParsedURL));
502 p->Priority = Msg->CurrMX->priority;
504 p->Port = DefaultMXPort;
506 p->Host = Msg->CurrMX->host;
510 ParsedURL *ppp = *pp;
512 while ((ppp->Next != NULL) &&
513 (ppp->Next->Priority <= p->Priority))
516 (ppp->Priority > p->Priority)) {
526 Msg->CurrMX = Msg->CurrMX->next;
528 Msg->CXFlags = Msg->CXFlags & F_HAVE_MX;
530 else { /* else fall back to the plain hostname */
532 for (i = 0; i < 2; i++) {
535 p = (ParsedURL*) malloc(sizeof(ParsedURL));
536 memset(p, 0, sizeof(ParsedURL));
538 p->Port = DefaultMXPort;
545 Msg->CXFlags = Msg->CXFlags & F_DIRECT;
547 if (Msg->MyQItem->FallBackHost != NULL)
549 Msg->MyQItem->FallBackHost->Next = *pp;
550 *pp = Msg->MyQItem->FallBackHost;
552 Msg->pCurrRelay = Msg->Relay;
553 return get_one_mx_host_ip(IO);
556 eNextState resolve_mx_records(AsyncIO *IO)
558 SmtpOutMsg * Msg = IO->Data;
560 SetSMTPState(IO, eSTMPmxlookup);
562 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
563 /* start resolving MX records here. */
564 if (!QueueQuery(ns_t_mx,
568 smtp_resolve_mx_record_done))
570 Msg->MyQEntry->Status = 5;
571 StrBufPrintf(Msg->MyQEntry->StatusMessage,
572 "No MX hosts found for <%s>", Msg->node);
573 return IO->NextState;
575 Msg->IO.NextState = eReadDNSReply;
576 return IO->NextState;
581 /******************************************************************************
582 * so, we're going to start a SMTP delivery. lets get it on. *
583 ******************************************************************************/
585 SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem,
586 MailQEntry *MyQEntry,
591 Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
594 memset(Msg, 0, sizeof(SmtpOutMsg));
597 Msg->MyQEntry = MyQEntry;
598 Msg->MyQItem = MyQItem;
599 Msg->pCurrRelay = MyQItem->URL;
601 InitIOStruct(&Msg->IO,
604 SMTP_C_ReadServerStatus,
606 SMTP_C_DispatchWriteDone,
607 SMTP_C_DispatchReadDone,
614 Msg->IO.ErrMsg = Msg->MyQEntry->StatusMessage;
619 void smtp_try_one_queue_entry(OneQueItem *MyQItem,
620 MailQEntry *MyQEntry,
622 /*KeepMsgText allows us to use MsgText as ours.*/
628 SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
630 Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
632 SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__);
634 FreeStrBuf (&MsgText);
637 if (KeepMsgText) Msg->msgtext = MsgText;
638 else Msg->msgtext = NewStrBufDup(MsgText);
640 if (smtp_resolve_recipients(Msg) &&
641 (!MyQItem->HaveRelay ||
642 (MyQItem->URL != NULL)))
645 ((CitContext *)Msg->IO.CitContext)->cs_host,
647 sizeof(((CitContext *)
648 Msg->IO.CitContext)->cs_host));
650 SMTPC_syslog(LOG_DEBUG, "Starting: [%ld] <%s> CC <%d> \n",
651 Msg->MyQItem->MessageID,
652 ChrPtr(Msg->MyQEntry->Recipient),
653 ((CitContext*)Msg->IO.CitContext)->cs_pid);
654 if (Msg->pCurrRelay == NULL) {
655 SetSMTPState(&Msg->IO, eSTMPmxlookup);
656 QueueEventContext(&Msg->IO,
659 else { /* oh... via relay host */
661 if (Msg->pCurrRelay->IsIP) {
662 SetSMTPState(&Msg->IO, eSTMPconnecting);
663 QueueEventContext(&Msg->IO,
667 SetSMTPState(&Msg->IO, eSTMPalookup);
668 /* uneducated admin has chosen to
669 add DNS to the equation... */
670 QueueEventContext(&Msg->IO,
676 SetSMTPState(&Msg->IO, eSMTPFailTotal);
677 /* No recipients? well fail then. */
678 if (Msg->MyQEntry != NULL) {
679 Msg->MyQEntry->Status = 5;
680 if (StrLength(Msg->MyQEntry->StatusMessage) == 0)
681 StrBufPlain(Msg->MyQEntry->StatusMessage,
682 HKEY("Invalid Recipient!"));
684 FinalizeMessageSend_DB(&Msg->IO);
685 DeleteSmtpOutMsg(Msg);
694 /*****************************************************************************/
695 /* SMTP CLIENT DISPATCHER */
696 /*****************************************************************************/
698 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *Msg)
700 double Timeout = 0.0;
701 AsyncIO *IO = &Msg->IO;
703 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
705 switch (NextTCPState) {
709 Timeout = SMTP_C_SendTimeouts[Msg->State];
710 if (Msg->State == eDATABody) {
711 /* if we're sending a huge message,
714 Timeout += StrLength(Msg->msgtext) / 512;
718 Timeout = SMTP_C_ReadTimeouts[Msg->State];
719 if (Msg->State == eDATATerminateBody) {
721 * some mailservers take a nap before accepting
722 * the message content inspection and such.
724 Timeout += StrLength(Msg->msgtext) / 512;
734 case eTerminateConnection:
738 SetNextTimeout(&Msg->IO, Timeout);
740 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO)
742 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
743 SmtpOutMsg *Msg = IO->Data;
746 rc = ReadHandlers[Msg->State](Msg);
750 SMTPSetTimeout(rc, Msg);
754 eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO)
756 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
757 SmtpOutMsg *Msg = IO->Data;
760 rc = SendHandlers[Msg->State](Msg);
761 SMTPSetTimeout(rc, Msg);
766 /*****************************************************************************/
767 /* SMTP CLIENT ERROR CATCHERS */
768 /*****************************************************************************/
769 eNextState SMTP_C_Terminate(AsyncIO *IO)
771 SmtpOutMsg *Msg = IO->Data;
773 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
774 return FinalizeMessageSend(Msg);
776 eNextState SMTP_C_TerminateDB(AsyncIO *IO)
778 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
779 return Terminate(IO);
781 eNextState SMTP_C_Timeout(AsyncIO *IO)
783 SmtpOutMsg *Msg = IO->Data;
785 Msg->MyQEntry->Status = 4;
786 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
787 StrBufPrintf(IO->ErrMsg, "Timeout: %s while talking to %s",
788 ReadErrors[Msg->State].Key,
790 if (Msg->State > eRCPT)
793 return FailOneAttempt(IO);
795 eNextState SMTP_C_ConnFail(AsyncIO *IO)
797 SmtpOutMsg *Msg = IO->Data;
799 Msg->MyQEntry->Status = 4;
800 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
801 StrBufPrintf(IO->ErrMsg, "Connection failure: %s while talking to %s",
802 ReadErrors[Msg->State].Key,
805 return FailOneAttempt(IO);
807 eNextState SMTP_C_DNSFail(AsyncIO *IO)
809 SmtpOutMsg *Msg = IO->Data;
810 Msg->MyQEntry->Status = 4;
811 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
812 return FailOneAttempt(IO);
814 eNextState SMTP_C_Shutdown(AsyncIO *IO)
816 EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
817 SmtpOutMsg *Msg = IO->Data;
819 switch (IO->NextState) {
823 /* todo: abort c-ares */
832 StopClientWatchers(IO, 1);
837 case eTerminateConnection:
841 Msg->MyQEntry->Status = 3;
842 StrBufPlain(Msg->MyQEntry->StatusMessage,
843 HKEY("server shutdown during message submit."));
844 return FinalizeMessageSend(Msg);
849 * @brief lineread Handler;
850 * understands when to read more SMTP lines, and when this is a one-lined reply.
852 eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
854 eReadState Finished = eBufferNotEmpty;
856 while (Finished == eBufferNotEmpty) {
857 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
860 case eMustReadMore: /// read new from socket...
863 case eBufferNotEmpty: /* shouldn't happen... */
864 case eReadSuccess: /// done for now...
865 if (StrLength(IO->IOBuf) < 4)
867 if (ChrPtr(IO->IOBuf)[3] == '-')
870 Msg = (SmtpOutMsg *)IO->Data;
871 if (Msg->MultiLineBuf == NULL)
872 Msg->MultiLineBuf = NewStrBuf ();
874 StrBufAppendBufPlain(Msg->MultiLineBuf, HKEY("\n"), 0);
875 StrBufAppendBuf(Msg->MultiLineBuf, IO->IOBuf, 0);
876 Finished = eBufferNotEmpty;
881 case eReadFail: /// WHUT?
889 void LogDebugEnableSMTPClient(const int n)
891 SMTPClientDebugEnabled = n;
894 CTDL_MODULE_INIT(smtp_eventclient)
897 CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient, &SMTPClientDebugEnabled);
898 return "smtpeventclient";