mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 04:01:58 +01:00
journaling strip fix
This commit is contained in:
parent
f2dd3b669a
commit
92e2ca30c1
@ -162,7 +162,6 @@ struct _state {
|
|||||||
|
|
||||||
int bodylen;
|
int bodylen;
|
||||||
int tolen;
|
int tolen;
|
||||||
char ms_journal, ms_journal_dropped;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -181,6 +180,8 @@ struct session_data {
|
|||||||
char bodydigest[2*DIGEST_LENGTH+1];
|
char bodydigest[2*DIGEST_LENGTH+1];
|
||||||
char digest[2*DIGEST_LENGTH+1];
|
char digest[2*DIGEST_LENGTH+1];
|
||||||
time_t now, sent, retained;
|
time_t now, sent, retained;
|
||||||
|
char ms_journal, ms_journal_dropped;
|
||||||
|
int journal_envelope_length, journal_bottom_length;
|
||||||
#ifdef NEED_MYSQL
|
#ifdef NEED_MYSQL
|
||||||
MYSQL mysql;
|
MYSQL mysql;
|
||||||
#endif
|
#endif
|
||||||
|
10
src/digest.c
10
src/digest.c
@ -33,7 +33,7 @@ int search_header_end(char *p, int n){
|
|||||||
|
|
||||||
|
|
||||||
int make_digests(struct session_data *sdata, struct __config *cfg){
|
int make_digests(struct session_data *sdata, struct __config *cfg){
|
||||||
int i=0, n, fd, offset=3, hdr_len=0;
|
int i=0, n, fd, offset=3, hdr_len=0, len=0;
|
||||||
char *body=NULL;
|
char *body=NULL;
|
||||||
unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH], md2[DIGEST_LENGTH];
|
unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH], md2[DIGEST_LENGTH];
|
||||||
SHA256_CTX context, context2;
|
SHA256_CTX context, context2;
|
||||||
@ -47,7 +47,15 @@ int make_digests(struct session_data *sdata, struct __config *cfg){
|
|||||||
fd = open(sdata->filename, O_RDONLY);
|
fd = open(sdata->filename, O_RDONLY);
|
||||||
if(fd == -1) return -1;
|
if(fd == -1) return -1;
|
||||||
|
|
||||||
|
if(sdata->ms_journal == 1 && sdata->journal_envelope_length < sizeof(buf)){
|
||||||
|
n = read(fd, buf, sdata->journal_envelope_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while((n = read(fd, buf, sizeof(buf))) > 0){
|
while((n = read(fd, buf, sizeof(buf))) > 0){
|
||||||
|
len += n;
|
||||||
|
|
||||||
|
if(sdata->ms_journal == 1 && len > sdata->tot_len) n -= len - sdata->tot_len;
|
||||||
|
|
||||||
SHA256_Update(&context2, buf, n);
|
SHA256_Update(&context2, buf, n);
|
||||||
|
|
||||||
|
@ -396,6 +396,11 @@ void init_session_data(struct session_data *sdata){
|
|||||||
sdata->tot_len = 0;
|
sdata->tot_len = 0;
|
||||||
sdata->num_of_rcpt_to = 0;
|
sdata->num_of_rcpt_to = 0;
|
||||||
|
|
||||||
|
sdata->ms_journal = 0;
|
||||||
|
sdata->ms_journal_dropped = 0;
|
||||||
|
sdata->journal_envelope_length = 0;
|
||||||
|
sdata->journal_bottom_length = 0;
|
||||||
|
|
||||||
sdata->tre = '-';
|
sdata->tre = '-';
|
||||||
|
|
||||||
sdata->rav = AVIR_OK;
|
sdata->rav = AVIR_OK;
|
||||||
|
28
src/parser.c
28
src/parser.c
@ -84,7 +84,7 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(take_into_pieces == 1 && state.writebufpos > 0){
|
if(take_into_pieces == 1 && state.writebufpos > 0){
|
||||||
if(state.ms_journal == 1) remove_trailing_journal_boundary(sdata, &state, &writebuffer[0]);
|
if(sdata->ms_journal == 1) remove_trailing_journal_boundary(sdata, &state, &writebuffer[0]);
|
||||||
|
|
||||||
len = write(state.mfd, writebuffer, state.writebufpos);
|
len = write(state.mfd, writebuffer, state.writebufpos);
|
||||||
memset(writebuffer, 0, sizeof(writebuffer));
|
memset(writebuffer, 0, sizeof(writebuffer));
|
||||||
@ -95,6 +95,10 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
|
|||||||
close(state.mfd); state.mfd = 0;
|
close(state.mfd); state.mfd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sdata->ms_journal == 1){
|
||||||
|
sdata->tot_len -= sdata->journal_envelope_length + sdata->journal_bottom_length;
|
||||||
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
@ -168,8 +172,8 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
sdata->spam_message = 1;
|
sdata->spam_message = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state->is_1st_header == 1 && state->ms_journal == 0 && strncmp(buf, "X-MS-Journal-Report:", strlen("X-MS-Journal-Report:")) == 0){
|
if(state->is_1st_header == 1 && sdata->ms_journal == 0 && strncmp(buf, "X-MS-Journal-Report:", strlen("X-MS-Journal-Report:")) == 0){
|
||||||
state->ms_journal = 1;
|
sdata->ms_journal = 1;
|
||||||
memset(state->message_id, 0, SMALLBUFSIZE);
|
memset(state->message_id, 0, SMALLBUFSIZE);
|
||||||
|
|
||||||
memset(state->b_from, 0, SMALLBUFSIZE);
|
memset(state->b_from, 0, SMALLBUFSIZE);
|
||||||
@ -177,6 +181,11 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(sdata->ms_journal_dropped == 0){
|
||||||
|
sdata->journal_envelope_length += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){
|
if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){
|
||||||
state->message_state = MSG_BODY;
|
state->message_state = MSG_BODY;
|
||||||
|
|
||||||
@ -184,7 +193,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
state->is_1st_header = 0;
|
state->is_1st_header = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state->ms_journal == 1 && strncasecmp(buf, "Received:", strlen("Received:")) == 0){
|
if(sdata->ms_journal == 1 && strncasecmp(buf, "Received:", strlen("Received:")) == 0){
|
||||||
state->is_1st_header = 1;
|
state->is_1st_header = 1;
|
||||||
state->is_header = 1;
|
state->is_header = 1;
|
||||||
memset(state->b_body, 0, BIGBUFSIZE);
|
memset(state->b_body, 0, BIGBUFSIZE);
|
||||||
@ -214,7 +223,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
state->saved_size += len;
|
state->saved_size += len;
|
||||||
//n = write(state->mfd, buf, len); // WRITE
|
//n = write(state->mfd, buf, len); // WRITE
|
||||||
if(len + state->writebufpos > writebuffersize-1){
|
if(len + state->writebufpos > writebuffersize-1){
|
||||||
if(state->ms_journal == 1) remove_trailing_journal_boundary(sdata, state, writebuffer);
|
if(sdata->ms_journal == 1) remove_trailing_journal_boundary(sdata, state, writebuffer);
|
||||||
n = write(state->mfd, writebuffer, state->writebufpos); state->writebufpos = 0; memset(writebuffer, 0, writebuffersize);
|
n = write(state->mfd, writebuffer, state->writebufpos); state->writebufpos = 0; memset(writebuffer, 0, writebuffersize);
|
||||||
}
|
}
|
||||||
memcpy(writebuffer+state->writebufpos, buf, len); state->writebufpos += len;
|
memcpy(writebuffer+state->writebufpos, buf, len); state->writebufpos += len;
|
||||||
@ -350,7 +359,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(state->message_state == MSG_BODY && state->ms_journal == 1 && strncasecmp(buf, "Recipient:", strlen("Recipient:")) == 0){
|
if(state->message_state == MSG_BODY && sdata->ms_journal == 1 && strncasecmp(buf, "Recipient:", strlen("Recipient:")) == 0){
|
||||||
state->is_header = 1;
|
state->is_header = 1;
|
||||||
state->is_1st_header = 1;
|
state->is_1st_header = 1;
|
||||||
state->message_state = MSG_RECIPIENT;
|
state->message_state = MSG_RECIPIENT;
|
||||||
@ -361,10 +370,11 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
if(p) *p = '\0';
|
if(p) *p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state->message_state == MSG_RECEIVED && state->ms_journal == 1 && state->ms_journal_dropped == 0){
|
if(state->message_state == MSG_RECEIVED && sdata->ms_journal == 1 && sdata->ms_journal_dropped == 0){
|
||||||
state->ms_journal_dropped = 1;
|
sdata->ms_journal_dropped = 1;
|
||||||
|
sdata->journal_envelope_length -= len;
|
||||||
state->writebufpos = 0; memset(writebuffer, 0, writebuffersize);
|
state->writebufpos = 0; memset(writebuffer, 0, writebuffersize);
|
||||||
memcpy(writebuffer+state->writebufpos, buf, len); state->writebufpos += strlen(buf);
|
memcpy(writebuffer+state->writebufpos, buf, strlen(buf)); state->writebufpos += strlen(buf);
|
||||||
memcpy(writebuffer+state->writebufpos, "\n", 1); state->writebufpos++;
|
memcpy(writebuffer+state->writebufpos, "\n", 1); state->writebufpos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +94,6 @@ void init_state(struct _state *state){
|
|||||||
|
|
||||||
state->tolen = 0;
|
state->tolen = 0;
|
||||||
state->bodylen = 0;
|
state->bodylen = 0;
|
||||||
|
|
||||||
state->ms_journal = 0;
|
|
||||||
state->ms_journal_dropped = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -820,14 +817,14 @@ void remove_trailing_journal_boundary(struct session_data *sdata, struct _state
|
|||||||
p = strstr(writebuffer, state->boundaries->s);
|
p = strstr(writebuffer, state->boundaries->s);
|
||||||
if(p){
|
if(p){
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
|
sdata->journal_bottom_length = len;
|
||||||
state->writebufpos -= len;
|
state->writebufpos -= len;
|
||||||
sdata->tot_len -= len;
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
p = strrchr(writebuffer, '\n');
|
p = strrchr(writebuffer, '\n');
|
||||||
if(p){
|
if(p){
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
|
sdata->journal_bottom_length += len;
|
||||||
state->writebufpos -= len;
|
state->writebufpos -= len;
|
||||||
sdata->tot_len -= len;
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user