-
- /* 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 1;
-}
-
-
-
-void smtp_try(OneQueItem *MyQItem,
- MailQEntry *MyQEntry,
- StrBuf *MsgText,
- int KeepMsgText, /* KeepMsgText allows us to use MsgText as ours. */
- int MsgCount)
-{
- SmtpOutMsg * SendMsg;
-
- CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
-
- SendMsg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
- memset(SendMsg, 0, sizeof(SmtpOutMsg));
- SendMsg->IO.sock = (-1);
- SendMsg->IO.NextState = eReadMessage;
- SendMsg->n = MsgCount++;
- SendMsg->MyQEntry = MyQEntry;
- SendMsg->MyQItem = MyQItem;
- SendMsg->pCurrRelay = MyQItem->URL;
-
- SendMsg->IO.dport = DefaultMXPort;
- SendMsg->IO.Data = SendMsg;
- SendMsg->IO.SendDone = SMTP_C_DispatchWriteDone;
- SendMsg->IO.ReadDone = SMTP_C_DispatchReadDone;
- SendMsg->IO.Terminate = SMTP_C_Terminate;
- SendMsg->IO.LineReader = SMTP_C_ReadServerStatus;
- SendMsg->IO.ConnFail = SMTP_C_ConnFail;
- SendMsg->IO.Timeout = SMTP_C_Timeout;
-
- if (KeepMsgText) {
- SendMsg->msgtext = MsgText;
- }
- else {
- SendMsg->msgtext = NewStrBufDup(MsgText);
- }
-
- if (smtp_resolve_recipients(SendMsg)) {
- if (SendMsg->pCurrRelay == NULL)
- QueueEventContext(&SendMsg->IO,
- resolve_mx_records);
- else {
- if (SendMsg->pCurrRelay->IsIP) {
- QueueEventContext(&SendMsg->IO,
- mx_connect_relay_ip);
- }
- else {
- QueueEventContext(&SendMsg->IO,
- get_one_mx_host_ip);