Esempio n. 1
0
/* 
 * Build a comma separated string of smtp recipient email addresses
 * for the email message To-header.
 */
void
build_to_header_rcpt_addrs(smtp_t *smtp)
{
	char *fetched_email;
	char *email_to_addrs;
	int email_addrs_max;

	if (smtp == NULL) return;
	email_to_addrs = smtp->email_to;
	smtp->email_it = 0;

	email_addrs_max = (SMTP_BUFFER_MAX / SMTP_EMAIL_ADDR_MAX_LENGTH) - 1;

	while ((fetched_email = fetch_next_email(smtp)) != NULL) {

		/* First email address, so no need for "," */
		if (smtp->email_it == 0) {
			snprintf(email_to_addrs, SMTP_EMAIL_ADDR_MAX_LENGTH, "%s", fetched_email);
		}
		else {
			strcat(email_to_addrs, ", ");
			strncat(email_to_addrs, fetched_email, SMTP_EMAIL_ADDR_MAX_LENGTH);
		}
	
		smtp->email_it++;
		if (smtp->email_it >= email_addrs_max)
			break;
				
	}

	smtp->email_it = 0;
}
Esempio n. 2
0
/*
 * Build a comma separated string of smtp recipient email addresses
 * for the email message To-header.
 */
static void
build_to_header_rcpt_addrs(smtp_t *smtp)
{
	char *fetched_email;
	char *email_to_addrs;
	int bytes_available = SMTP_BUFFER_MAX - 1;
	int bytes_not_written, bytes_to_write;

	if (smtp == NULL)
		return;

	email_to_addrs = smtp->email_to;
	smtp->email_it = 0;

	while (1) {
		fetched_email = fetch_next_email(smtp);
		if (fetched_email == NULL)
			break;

		bytes_not_written = 0;
		bytes_to_write = strlen(fetched_email);
		if (smtp->email_it == 0) {
			if (bytes_available < bytes_to_write)
				break;
		} else {
			if (bytes_available < 2 + bytes_to_write)
				break;

			/* Prepend with a comma and space to all non-first email addresses */
			*email_to_addrs++ = ',';
			*email_to_addrs++ = ' ';
			bytes_available -= 2;
		}

		bytes_not_written = snprintf(email_to_addrs, bytes_to_write + 1, "%s", fetched_email) - bytes_to_write;;
		if (bytes_not_written > 0) {
			/* Inconsistent state, no choice but to break here and do nothing */
			break;
		}

		email_to_addrs += bytes_to_write;
		bytes_available -= bytes_to_write;
		smtp->email_it++;
	}

	smtp->email_it = 0;
}
Esempio n. 3
0
/* RCPT command processing */
static int
rcpt_cmd(thread_t * thread)
{
	smtp_t *smtp = THREAD_ARG(thread);
	char *buffer;
	char *fetched_email;

	buffer = (char *) MALLOC(SMTP_BUFFER_MAX);
	/* We send RCPT TO command multiple time to add all our email receivers.
	 * --rfc821.3.1
	 */
	fetched_email = fetch_next_email(smtp);

	snprintf(buffer, SMTP_BUFFER_MAX, SMTP_RCPT_CMD, fetched_email);
	if (send(thread->u.fd, buffer, strlen(buffer), 0) == -1)
		smtp->stage = ERROR;
	FREE(buffer);

	return 0;
}
Esempio n. 4
0
static int
rcpt_code(thread_t * thread, int status)
{
	smtp_t *smtp = THREAD_ARG(thread);
	char *fetched_email;

	if (status == 250) {
		smtp->email_it++;

		fetched_email = fetch_next_email(smtp);

		if (!fetched_email)
			smtp->stage++;
	} else {
		log_message(LOG_INFO, "Error processing RCPT cmd on SMTP server %s."
				      " SMTP status code = %d"
				    , FMT_SMTP_HOST()
				    , status);
		smtp->stage = ERROR;
	}

	return 0;
}
Esempio n. 5
0
static int
rcpt_code(thread_t * thread, int status)
{
	smtp_t *smtp = THREAD_ARG(thread);
	char *fetched_email;

	if (status == 250) {
		smtp->email_it++;

		fetched_email = fetch_next_email(smtp);

		if (!fetched_email)
			smtp->stage++;
	} else {
		log_message(LOG_INFO, "Error processing RCPT cmd on SMTP server [%s]:%d."
				      " SMTP status code = %d"
				    , inet_sockaddrtos(&global_data->smtp_server)
				    , SMTP_PORT, status);
		smtp->stage = ERROR;
	}

	return 0;
}