]> mj.ucw.cz Git - umpf.git/blobdiff - int.c
fix content length after filtering mail
[umpf.git] / int.c
diff --git a/int.c b/int.c
index af67fe0f694e1aafed984e1405271d91de8d0e12..56861dd45e1ecc48954774c12ecac7903b81ee37 100644 (file)
--- 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);