- It = GetNewHashPos(Msg->MyQItem->MailQEntries, 0);
- citthread_mutex_lock(&ActiveQItemsLock);
- {
- GetHashPosFromKey(ActiveQItems, IKEY(Msg->MyQItem->MessageID), It);
- DeleteEntryFromHash(ActiveQItems, It);
- }
- citthread_mutex_unlock(&ActiveQItemsLock);
- DeleteHashPos(&It);
- }
-
-/// TODO : else free message...
- close(Msg->IO.sock);
- DeleteSmtpOutMsg(Msg);
-}
-
-eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
-{
- eReadState Finished = eBufferNotEmpty;
-
- while (Finished == eBufferNotEmpty) {
- Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
-
- switch (Finished) {
- case eMustReadMore: /// read new from socket...
- return Finished;
- break;
- case eBufferNotEmpty: /* shouldn't happen... */
- case eReadSuccess: /// done for now...
- if (StrLength(IO->IOBuf) < 4)
- continue;
- if (ChrPtr(IO->IOBuf)[3] == '-')
- Finished = eBufferNotEmpty;
- else
- return Finished;
- break;
- case eReadFail: /// WHUT?
- ///todo: shut down!
- break;
- }
- }
- return Finished;
-}
-
-/**
- * this one has to have the context for loading the message via the redirect buffer...
- */
-StrBuf *smtp_load_msg(OneQueItem *MyQItem)
-{
- CitContext *CCC=CC;
- StrBuf *SendMsg;
-
- CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
- CtdlOutputMsg(MyQItem->MessageID, MT_RFC822, HEADERS_ALL, 0, 1, NULL, (ESC_DOT|SUPPRESS_ENV_TO) );
- SendMsg = CCC->redirect_buffer;
- CCC->redirect_buffer = NULL;
- if ((StrLength(SendMsg) > 0) &&
- ChrPtr(SendMsg)[StrLength(SendMsg) - 1] != '\n') {
- CtdlLogPrintf(CTDL_WARNING,
- "SMTP client[%ld]: Possible problem: message did not "
- "correctly terminate. (expecting 0x10, got 0x%02x)\n",
- MsgCount, //yes uncool, but best choice here...
- ChrPtr(SendMsg)[StrLength(SendMsg) - 1] );
- StrBufAppendBufPlain(SendMsg, HKEY("\r\n"), 0);
- }
- return SendMsg;
-}
-
-
-int smtp_resolve_recipients(SmtpOutMsg *SendMsg)
-{
- const char *ptr;
- char buf[1024];
- int scan_done;
- int lp, rp;
- int i;
-
- /* Parse out the host portion of the recipient address */
- process_rfc822_addr(ChrPtr(SendMsg->MyQEntry->Recipient),
- SendMsg->user,
- SendMsg->node,
- SendMsg->name);
-
- CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: Attempting delivery to <%s> @ <%s> (%s)\n",
- SendMsg->n, SendMsg->user, SendMsg->node, SendMsg->name);
- /* If no envelope_from is supplied, extract one from the message */
- if ( (SendMsg->envelope_from == NULL) ||
- (IsEmptyStr(SendMsg->envelope_from)) ) {
- SendMsg->mailfrom[0] = '\0';
- scan_done = 0;
- ptr = ChrPtr(SendMsg->msgtext);
- do {
- if (ptr = cmemreadline(ptr, buf, sizeof buf), *ptr == 0) {
- scan_done = 1;
- }
- if (!strncasecmp(buf, "From:", 5)) {
- safestrncpy(SendMsg->mailfrom, &buf[5], sizeof SendMsg->mailfrom);
- striplt(SendMsg->mailfrom);
- for (i=0; SendMsg->mailfrom[i]; ++i) {
- if (!isprint(SendMsg->mailfrom[i])) {
- strcpy(&SendMsg->mailfrom[i], &SendMsg->mailfrom[i+1]);
- i=0;
- }
- }
-
- /* Strip out parenthesized names */
- lp = (-1);
- rp = (-1);
- for (i=0; !IsEmptyStr(SendMsg->mailfrom + i); ++i) {
- if (SendMsg->mailfrom[i] == '(') lp = i;
- if (SendMsg->mailfrom[i] == ')') rp = i;
- }
- if ((lp>0)&&(rp>lp)) {
- strcpy(&SendMsg->mailfrom[lp-1], &SendMsg->mailfrom[rp+1]);
- }
-
- /* Prefer brokketized names */
- lp = (-1);
- rp = (-1);
- for (i=0; !IsEmptyStr(SendMsg->mailfrom + i); ++i) {
- if (SendMsg->mailfrom[i] == '<') lp = i;
- if (SendMsg->mailfrom[i] == '>') rp = i;
- }
- if ( (lp>=0) && (rp>lp) ) {
- SendMsg->mailfrom[rp] = 0;
- memmove(SendMsg->mailfrom,
- &SendMsg->mailfrom[lp + 1],
- rp - lp);
- }
-
- scan_done = 1;
- }
- } while (scan_done == 0);
- if (IsEmptyStr(SendMsg->mailfrom)) strcpy(SendMsg->mailfrom, "someone@somewhere.org");
- stripallbut(SendMsg->mailfrom, '<', '>');
- SendMsg->envelope_from = SendMsg->mailfrom;
- }
-
- return 0;
-}
-
-
-#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))
-#define SMTP_DBG_READ() CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: < %s\n", SendMsg->n, ChrPtr(SendMsg->IO.IOBuf))
-
-/*
-void connect_one_smtpsrv_xamine_result(void *Ctx,
- int status,
- int timeouts,
- struct hostent *hostent)
-{
- 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) {
- if (errno > 0) {
- StrBufPlain(SendMsg->MyQEntry->StatusMessage,
- strerror(errno), -1);
- }