eSMTP_C_States State;
- int SMTPstatus;
+/// int SMTPstatus; ->MyQEntry->Status
int i_mx;
int n_mx;
free(Msg);
}
+eNextState SMTP_C_Timeout(void *Data);
+eNextState SMTP_C_ConnFail(void *Data);
eNextState SMTP_C_DispatchReadDone(void *Data);
eNextState SMTP_C_DispatchWriteDone(void *Data);
-
+eNextState SMTP_C_Terminate(void *Data);
+eNextState SMTP_C_MXLookup(void *Data);
typedef eNextState (*SMTPReadHandler)(SmtpOutMsg *Msg);
typedef eNextState (*SMTPSendHandler)(SmtpOutMsg *Msg);
void *vHandler;
StrBufExtract_NextToken(Line, RawQItem, &pLine, '\n');
+ if (StrLength(Line) == 0) continue;
StrBufExtract_NextToken(Token, Line, &pItemPart, '|');
if (GetHash(QItemHandlers, SKEY(Token), &vHandler))
{
}
/// TODO : else free message...
+ close(Msg->IO.sock);
DeleteSmtpOutMsg(Msg);
}
CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: Number of MX hosts for <%s> is %d [%s]\n",
SendMsg->n, SendMsg->node, SendMsg->num_mxhosts, SendMsg->mxhosts);
if (SendMsg->num_mxhosts < 1) {
- SendMsg->SMTPstatus = 5;
+ SendMsg->MyQEntry->Status = 5;
StrBufPrintf(SendMsg->MyQEntry->StatusMessage,
"No MX hosts found for <%s>", SendMsg->node);
return; ///////TODO: abort!
}
}
-/* TODO: abort... */
-#define SMTP_ERROR(WHICH_ERR, ERRSTR) {SendMsg->SMTPstatus = WHICH_ERR; StrBufAppendBufPlain(SendMsg->MyQEntry->StatusMessage, HKEY(ERRSTR), 0); return eAbort; }
-#define SMTP_VERROR(WHICH_ERR) { SendMsg->SMTPstatus = WHICH_ERR; StrBufAppendBufPlain(SendMsg->MyQEntry->StatusMessage, &ChrPtr(SendMsg->IO.IOBuf)[4], -1, 0); return eAbort; }
+
+#define SMTP_ERROR(WHICH_ERR, ERRSTR) {SendMsg->MyQEntry->Status = WHICH_ERR; StrBufAppendBufPlain(SendMsg->MyQEntry->StatusMessage, HKEY(ERRSTR), 0); return eAbort; }
+#define SMTP_VERROR(WHICH_ERR) { SendMsg->MyQEntry->Status = WHICH_ERR; StrBufAppendBufPlain(SendMsg->MyQEntry->StatusMessage, &ChrPtr(SendMsg->IO.IOBuf)[4], -1, 0); return eAbort; }
#define SMTP_IS_STATE(WHICH_STATE) (ChrPtr(SendMsg->IO.IOBuf)[0] == WHICH_STATE)
#define SMTP_DBG_SEND() CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: > %s\n", SendMsg->n, ChrPtr(SendMsg->IO.IOBuf))
int connect_one_smtpsrv_xamine_result(void *Ctx)
{
SmtpOutMsg *SendMsg = Ctx;
+
+ CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: connecting [%s:%s]!\n",
+ SendMsg->n, SendMsg->mx_host, SendMsg->mx_port);
+
+ SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.IOBuf = NewStrBuf();
+ SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
+
+
SendMsg->IO.SendBuf.fd =
SendMsg->IO.RecvBuf.fd =
SendMsg->IO.sock = sock_connect(SendMsg->mx_host, SendMsg->mx_port);
StrBufPrintf(SendMsg->MyQEntry->StatusMessage,
"Could not connect: %s", strerror(errno));
- if (SendMsg->IO.sock >= 0)
- {
- CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: connected!\n", SendMsg->n);
- int fdflags;
- fdflags = fcntl(SendMsg->IO.sock, F_GETFL);
- if (fdflags < 0)
- CtdlLogPrintf(CTDL_DEBUG,
- "SMTP client[%ld]: unable to get socket flags! %s \n",
- SendMsg->n, strerror(errno));
- fdflags = fdflags | O_NONBLOCK;
- if (fcntl(SendMsg->IO.sock, F_SETFL, fdflags) < 0)
- CtdlLogPrintf(CTDL_DEBUG,
- "SMTP client[%ld]: unable to set socket nonblocking flags! %s \n",
- SendMsg->n, strerror(errno));
- }
+
+
if (SendMsg->IO.sock < 0) {
if (errno > 0) {
StrBufPlain(SendMsg->MyQEntry->StatusMessage,
}
/// hier: naechsten mx ausprobieren.
if (SendMsg->IO.sock < 0) {
- SendMsg->SMTPstatus = 4; /* dsn is already filled in */
+ SendMsg->MyQEntry->Status = 4; /* dsn is already filled in */
//// hier: abbrechen & bounce.
return -1;
}
- SendMsg->IO.SendBuf.Buf = NewStrBuf();
- SendMsg->IO.RecvBuf.Buf = NewStrBuf();
- SendMsg->IO.IOBuf = NewStrBuf();
InitEventIO(&SendMsg->IO, SendMsg,
SMTP_C_DispatchReadDone,
SMTP_C_DispatchWriteDone,
+ SMTP_C_Terminate,
+ SMTP_C_Timeout,
+ SMTP_C_ConnFail,
+ SMTP_C_MXLookup,
SMTP_C_ReadServerStatus,
1);
return 0;
}
+
eNextState SMTPC_read_greeting(SmtpOutMsg *SendMsg)
{
/* Process the SMTP greeting from the server */
StrBufPlain(SendMsg->MyQEntry->StatusMessage,
&ChrPtr(SendMsg->IO.RecvBuf.Buf)[4],
StrLength(SendMsg->IO.RecvBuf.Buf) - 4);
- SendMsg->SMTPstatus = 2;
+ SendMsg->MyQEntry->Status = 2;
return eSendReply;
}
CtdlLogPrintf(CTDL_INFO, "SMTP client[%ld]: delivery to <%s> @ <%s> (%s) succeeded\n",
SendMsg->n, SendMsg->user, SendMsg->node, SendMsg->name);
- return eSendReply;
+ return eTerminateConnection;
}
eNextState SMTPC_read_dummy(SmtpOutMsg *SendMsg)
SendMsg->n = MsgCount++;
SendMsg->MyQEntry = MyQEntry;
SendMsg->MyQItem = MyQItem;
- SendMsg->msgtext = MsgText;
+ if (KeepMsgText)
+ SendMsg->msgtext = MsgText;
+ else
+ SendMsg->msgtext = NewStrBufDup(MsgText);
smtp_resolve_recipients(SendMsg);
resolve_mx_hosts(SendMsg);
StrBufExtract_NextToken(Item->Current->Recipient, Line, Pos, '|');
Item->Current->Status = StrBufExtractNext_int(Line, Pos, '|');
StrBufExtract_NextToken(Item->Current->StatusMessage, Line, Pos, '|');
+ Item->Current = NULL; // TODO: is this always right?
}
long len;
const char *Key;
- CtdlLogPrintf(CTDL_DEBUG, "SMTP client: smtp_do_procmsg(%ld)\n", msgnum);
+ CtdlLogPrintf(CTDL_DEBUG, "SMTP Queue: smtp_do_procmsg(%ld)\n", msgnum);
///strcpy(envelope_from, "");
msg = CtdlFetchMessage(msgnum, 1);
if (msg == NULL) {
- CtdlLogPrintf(CTDL_ERR, "SMTP client: tried %ld but no such message!\n", msgnum);
+ CtdlLogPrintf(CTDL_ERR, "SMTP Queue: tried %ld but no such message!\n", msgnum);
return;
}
MyQItem = DeserializeQueueItem(PlainQItem, msgnum);
FreeStrBuf(&PlainQItem);
- if (MyQItem == NULL)
+ if (MyQItem == NULL) {
+ CtdlLogPrintf(CTDL_ERR, "SMTP Queue: Msg No %ld: already in progress!\n", msgnum);
return; /* s.b. else is already processing... */
-
+ }
/*
* Postpone delivery if we've already tried recently.
* Bail out if there's no actual message associated with this
*/
if (MyQItem->MessageID < 0L) {
- CtdlLogPrintf(CTDL_ERR, "SMTP client: no 'msgid' directive found!\n");
+ CtdlLogPrintf(CTDL_ERR, "SMTP Queue: no 'msgid' directive found!\n");
It = GetNewHashPos(MyQItem->MailQEntries, 0);
citthread_mutex_lock(&ActiveQItemsLock);
{
return;
}
+ It = GetNewHashPos(MyQItem->MailQEntries, 0);
+ while (GetNextHashPos(MyQItem->MailQEntries, It, &len, &Key, &vQE))
+ {
+ MailQEntry *ThisItem = vQE;
+ CtdlLogPrintf(CTDL_DEBUG, "SMTP Queue: Task: <%s> %d\n", ChrPtr(ThisItem->Recipient), ThisItem->Active);
+ }
+ DeleteHashPos(&It);
+
CountActiveQueueEntries(MyQItem);
if (MyQItem->ActiveDeliveries > 0)
{
{
MailQEntry *ThisItem = vQE;
if (ThisItem->Active == 1) {
- CtdlLogPrintf(CTDL_DEBUG, "SMTP client: Trying <%s>\n", ChrPtr(ThisItem->Recipient));
+ CtdlLogPrintf(CTDL_DEBUG, "SMTP Queue: Trying <%s>\n", ChrPtr(ThisItem->Recipient));
smtp_try(MyQItem, ThisItem, Msg, (i == MyQItem->ActiveDeliveries));
i++;
}
int num_processed = 0;
struct CitContext smtp_queue_CC;
+ CtdlThreadSleep(10);
+
CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send");
citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
CtdlLogPrintf(CTDL_DEBUG, "smtp_queue_thread() initializing\n");
SMTPC_send_QUIT
};
+eNextState SMTP_C_Terminate(void *Data)
+{
+ SmtpOutMsg *pMsg = Data;
+ FinalizeMessageSend(pMsg);
+
+}
+
+eNextState SMTP_C_Timeout(void *Data)
+{
+ SmtpOutMsg *pMsg = Data;
+ FinalizeMessageSend(pMsg);
+
+}
+
+eNextState SMTP_C_ConnFail(void *Data)
+{
+ SmtpOutMsg *pMsg = Data;
+ FinalizeMessageSend(pMsg);
+
+}
+
eNextState SMTP_C_DispatchReadDone(void *Data)
{
SmtpOutMsg *pMsg = Data;
}
+eNextState SMTP_C_MXLookup(void *Data)
+{
+
+}
+
#endif
CTDL_MODULE_INIT(smtp_eventclient)