]> mj.ucw.cz Git - umpf.git/commitdiff
fix content length after filtering mail
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 14:11:33 +0000 (16:11 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 14:11:33 +0000 (16:11 +0200)
ham.c
int.c
umpf.h

diff --git a/ham.c b/ham.c
index 0424d05a7b909d17fd606ef0ce02ce76828de27d..1441451d246e78d83bbd89f894743c6a05acf7b8 100644 (file)
--- 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 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);
 
diff --git a/umpf.h b/umpf.h
index ef9651c50e64fbb5f4f88ccd4e732ca846c36aea..cff01db6181c1389bd7d9b34b760df1674bf16d5 100644 (file)
--- 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);