diff --git a/src/bdat.c b/src/bdat.c index aeea05a4..6a77da81 100644 --- a/src/bdat.c +++ b/src/bdat.c @@ -72,7 +72,7 @@ void process_bdat(struct smtp_session *session, char *readbuf, int readlen, stru syslog(LOG_PRIORITY, "%s: %s", ERR_OPEN_TMP_FILE, session->ttmpfile); } - if(cfg->process_rcpt_to_addresses == 1) write_envelope_addresses(session); + if(cfg->process_rcpt_to_addresses == 1) write_envelope_addresses(session, cfg); } session->bdat_bytes_to_read -= readlen; diff --git a/src/piler.h b/src/piler.h index 8c84bd3e..9b1367c6 100644 --- a/src/piler.h +++ b/src/piler.h @@ -71,7 +71,7 @@ int is_email_address_on_my_domains(char *email, struct data *data); int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct config *cfg); void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections); struct smtp_session *get_session_by_socket(struct smtp_session **sessions, int max_connections, int socket); -void write_envelope_addresses(struct smtp_session *session); +void write_envelope_addresses(struct smtp_session *session, struct config *cfg); void handle_data(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg); void free_smtp_session(struct smtp_session *session); diff --git a/src/session.c b/src/session.c index cdd04f11..04ede38f 100644 --- a/src/session.c +++ b/src/session.c @@ -231,14 +231,17 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen, struc } -void write_envelope_addresses(struct smtp_session *session){ +void write_envelope_addresses(struct smtp_session *session, struct config *cfg){ int i; - char s[SMALLBUFSIZE]; + char *p, s[SMALLBUFSIZE]; if(session->fd == -1) return; for(i=0; inum_of_rcpt_to; i++){ - snprintf(s, sizeof(s)-1, "X-Piler-Envelope-To: %s\n", session->rcptto[i]); - if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope to address", session->ttmpfile); + p = strchr(session->rcptto[i], '@'); + if(p && strncmp(p+1, cfg->hostid, cfg->hostid_len)){ + snprintf(s, sizeof(s)-1, "X-Piler-Envelope-To: %s\n", session->rcptto[i]); + if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope to address", session->ttmpfile); + } } } diff --git a/src/smtp.c b/src/smtp.c index 1b846d86..850fe65d 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -299,7 +299,7 @@ void process_command_data(struct smtp_session *session, struct config *cfg){ session->protocol_state = SMTP_STATE_DATA; send_smtp_response(session, SMTP_RESP_354_DATA_OK); - if(cfg->process_rcpt_to_addresses == 1) write_envelope_addresses(session); + if(cfg->process_rcpt_to_addresses == 1) write_envelope_addresses(session, cfg); } }