From: Anicka Bernathova Date: Tue, 21 Jul 2009 14:11:33 +0000 (+0200) Subject: fix content length after filtering mail X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=8628def3891660a2ebfce358dc65cf6b0f0a92d1;p=umpf.git fix content length after filtering mail --- diff --git a/ham.c b/ham.c index 0424d05..1441451 100644 --- a/ham.c +++ b/ham.c @@ -14,7 +14,7 @@ char mbox_write_buf[BUFSIZE]; int mbox_write_pos; int mbox_write_err; -static void +void new_header(char* buf, struct list* h) { char* p; diff --git a/int.c b/int.c index af67fe0..56861dd 100644 --- a/int.c +++ b/int.c @@ -595,6 +595,34 @@ bad: return NULL; } +static void +fix_content_length(struct list* h, int len) +{ + struct hlist* ph; + int found = 0; + char* clheader = "Content-Length: "; + + LIST_FOREACH(ph, h) { + if (!strcasecmp("Content-Length", ph->name)) { + found = 1; + free_string(ph->value); + ph->value = xmalloc(INT_TO_STRING_LEN); + sscanf(ph->value, "%d", &len); + break; + } + } + if (! found) { + char* buf, * tmpbuf; + buf = xmalloc(INT_TO_STRING_LEN + strlen(clheader)); + tmpbuf = xmalloc(INT_TO_STRING_LEN); + sscanf(tmpbuf, "%d", &len); + strcat(buf, tmpbuf); + new_header(buf, h); + free_string(buf); + free_string(tmpbuf); + } +} + static void do_filter(char* program, struct list* hash) { @@ -612,7 +640,9 @@ do_filter(char* program, struct list* hash) destroy_headers(current_headers); destroy_body(current_body); current_headers = make_hlist(f->fd); - current_body = get_body(f->fd); + current_body = get_body(f->fd); + fix_content_length(current_headers, current_body->body_len); + save_current_headers(hash); set_cur_mail_length_var(curr_email_len, hash); set_exit_code_var(f->exit, hash); diff --git a/umpf.h b/umpf.h index ef9651c..cff01db 100644 --- a/umpf.h +++ b/umpf.h @@ -229,6 +229,7 @@ int curr_email_len; struct list* current_headers; struct email* current_body; struct list* make_hlist(int fd); +void new_header(char* buf, struct list* h); void print_headers(struct list* l); struct email* get_body(int fd); int deliver_local_email(char* folder, struct email* email);