diff --git a/src/message.c b/src/message.c index cc5ba724..19d5df11 100644 --- a/src/message.c +++ b/src/message.c @@ -416,7 +416,12 @@ int process_message(struct session_data *sdata, struct _state *state, struct __d rc = store_meta_data(sdata, state, cfg); if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored metadata, rc=%d", sdata->ttmpfile, rc); - if(rc == ERR_EXISTS) return ERR_EXISTS; + if(rc == ERR_EXISTS){ + + remove_stored_message_files(sdata, state, cfg); + + return ERR_EXISTS; + } return OK; } diff --git a/src/piler.h b/src/piler.h index ec2214a1..aa5989bc 100644 --- a/src/piler.h +++ b/src/piler.h @@ -37,6 +37,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg); int process_message(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg); int store_file(struct session_data *sdata, char *filename, int startpos, int len, struct __config *cfg); +int remove_stored_message_files(struct session_data *sdata, struct _state *state, struct __config *cfg); int store_attachments(struct session_data *sdata, struct _state *state, struct __config *cfg); int query_attachments(struct session_data *sdata, struct ptr_array *ptr_arr, struct __config *cfg); diff --git a/src/store.c b/src/store.c index 1b6b0c6e..b7b54e4b 100644 --- a/src/store.c +++ b/src/store.c @@ -173,3 +173,28 @@ ENDE: } +int remove_stored_message_files(struct session_data *sdata, struct _state *state, struct __config *cfg){ + int i; + char s[SMALLBUFSIZE]; + + if(state->n_attachments > 0){ + + for(i=1; i<=state->n_attachments; i++){ + snprintf(s, sizeof(s)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, sdata->ttmpfile[RND_STR_LEN-6], sdata->ttmpfile[RND_STR_LEN-5], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile, i); + + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s); + + unlink(s); + } + } + + snprintf(s, sizeof(s)-1, "%s/%c%c/%c%c/%c%c/%s.m", cfg->queuedir, sdata->ttmpfile[RND_STR_LEN-6], sdata->ttmpfile[RND_STR_LEN-5], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile); + + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s); + + unlink(s); + + return 0; +} + +