- CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
- if ((status == ARES_SUCCESS) && (hostent != NULL) ) {
- unsigned long psaddr;
- // TODO: IPV6
- memcpy(&psaddr, hostent->h_addr_list[0], sizeof(psaddr));
- psaddr = ntohl(psaddr);
-
- CtdlLogPrintf(CTDL_DEBUG,
- "SMTP client[%ld]: connecting to %s [%ld.%ld.%ld.%ld:%d] ...\n",
- SendMsg->n,
- SendMsg->mx_host,
- (psaddr >> 24) & 0xFF,
- (psaddr >> 16) & 0xFF,
- (psaddr >> 8) & 0xFF,
- (psaddr >> 0) & 0xFF,
- SendMsg->IO.dport);
-
- SendMsg->MyQEntry->Status = 5;
- StrBufPrintf(SendMsg->MyQEntry->StatusMessage,
- "Timeout while connecting %s [%ld.%ld.%ld.%ld:%d] ",
- SendMsg->mx_host,
- (psaddr >> 24) & 0xFF,
- (psaddr >> 16) & 0xFF,
- (psaddr >> 8) & 0xFF,
- (psaddr >> 0) & 0xFF,
- SendMsg->IO.dport);
-
- SendMsg->IO.HEnt = hostent;
- InitEventIO(IO, SendMsg,
- SMTP_C_DispatchReadDone,
- SMTP_C_DispatchWriteDone,
- SMTP_C_Terminate,
- SMTP_C_Timeout,
- SMTP_C_ConnFail,
- SMTP_C_ReadServerStatus,
- SMTP_C_ConnTimeout,
- SMTP_C_ReadTimeouts[0],
- 1);
-
- }
-}
-
-const unsigned short DefaultMXPort = 25;
-void get_one_mx_host_ip(SmtpOutMsg *SendMsg)
-{
- //char *endpart;
- //char buf[SIZ];
-
- CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
- SendMsg->IO.dport = DefaultMXPort;
-
-
-/* TODO: Relay!
- *SendMsg->mx_user = '\0';
- *SendMsg->mx_pass = '\0';
- if (num_tokens(buf, '@') > 1) {
- strcpy (SendMsg->mx_user, buf);
- endpart = strrchr(SendMsg->mx_user, '@');
- *endpart = '\0';
- strcpy (SendMsg->mx_host, endpart + 1);
- endpart = strrchr(SendMsg->mx_user, ':');
- if (endpart != NULL) {
- strcpy(SendMsg->mx_pass, endpart+1);
- *endpart = '\0';
- }
-
- endpart = strrchr(SendMsg->mx_host, ':');
- if (endpart != 0){
- *endpart = '\0';
- strcpy(SendMsg->mx_port, endpart + 1);
- }
- }
- else
-*/
- SendMsg->mx_host = SendMsg->CurrMX->host;
- SendMsg->CurrMX = SendMsg->CurrMX->next;
-
- CtdlLogPrintf(CTDL_DEBUG,
- "SMTP client[%ld]: looking up %s : %d ...\n",
- SendMsg->n,
- SendMsg->mx_host,
- SendMsg->IO.dport);
-
- ares_gethostbyname(SendMsg->IO.DNSChannel,
- SendMsg->mx_host,
- AF_INET6, /* it falls back to ipv4 in doubt... */
- get_one_mx_host_ip_done,
- &SendMsg->IO);
-}
-
-
-eNextState smtp_resolve_mx_done(AsyncIO *IO)
-{
- SmtpOutMsg * SendMsg = IO->Data;
-
- CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
-
- 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->CurrMX = SendMsg->AllMX = IO->VParsedDNSReply;
- //// TODO: should we remove the current ares context???
- get_one_mx_host_ip(SendMsg);
- return 0;
-}