mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 23:51:59 +01:00
write envelope addresses to the beginning of email message file
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
1a9c145116
commit
e0e59d2e74
@ -60,7 +60,7 @@ void get_bdat_size_to_read(struct smtp_session *session, char *buf){
|
||||
}
|
||||
|
||||
|
||||
void process_bdat(struct smtp_session *session, char *readbuf, int readlen){
|
||||
void process_bdat(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg){
|
||||
int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
|
||||
@ -71,6 +71,8 @@ void process_bdat(struct smtp_session *session, char *readbuf, int readlen){
|
||||
if(session->fd == -1){
|
||||
syslog(LOG_PRIORITY, "%s: %s", ERR_OPEN_TMP_FILE, session->ttmpfile);
|
||||
}
|
||||
|
||||
if(cfg->process_rcpt_to_addresses == 1) write_envelope_addresses(session);
|
||||
}
|
||||
|
||||
session->bdat_bytes_to_read -= readlen;
|
||||
@ -113,7 +115,7 @@ void process_bdat(struct smtp_session *session, char *readbuf, int readlen){
|
||||
|
||||
snprintf(buf, sizeof(buf)-1, "250 OK <%s>\r\n", session->ttmpfile);
|
||||
send_smtp_response(session, buf);
|
||||
syslog(LOG_PRIORITY, "received: %s, from=%s, size=%d", session->ttmpfile, session->mailfrom, session->tot_len);
|
||||
syslog(LOG_PRIORITY, "received: %s, from=%s, size=%d, client=%s", session->ttmpfile, session->mailfrom, session->tot_len, session->remote_host);
|
||||
}
|
||||
else send_smtp_response(session, SMTP_RESP_250_BDAT);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#define VERSION "1.3.3"
|
||||
|
||||
#define BUILD 988
|
||||
#define BUILD 989
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
|
@ -381,6 +381,7 @@ struct counters {
|
||||
struct smtp_session {
|
||||
char ttmpfile[SMALLBUFSIZE];
|
||||
char mailfrom[SMALLBUFSIZE];
|
||||
char rcptto[MAX_RCPT_TO][SMALLBUFSIZE];
|
||||
char buf[SMALLBUFSIZE];
|
||||
char remote_host[INET6_ADDRSTRLEN];
|
||||
time_t lasttime;
|
||||
@ -393,6 +394,7 @@ struct smtp_session {
|
||||
int bdat_rounds;
|
||||
int bdat_last_round;
|
||||
int bdat_bytes_to_read;
|
||||
int num_of_rcpt_to;
|
||||
struct config *cfg;
|
||||
struct net net;
|
||||
};
|
||||
|
@ -32,6 +32,8 @@ struct parser_state parse_message(struct session_data *sdata, int take_into_piec
|
||||
return state;
|
||||
}
|
||||
|
||||
/* TODO: since piler-smtp handles the smtp connection, piler has
|
||||
* node idea about the envelope addresses */
|
||||
|
||||
if(sdata->num_of_rcpt_to > 0 && cfg->process_rcpt_to_addresses == 1){
|
||||
for(i=0; i<sdata->num_of_rcpt_to; i++){
|
||||
|
@ -309,7 +309,7 @@ int main(int argc, char **argv){
|
||||
break;
|
||||
}
|
||||
|
||||
handle_data(session, &readbuf[0], readlen);
|
||||
handle_data(session, &readbuf[0], readlen, &cfg);
|
||||
|
||||
if(session->protocol_state == SMTP_STATE_BDAT && session->bad == 1){
|
||||
done = 1;
|
||||
|
@ -71,7 +71,8 @@ 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 handle_data(struct smtp_session *session, char *readbuf, int readlen);
|
||||
void write_envelope_addresses(struct smtp_session *session);
|
||||
void handle_data(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg);
|
||||
void free_smtp_session(struct smtp_session *session);
|
||||
|
||||
void child_sighup_handler(int sig);
|
||||
|
@ -104,6 +104,7 @@ void init_smtp_session(struct smtp_session *session, int slot, int sd, struct co
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addr_size = sizeof(struct sockaddr_in);
|
||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
int i;
|
||||
|
||||
session->slot = slot;
|
||||
|
||||
@ -120,6 +121,11 @@ void init_smtp_session(struct smtp_session *session, int slot, int sd, struct co
|
||||
|
||||
session->fd = -1;
|
||||
|
||||
memset(session->mailfrom, 0, SMALLBUFSIZE);
|
||||
|
||||
session->num_of_rcpt_to = 0;
|
||||
for(i=0; i<MAX_RCPT_TO; i++) memset(session->rcptto[i], 0, SMALLBUFSIZE);
|
||||
|
||||
memset(session->buf, 0, SMALLBUFSIZE);
|
||||
memset(session->remote_host, 0, INET6_ADDRSTRLEN);
|
||||
|
||||
@ -162,7 +168,7 @@ void tear_down_session(struct smtp_session **sessions, int slot, int *num_connec
|
||||
}
|
||||
|
||||
|
||||
void handle_data(struct smtp_session *session, char *readbuf, int readlen){
|
||||
void handle_data(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg){
|
||||
char *p, puf[MAXBUFSIZE];
|
||||
int result;
|
||||
|
||||
@ -174,7 +180,7 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen){
|
||||
return;
|
||||
}
|
||||
|
||||
process_bdat(session, readbuf, readlen);
|
||||
process_bdat(session, readbuf, readlen, cfg);
|
||||
}
|
||||
|
||||
// process DATA
|
||||
@ -204,13 +210,13 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen){
|
||||
if(puf[0] == '\0') continue;
|
||||
|
||||
if(result == 1){
|
||||
process_smtp_command(session, puf);
|
||||
process_smtp_command(session, puf, cfg);
|
||||
|
||||
// if chunking is enabled and we have data after BDAT <len>
|
||||
// then process the rest
|
||||
|
||||
if(session->cfg->enable_chunking == 1 && p && session->protocol_state == SMTP_STATE_BDAT){
|
||||
process_bdat(session, p, strlen(p));
|
||||
process_bdat(session, p, strlen(p), cfg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -223,3 +229,21 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void write_envelope_addresses(struct smtp_session *session){
|
||||
int i;
|
||||
char s[SMALLBUFSIZE];
|
||||
|
||||
if(session->fd == -1) return;
|
||||
|
||||
snprintf(s, sizeof(s)-1, "X-Piler-Envelope-From: %s\n", session->mailfrom);
|
||||
if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope from address", session->ttmpfile);
|
||||
|
||||
for(i=0; i<session->num_of_rcpt_to; i++){
|
||||
if(i == 0) snprintf(s, sizeof(s)-1, "X-Piler-Envelope-To: %s\n", session->rcptto[session->num_of_rcpt_to]);
|
||||
else snprintf(s, sizeof(s)-1, " %s\n", session->rcptto[session->num_of_rcpt_to]);
|
||||
|
||||
if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope to address", session->ttmpfile);
|
||||
}
|
||||
}
|
||||
|
16
src/smtp.c
16
src/smtp.c
@ -15,7 +15,7 @@
|
||||
#include "smtp.h"
|
||||
|
||||
|
||||
void process_smtp_command(struct smtp_session *session, char *buf){
|
||||
void process_smtp_command(struct smtp_session *session, char *buf, struct config *cfg){
|
||||
char response[SMALLBUFSIZE];
|
||||
|
||||
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "processing command: *%s*", buf);
|
||||
@ -42,7 +42,7 @@ void process_smtp_command(struct smtp_session *session, char *buf){
|
||||
}
|
||||
|
||||
if(strncasecmp(buf, SMTP_CMD_DATA, strlen(SMTP_CMD_DATA)) == 0){
|
||||
process_command_data(session);
|
||||
process_command_data(session, cfg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -244,8 +244,6 @@ void process_command_starttls(struct smtp_session *session){
|
||||
|
||||
|
||||
void process_command_mail_from(struct smtp_session *session, char *buf){
|
||||
memset(session->mailfrom, 0, SMALLBUFSIZE);
|
||||
|
||||
if(session->protocol_state != SMTP_STATE_HELO && session->protocol_state != SMTP_STATE_PERIOD && session->protocol_state != SMTP_STATE_BDAT){
|
||||
send(session->net.socket, SMTP_RESP_503_ERR, strlen(SMTP_RESP_503_ERR), 0);
|
||||
}
|
||||
@ -271,6 +269,12 @@ void process_command_rcpt_to(struct smtp_session *session, char *buf){
|
||||
// For now, we are not interested in the envelope recipients
|
||||
|
||||
session->protocol_state = SMTP_STATE_RCPT_TO;
|
||||
|
||||
if(session->num_of_rcpt_to < MAX_RCPT_TO){
|
||||
extractEmail(buf, session->rcptto[session->num_of_rcpt_to]);
|
||||
session->num_of_rcpt_to++;
|
||||
}
|
||||
|
||||
send_smtp_response(session, SMTP_RESP_250_OK);
|
||||
}
|
||||
else {
|
||||
@ -279,7 +283,7 @@ void process_command_rcpt_to(struct smtp_session *session, char *buf){
|
||||
}
|
||||
|
||||
|
||||
void process_command_data(struct smtp_session *session){
|
||||
void process_command_data(struct smtp_session *session, struct config *cfg){
|
||||
session->tot_len = 0;
|
||||
|
||||
if(session->protocol_state != SMTP_STATE_RCPT_TO){
|
||||
@ -294,6 +298,8 @@ void process_command_data(struct smtp_session *session){
|
||||
else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <piler.h>
|
||||
|
||||
void process_smtp_command(struct smtp_session *session, char *buf);
|
||||
void process_smtp_command(struct smtp_session *session, char *buf, struct config *cfg);
|
||||
void process_data(struct smtp_session *session, char *readbuf, int readlen);
|
||||
|
||||
void send_smtp_response(struct smtp_session *session, char *buf);
|
||||
@ -17,12 +17,12 @@ void process_command_quit(struct smtp_session *session, char *buf, int buflen);
|
||||
void process_command_reset(struct smtp_session *session);
|
||||
void process_command_mail_from(struct smtp_session *session, char *buf);
|
||||
void process_command_rcpt_to(struct smtp_session *session, char *buf);
|
||||
void process_command_data(struct smtp_session *session);
|
||||
void process_command_data(struct smtp_session *session, struct config *cfg);
|
||||
void process_command_period(struct smtp_session *session);
|
||||
void process_command_starttls(struct smtp_session *session);
|
||||
|
||||
void reset_bdat_counters(struct smtp_session *session);
|
||||
void get_bdat_size_to_read(struct smtp_session *session, char *buf);
|
||||
void process_bdat(struct smtp_session *session, char *readbuf, int readlen);
|
||||
void process_bdat(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user