if (pish->msgMailFrom != NULL) { sprintf(command, "MAIL FROM:%s%s", pish->msgMailFrom, CRLF);
if (pish->fileCount > 1) {		 int	ff; ff = (RANDOM() % pish->fileCount);  fileEntry = ((smtp_file_t *)pish->files) + ff; } else { fileEntry = (smtp_file_t *)pish->files; } if (fileEntry->msgMailFrom != NULL) { sprintf(command, "MAIL FROM:%s%s", fileEntry->msgMailFrom, CRLF);
sendSMTPLoop(ptcx_t ptcx, mail_command_t *cmd, cmd_stats_t *ptimer, void *mystate){    doSMTP_state_t	*me = (doSMTP_state_t *)mystate;    char	command[MAXCOMMANDLEN];    char	respBuffer[MAX_RESPONSE_LEN];    char	rcptToUser[MAX_MAILADDR_LEN];    int	rc, jj;    long		addressNum;    long		domainNum;    int		numBytes;    pish_stats_t	*stats = (pish_stats_t *)ptimer->data;    pish_command_t	*pish = (pish_command_t *)cmd->data;    /* send MAIL FROM:<username> */    if (pish->msgMailFrom != NULL) {	sprintf(command, "MAIL FROM:%s%s", pish->msgMailFrom, CRLF);    } else {	sprintf(command, "MAIL FROM:<%s>%s", pish->smtpMailFrom, CRLF);    }    event_start(ptcx, &stats->cmd);    rc = doSmtpCommandResponse(ptcx, ptcx->sock, command, respBuffer, sizeof(respBuffer));    event_stop(ptcx, &stats->cmd);    if (rc == -1) {	if (gf_timeexpired < EXIT_FAST) {	    stats->cmd.errs++;	    trimEndWhite (command);	    returnerr(debugfile, "%s SMTP FROM [%.99s], ERROR reading [%.99s] response [%.99s]\n",		      ptcx->errMsg, command, respBuffer);	}	doSMTPExit (ptcx, me);	return -1;    }    /* send RCPT TO:<username> for each recipient */    for (jj = 0; jj < pish->numRecipients; jj++) {	/* generate a random recipient (but with an account on the server) */	domainNum = rangeNext (&stats->domainRange, stats->lastDomain);	stats->lastDomain = domainNum;	addressNum = rangeNext (&stats->addressRange, stats->lastAddress);	stats->lastAddress = addressNum;	sprintf(rcptToUser, pish->addressFormat, addressNum, domainNum);	D_PRINTF(debugfile,"rcptToUser=%s\n", rcptToUser);	sprintf(command, "RCPT TO:<%s>%s", rcptToUser, CRLF);	event_start(ptcx, &stats->cmd);	rc = doSmtpCommandResponse(ptcx, ptcx->sock, command, respBuffer, sizeof(respBuffer));	event_stop(ptcx, &stats->cmd);	if (rc == -1) {	    if (gf_timeexpired < EXIT_FAST) {		stats->cmd.errs++;		trimEndWhite (command);		returnerr(debugfile, "%s SMTP RCPT [%.99s], ERROR reading [%.99s] response [%.99s]\n",			  ptcx->errMsg, command, respBuffer);	    }	    doSMTPExit (ptcx, me);	    return -1;	}    }    /* send DATA */    event_start(ptcx, &stats->cmd);    sprintf(command, "DATA%s", CRLF);    event_stop(ptcx, &stats->cmd);    if (doSmtpCommandResponse(ptcx, ptcx->sock, command, respBuffer, sizeof(respBuffer)) == -1 ||	respBuffer[0] != '3') {	if (gf_timeexpired < EXIT_FAST) {	    stats->cmd.errs++;	    returnerr(debugfile, "%s SMTP DATA ERROR, response [%.99s]\n",		      ptcx->errMsg, respBuffer);	}	doSMTPExit (ptcx, me);	return -1;    }    D_PRINTF(debugfile, "data response %s\n", respBuffer);    /* send data as message (we already added the CRLF.CRLF) */    event_start(ptcx, &stats->msgwrite);    numBytes = sendMessage(ptcx, ptcx->sock, pish->msgdata);    if (numBytes == -1) {	event_stop(ptcx, &stats->msgwrite);	if (gf_timeexpired < EXIT_FAST) {	    returnerr(debugfile, "%s SMTP Error sending mail message: %s\n",		      ptcx->errMsg, neterrstr());	    stats->msgwrite.errs++;	}	doSMTPExit (ptcx, me);	return -1;    }    /* read server response */    numBytes = readResponse(ptcx, ptcx->sock, respBuffer, sizeof(respBuffer));    event_stop(ptcx, &stats->msgwrite);    if (numBytes <= 0) {	if (gf_timeexpired < EXIT_FAST) {	    returnerr(debugfile,"%s SMTP Error reading send message response: %s\n",		      ptcx->errMsg, neterrstr());	    stats->msgwrite.errs++;	}	doSMTPExit (ptcx, me);	return -1;    }    return 0;}